@lunora/x402 0.0.0 → 1.0.0-alpha.2
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 +111 -0
- package/README.md +43 -28
- package/__assets__/package-og.svg +14 -0
- package/dist/charge/index.d.mts +76 -0
- package/dist/charge/index.d.ts +76 -0
- package/dist/charge/index.mjs +7 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +2 -0
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs +4 -0
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-CSu5b5lD.mjs +85 -0
- package/dist/packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs +26 -0
- package/dist/packem_shared/config.d-CddwCiBm.d.mts +325 -0
- package/dist/packem_shared/config.d-CddwCiBm.d.ts +325 -0
- package/dist/packem_shared/createChargeMiddleware-BJkYJeFf.mjs +148 -0
- package/dist/packem_shared/createFacilitatorClient-rXHBnCZm.mjs +16 -0
- package/dist/packem_shared/createPayFetch-O2vkvM1v.mjs +17 -0
- package/dist/packem_shared/createProcedureChargeGate-CV8ITlQP.mjs +19 -0
- package/dist/packem_shared/registerWallet-I4pVwq65.mjs +109 -0
- package/dist/packem_shared/toPaymentEventRow-DW4O9N7Y.mjs +22 -0
- package/dist/packem_shared/withX402-rUq0voT8.mjs +15 -0
- package/dist/pay/index.d.mts +77 -0
- package/dist/pay/index.d.ts +77 -0
- package/dist/pay/index.mjs +21 -0
- package/package.json +75 -7
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { e as X402PayConfig } from "../packem_shared/config.d-CddwCiBm.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-CddwCiBm.mjs";
|
|
3
|
+
import { x402Client } from '@x402/core/client';
|
|
4
|
+
import { ClientSvmSigner } from '@x402/svm';
|
|
5
|
+
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
+
import '@x402/evm';
|
|
7
|
+
import '@x402/core/http';
|
|
8
|
+
import '@x402/core/types';
|
|
9
|
+
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
|
+
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
|
+
/** How the wallet reads its key material — wired to `ctx.secrets.get` in an action. */
|
|
12
|
+
interface WalletDeps {
|
|
13
|
+
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
14
|
+
readonly getSecret: GetSecret;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a viem `LocalAccount` from a raw private key. The key may be given with
|
|
18
|
+
* or without the `0x` prefix. The account is a structural `ClientEvmSigner`
|
|
19
|
+
* (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
|
|
20
|
+
*/
|
|
21
|
+
declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
24
|
+
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
25
|
+
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
26
|
+
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
27
|
+
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
28
|
+
*/
|
|
29
|
+
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
30
|
+
/**
|
|
31
|
+
* Register the scheme family the configured network needs on `client`, wired to
|
|
32
|
+
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
33
|
+
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
34
|
+
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
35
|
+
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
36
|
+
* `@coinbase/cdp-sdk`).
|
|
37
|
+
*/
|
|
38
|
+
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
39
|
+
/** A payment-enabled `fetch`: same signature as the platform `fetch`. */
|
|
40
|
+
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
|
+
/** Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap. */
|
|
42
|
+
interface X402PayDeps extends WalletDeps {
|
|
43
|
+
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
44
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
48
|
+
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
49
|
+
* with unlimited spend authority.
|
|
50
|
+
*/
|
|
51
|
+
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
52
|
+
/** A configured pay rail: a payment-enabled `fetch` bounded by the spend policy. */
|
|
53
|
+
interface X402Pay {
|
|
54
|
+
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
55
|
+
readonly fetch: PayFetch;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
59
|
+
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
60
|
+
* signer) when the policy is unbounded.
|
|
61
|
+
*/
|
|
62
|
+
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
63
|
+
/**
|
|
64
|
+
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
65
|
+
*
|
|
66
|
+
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
67
|
+
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
68
|
+
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
69
|
+
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
70
|
+
* only when an action actually pays, and the single `SpendState` behind the
|
|
71
|
+
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
72
|
+
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
73
|
+
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
74
|
+
* fail-closed.
|
|
75
|
+
*/
|
|
76
|
+
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
77
|
+
export { type PayFetch, type WalletDeps, X402Pay, type X402PayConfig, type X402PayDeps, createPayFetch, createX402Pay, lazyX402Pay, registerWallet, resolveEvmAccount, resolveSvmSigner };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { e as X402PayConfig } from "../packem_shared/config.d-CddwCiBm.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-CddwCiBm.js";
|
|
3
|
+
import { x402Client } from '@x402/core/client';
|
|
4
|
+
import { ClientSvmSigner } from '@x402/svm';
|
|
5
|
+
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
+
import '@x402/evm';
|
|
7
|
+
import '@x402/core/http';
|
|
8
|
+
import '@x402/core/types';
|
|
9
|
+
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
|
+
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
|
+
/** How the wallet reads its key material — wired to `ctx.secrets.get` in an action. */
|
|
12
|
+
interface WalletDeps {
|
|
13
|
+
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
14
|
+
readonly getSecret: GetSecret;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a viem `LocalAccount` from a raw private key. The key may be given with
|
|
18
|
+
* or without the `0x` prefix. The account is a structural `ClientEvmSigner`
|
|
19
|
+
* (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
|
|
20
|
+
*/
|
|
21
|
+
declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
24
|
+
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
25
|
+
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
26
|
+
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
27
|
+
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
28
|
+
*/
|
|
29
|
+
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
30
|
+
/**
|
|
31
|
+
* Register the scheme family the configured network needs on `client`, wired to
|
|
32
|
+
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
33
|
+
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
34
|
+
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
35
|
+
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
36
|
+
* `@coinbase/cdp-sdk`).
|
|
37
|
+
*/
|
|
38
|
+
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
39
|
+
/** A payment-enabled `fetch`: same signature as the platform `fetch`. */
|
|
40
|
+
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
|
+
/** Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap. */
|
|
42
|
+
interface X402PayDeps extends WalletDeps {
|
|
43
|
+
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
44
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
48
|
+
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
49
|
+
* with unlimited spend authority.
|
|
50
|
+
*/
|
|
51
|
+
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
52
|
+
/** A configured pay rail: a payment-enabled `fetch` bounded by the spend policy. */
|
|
53
|
+
interface X402Pay {
|
|
54
|
+
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
55
|
+
readonly fetch: PayFetch;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
59
|
+
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
60
|
+
* signer) when the policy is unbounded.
|
|
61
|
+
*/
|
|
62
|
+
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
63
|
+
/**
|
|
64
|
+
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
65
|
+
*
|
|
66
|
+
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
67
|
+
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
68
|
+
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
69
|
+
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
70
|
+
* only when an action actually pays, and the single `SpendState` behind the
|
|
71
|
+
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
72
|
+
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
73
|
+
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
74
|
+
* fail-closed.
|
|
75
|
+
*/
|
|
76
|
+
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
77
|
+
export { type PayFetch, type WalletDeps, X402Pay, type X402PayConfig, type X402PayDeps, createPayFetch, createX402Pay, lazyX402Pay, registerWallet, resolveEvmAccount, resolveSvmSigner };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createPayFetch } from '../packem_shared/createPayFetch-O2vkvM1v.mjs';
|
|
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, recordSpend, usdToAtomic } from '../packem_shared/DEFAULT_STABLECOIN_DECIMALS-CSu5b5lD.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 };
|
package/package.json
CHANGED
|
@@ -1,10 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/x402",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
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
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"agents",
|
|
7
|
+
"cloudflare",
|
|
8
|
+
"lunora",
|
|
9
|
+
"micropayments",
|
|
10
|
+
"payments",
|
|
11
|
+
"stablecoin",
|
|
12
|
+
"usdc",
|
|
13
|
+
"workers",
|
|
14
|
+
"x402"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://lunora.sh",
|
|
17
|
+
"bugs": "https://github.com/anolilab/lunora/issues",
|
|
18
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Daniel Bannert",
|
|
21
|
+
"email": "d.bannert@anolilab.de"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/anolilab/lunora.git",
|
|
26
|
+
"directory": "packages/x402"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"./dist",
|
|
30
|
+
"__assets__",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE.md"
|
|
33
|
+
],
|
|
34
|
+
"type": "module",
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./charge": {
|
|
42
|
+
"types": "./dist/charge/index.d.ts",
|
|
43
|
+
"import": "./dist/charge/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./pay": {
|
|
46
|
+
"types": "./dist/pay/index.d.ts",
|
|
47
|
+
"import": "./dist/pay/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@lunora/errors": "1.0.0-alpha.4",
|
|
56
|
+
"@solana/kit": "5.5.1",
|
|
57
|
+
"@x402/core": "2.17.0",
|
|
58
|
+
"@x402/evm": "2.17.0",
|
|
59
|
+
"@x402/fetch": "2.17.0",
|
|
60
|
+
"@x402/svm": "2.17.0",
|
|
61
|
+
"viem": "2.54.1"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@coinbase/cdp-sdk": ">=1.0.0",
|
|
65
|
+
"@coinbase/x402": ">=2.0.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@coinbase/cdp-sdk": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@coinbase/x402": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": "^22.15.0 || >=24.11.0"
|
|
77
|
+
}
|
|
78
|
+
}
|