mppx 0.21.0 → 0.21.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/CHANGELOG.md +19 -0
- package/dist/Errors.d.ts +55 -0
- package/dist/Errors.js +48 -0
- package/dist/Html.d.ts +1 -1
- package/dist/Html.js +2 -2
- package/dist/Method.d.ts +1 -1
- package/dist/cli/cli.js +138 -138
- package/dist/cli/internal.js +1 -1
- package/dist/cli/plugins/evm.js +1 -1
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/plugins/x402.js +1 -1
- package/dist/cli/utils.d.ts +2 -45
- package/dist/cli/utils.js +2 -79
- package/dist/cli/validate/index.js +5 -2
- package/dist/cli/validate/payment.d.ts +1 -1
- package/dist/cli/validate/payment.js +3 -3
- package/dist/cli/validate/print.d.ts +12 -0
- package/dist/cli/validate/print.js +35 -0
- package/dist/client/core.d.ts +6 -0
- package/dist/client/core.js +6 -0
- package/dist/client/index.d.ts +2 -8
- package/dist/client/index.js +2 -6
- package/dist/client/internal/protocols/Shared.js +1 -1
- package/dist/client/internal/protocols/X402.js +3 -3
- package/dist/evm/client/Charge.js +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/server/Charge.js +1 -1
- package/dist/integrations/x402/Evm.js +1 -1
- package/dist/integrations/x402/Negotiator.js +1 -1
- package/dist/internal/AcceptPayment.js +1 -1
- package/dist/internal/CredentialExpiry.js +1 -1
- package/dist/{mcp/internal/Credential.d.ts → internal/McpCredential.d.ts} +2 -2
- package/dist/{mcp/internal/Credential.js → internal/McpCredential.js} +2 -2
- package/dist/{server/internal → internal}/challengeMeta.js +1 -1
- package/dist/{server/internal → internal}/html/config.d.ts +2 -2
- package/dist/internal/pc.d.ts +46 -0
- package/dist/internal/pc.js +80 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/{x402 → internal/x402}/Header.js +1 -1
- package/dist/{x402 → internal/x402}/Siwx.d.ts +2 -2
- package/dist/{x402 → internal/x402}/Siwx.js +2 -2
- package/dist/{x402 → internal/x402}/Types.d.ts +1 -1
- package/dist/{x402 → internal/x402}/Types.js +1 -1
- package/dist/mcp/server/index.d.ts +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.js +6 -6
- package/dist/server/Transport.d.ts +2 -2
- package/dist/server/Transport.js +4 -4
- package/dist/server/index.d.ts +1 -8
- package/dist/server/index.js +1 -8
- package/dist/{mcp/server/Transport.d.ts → server/internal/mcpSdk.d.ts} +2 -2
- package/dist/{mcp/server/Transport.js → server/internal/mcpSdk.js} +3 -3
- package/dist/stripe/server/Charge.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +3 -0
- package/dist/tempo/Methods.js +3 -1
- package/dist/tempo/client/Charge.js +1 -1
- package/dist/tempo/client/Methods.d.ts +3 -0
- package/dist/tempo/client/index.d.ts +3 -0
- package/dist/tempo/client/index.js +1 -0
- package/dist/tempo/internal/configurable-account.d.ts +26 -0
- package/dist/tempo/internal/configurable-account.js +77 -0
- package/dist/tempo/internal/signature.d.ts +15 -0
- package/dist/tempo/internal/signature.js +43 -0
- package/dist/tempo/server/Charge.d.ts +1 -1
- package/dist/tempo/server/Charge.js +1 -1
- package/dist/tempo/server/Methods.d.ts +139 -4
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/ChannelOps.d.ts +29 -0
- package/dist/tempo/session/client/ChannelOps.js +108 -3
- package/dist/tempo/session/client/CredentialState.d.ts +6 -0
- package/dist/tempo/session/client/CredentialState.js +29 -4
- package/dist/tempo/session/client/Session.d.ts +3 -0
- package/dist/tempo/session/client/SessionManager.js +4 -0
- package/dist/tempo/session/precompile/Chain.d.ts +35 -1
- package/dist/tempo/session/precompile/Chain.js +52 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +46 -5
- package/dist/tempo/session/precompile/Voucher.js +78 -29
- package/dist/tempo/session/precompile/escrow.abi.d.ts +79 -0
- package/dist/tempo/session/precompile/escrow.abi.js +38 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +27 -0
- package/dist/tempo/session/server/ChannelStore.js +24 -3
- package/dist/tempo/session/server/CredentialVerification.d.ts +7 -1
- package/dist/tempo/session/server/CredentialVerification.js +91 -12
- package/dist/tempo/session/server/RequestState.d.ts +2 -0
- package/dist/tempo/session/server/RequestState.js +1 -0
- package/dist/tempo/session/server/Session.d.ts +11 -0
- package/dist/tempo/session/server/Session.js +10 -2
- package/dist/tempo/session/server/SponsorshipLimit.d.ts +11 -3
- package/dist/tempo/session/server/SponsorshipLimit.js +36 -4
- package/dist/tempo/subscription/KeyAuthorization.js +6 -2
- package/dist/{cli/validate → validation}/challenge.d.ts +1 -1
- package/dist/{cli/validate → validation}/challenge.js +4 -4
- package/dist/validation/core.d.ts +29 -2
- package/dist/validation/core.js +41 -10
- package/dist/{cli/validate → validation}/helpers.d.ts +0 -10
- package/dist/{cli/validate → validation}/helpers.js +1 -35
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +1 -1
- package/dist/x402/Assets.d.ts +1 -1
- package/dist/x402/client/Exact.d.ts +1 -1
- package/dist/x402/client/Exact.js +2 -2
- package/dist/x402/index.d.ts +4 -4
- package/dist/x402/index.js +4 -4
- package/dist/x402/internal/RouteBinding.d.ts +1 -1
- package/dist/x402/mcp.js +2 -2
- package/dist/x402/server/EvmCharge.d.ts +2 -2
- package/dist/x402/server/EvmCharge.js +4 -4
- package/dist/x402/server/Facilitator.d.ts +1 -1
- package/dist/x402/server/Facilitator.js +1 -1
- package/dist/x402/tempo.d.ts +48 -0
- package/dist/x402/tempo.js +68 -0
- package/package.json +21 -1
- /package/dist/{server/internal → internal}/challengeMeta.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.js +0 -0
- /package/dist/{server/internal → internal}/html/config.js +0 -0
- /package/dist/{server/internal → internal}/html/constants.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/constants.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.js +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.d.ts +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.js +0 -0
- /package/dist/{x402 → internal/x402}/Header.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.js +0 -0
- /package/dist/{cli/validate → validation}/messages.d.ts +0 -0
- /package/dist/{cli/validate → validation}/messages.js +0 -0
|
@@ -27,16 +27,6 @@ export declare function check(label: string, detail?: string): CheckResult;
|
|
|
27
27
|
export declare function fail(label: string, detail?: string, hint?: string): CheckResult;
|
|
28
28
|
export declare function warn(label: string, detail?: string, hint?: string): CheckResult;
|
|
29
29
|
export declare function skip(label: string, detail?: string, hint?: string): CheckResult;
|
|
30
|
-
export declare function printCheck(result: CheckResult): void;
|
|
31
|
-
export declare function printSection(title: string): void;
|
|
32
|
-
export type Counts = {
|
|
33
|
-
passed: number;
|
|
34
|
-
failed: number;
|
|
35
|
-
warnings: number;
|
|
36
|
-
suggested: number;
|
|
37
|
-
skipped: number;
|
|
38
|
-
};
|
|
39
|
-
export declare function printResults(results: CheckResult[], counts: Counts): void;
|
|
40
30
|
/** Fetches a validation target without automatic payments or redirected probes. */
|
|
41
31
|
export declare function fetchWithTimeout(url: RequestInfo | URL, init: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
42
32
|
export declare function formatBytes(bytes: number): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { identityOf, skipPayment, unwrapFetch } from '
|
|
2
|
-
import { pc } from '../utils.js';
|
|
1
|
+
import { identityOf, skipPayment, unwrapFetch } from '../client/internal/Fetch.js';
|
|
3
2
|
export function check(label, detail) {
|
|
4
3
|
return detail ? { label, detail, severity: 'pass' } : { label, severity: 'pass' };
|
|
5
4
|
}
|
|
@@ -25,39 +24,6 @@ export function skip(label, detail, hint) {
|
|
|
25
24
|
r.hint = hint;
|
|
26
25
|
return r;
|
|
27
26
|
}
|
|
28
|
-
const SEVERITY_ICONS = {
|
|
29
|
-
pass: pc.green('✓'),
|
|
30
|
-
fail: pc.red('✗'),
|
|
31
|
-
warn: pc.yellow('⚠'),
|
|
32
|
-
suggested: pc.cyan('◇'),
|
|
33
|
-
skip: pc.dim('○'),
|
|
34
|
-
};
|
|
35
|
-
export function printCheck(result) {
|
|
36
|
-
const icon = SEVERITY_ICONS[result.severity];
|
|
37
|
-
const text = result.detail ? `${result.label} (${result.detail})` : result.label;
|
|
38
|
-
console.log(` ${icon} ${text}`);
|
|
39
|
-
if (result.hint && result.severity !== 'pass') {
|
|
40
|
-
console.log(pc.dim(` → ${result.hint}`));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export function printSection(title) {
|
|
44
|
-
console.log(`\n${pc.bold(title)}`);
|
|
45
|
-
}
|
|
46
|
-
export function printResults(results, counts) {
|
|
47
|
-
for (const result of results) {
|
|
48
|
-
printCheck(result);
|
|
49
|
-
if (result.severity === 'pass')
|
|
50
|
-
counts.passed++;
|
|
51
|
-
else if (result.severity === 'fail')
|
|
52
|
-
counts.failed++;
|
|
53
|
-
else if (result.severity === 'warn')
|
|
54
|
-
counts.warnings++;
|
|
55
|
-
else if (result.severity === 'suggested')
|
|
56
|
-
counts.suggested++;
|
|
57
|
-
else if (result.severity === 'skip')
|
|
58
|
-
counts.skipped++;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
27
|
/** Fetches a validation target without automatic payments or redirected probes. */
|
|
62
28
|
export async function fetchWithTimeout(url, init, timeoutMs = 15_000) {
|
|
63
29
|
const controller = new AbortController();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { buildUrl, validate, validateStream } from './core.js';
|
|
2
|
-
export type { CheckResult, DiscoveryResult, EndpointSpec, EndpointValidationResult, PathParameter, ValidateEvent, ValidateOptions, ValidateResult, } from './core.js';
|
|
1
|
+
export { buildUrl, paymentSuccessLabel, validate, validateStream } from './core.js';
|
|
2
|
+
export type { CheckResult, DiscoveryResult, EndpointSpec, EndpointValidationResult, PathParameter, PaymentValidation, PaymentValidator, ValidateEvent, ValidateOptions, ValidateResult, } from './core.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/validation/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { buildUrl, validate, validateStream } from './core.js';
|
|
1
|
+
export { buildUrl, paymentSuccessLabel, validate, validateStream } from './core.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/x402/Assets.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Token } from 'viem/tokens';
|
|
2
2
|
import * as Currency_ from '../Currency.js';
|
|
3
|
-
import type { Asset, EvmNetwork, ExactTransfer } from '
|
|
3
|
+
import type { Asset, EvmNetwork, ExactTransfer } from '../internal/x402/Types.js';
|
|
4
4
|
declare const knownAsset: unique symbol;
|
|
5
5
|
/**
|
|
6
6
|
* Known x402 asset metadata: a token resolved to one chain, as `ousd(4217)` is, with the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Account } from 'viem';
|
|
2
2
|
import type * as Challenge from '../../Challenge.js';
|
|
3
|
+
import * as Types from '../../internal/x402/Types.js';
|
|
3
4
|
import * as Assets from '../Assets.js';
|
|
4
|
-
import * as Types from '../Types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Creates an x402 exact `PAYMENT-SIGNATURE` credential.
|
|
7
7
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getAddress, parseUnits } from 'viem';
|
|
2
|
+
import * as Header from '../../internal/x402/Header.js';
|
|
3
|
+
import * as Types from '../../internal/x402/Types.js';
|
|
2
4
|
import * as Assets from '../Assets.js';
|
|
3
|
-
import * as Header from '../Header.js';
|
|
4
5
|
import * as RouteBinding from '../internal/RouteBinding.js';
|
|
5
|
-
import * as Types from '../Types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Creates an x402 exact `PAYMENT-SIGNATURE` credential.
|
|
8
8
|
*/
|
package/dist/x402/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @deprecated Use `assets` instead. */
|
|
2
2
|
export * as Assets from './Assets.js';
|
|
3
|
-
export * as Header from '
|
|
4
|
-
export * as Siwx from '
|
|
5
|
-
export * as Types from '
|
|
3
|
+
export * as Header from '../internal/x402/Header.js';
|
|
4
|
+
export * as Siwx from '../internal/x402/Siwx.js';
|
|
5
|
+
export * as Types from '../internal/x402/Types.js';
|
|
6
6
|
export * as assets from './Assets.js';
|
|
7
|
-
export * from '
|
|
7
|
+
export * from '../internal/x402/Types.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/x402/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @deprecated Use `assets` instead. */
|
|
2
2
|
export * as Assets from './Assets.js';
|
|
3
|
-
export * as Header from '
|
|
4
|
-
export * as Siwx from '
|
|
5
|
-
export * as Types from '
|
|
3
|
+
export * as Header from '../internal/x402/Header.js';
|
|
4
|
+
export * as Siwx from '../internal/x402/Siwx.js';
|
|
5
|
+
export * as Types from '../internal/x402/Types.js';
|
|
6
6
|
export * as assets from './Assets.js';
|
|
7
|
-
export * from '
|
|
7
|
+
export * from '../internal/x402/Types.js';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/x402/mcp.js
CHANGED
|
@@ -4,10 +4,10 @@ import { createPaymentWrapper, MCP_PAYMENT_META_KEY, } from '@x402/mcp';
|
|
|
4
4
|
import * as Challenge from '../Challenge.js';
|
|
5
5
|
import * as Errors from '../Errors.js';
|
|
6
6
|
import * as Negotiator from '../integrations/x402/Negotiator.js';
|
|
7
|
+
import * as McpCredential from '../internal/McpCredential.js';
|
|
8
|
+
import { paymentRequiredHeader } from '../internal/x402/Types.js';
|
|
7
9
|
import * as Mcp from '../Mcp.js';
|
|
8
|
-
import * as McpCredential from '../mcp/internal/Credential.js';
|
|
9
10
|
import * as Receipt from '../Receipt.js';
|
|
10
|
-
import { paymentRequiredHeader } from './Types.js';
|
|
11
11
|
/**
|
|
12
12
|
* Creates an MCP tool wrapper that accepts both MPP and x402 payment metadata.
|
|
13
13
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type * as Credential from '../../Credential.js';
|
|
2
2
|
import * as Types from '../../evm/Types.js';
|
|
3
|
+
import * as Siwx from '../../internal/x402/Siwx.js';
|
|
4
|
+
import * as x402_Types from '../../internal/x402/Types.js';
|
|
3
5
|
import * as ServerTransport from '../../server/Transport.js';
|
|
4
|
-
import * as Siwx from '../Siwx.js';
|
|
5
|
-
import * as x402_Types from '../Types.js';
|
|
6
6
|
export type Options = {
|
|
7
7
|
/**
|
|
8
8
|
* Extra fields added to every x402 payment requirement's `extra`, for facilitators that read
|
|
@@ -6,13 +6,13 @@ import * as Challenge from '../../Challenge.js';
|
|
|
6
6
|
import * as Credential_ from '../../Credential.js';
|
|
7
7
|
import { VerificationFailedError } from '../../Errors.js';
|
|
8
8
|
import * as Types from '../../evm/Types.js';
|
|
9
|
+
import * as ChallengeMeta from '../../internal/challengeMeta.js';
|
|
10
|
+
import * as x402_Header from '../../internal/x402/Header.js';
|
|
11
|
+
import * as Siwx from '../../internal/x402/Siwx.js';
|
|
12
|
+
import * as x402_Types from '../../internal/x402/Types.js';
|
|
9
13
|
import * as PaymentRequest from '../../PaymentRequest.js';
|
|
10
|
-
import * as ChallengeMeta from '../../server/internal/challengeMeta.js';
|
|
11
14
|
import * as Scope from '../../server/internal/scope.js';
|
|
12
|
-
import * as x402_Header from '../Header.js';
|
|
13
15
|
import * as x402_RouteBinding from '../internal/RouteBinding.js';
|
|
14
|
-
import * as Siwx from '../Siwx.js';
|
|
15
|
-
import * as x402_Types from '../Types.js';
|
|
16
16
|
import * as x402_Facilitator from './Facilitator.js';
|
|
17
17
|
const pendingX402Credential = Symbol('mppx.evm.pendingX402Credential');
|
|
18
18
|
const x402Credential = Symbol('mppx.evm.x402Credential');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Types from '
|
|
1
|
+
import * as Types from '../../internal/x402/Types.js';
|
|
2
2
|
/** Headers to send with facilitator requests: a flat record, or one keyed by path. */
|
|
3
3
|
export type FacilitatorHeaders = Types.FacilitatorHeaders;
|
|
4
4
|
export type HttpOptions = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAddress } from 'viem';
|
|
2
2
|
import { FacilitatorResponseError } from '../../Errors.js';
|
|
3
|
-
import * as Types from '
|
|
3
|
+
import * as Types from '../../internal/x402/Types.js';
|
|
4
4
|
const mppxFetchWrapper = Symbol.for('mppx.fetch.wrapper');
|
|
5
5
|
/**
|
|
6
6
|
* Resolves an x402 facilitator URL, `{ url, headers }` config or client into a
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { RouteConfig } from '@x402/core/server';
|
|
2
|
+
import { x402ResourceServer } from '@x402/core/server';
|
|
3
|
+
/** The Tempo x402 facilitator. Fixed, so the API key only ever goes to Tempo over HTTPS. */
|
|
4
|
+
export declare const url = "https://api.tempo.xyz/v1/x402";
|
|
5
|
+
/** Base mainnet, the network the Tempo x402 facilitator settles USDC on. */
|
|
6
|
+
export declare const network = "eip155:8453";
|
|
7
|
+
/** Options for {@link tempoX402}. */
|
|
8
|
+
export type Options = {
|
|
9
|
+
/** Tempo API key with the `mpp:write` scope. @default process.env.TEMPO_API_KEY */
|
|
10
|
+
apiKey?: string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Tempo address that receives each payment, as `extra.tempoSettlement`. A route can override it.
|
|
13
|
+
* @default process.env.TEMPO_PAYOUT_ADDRESS
|
|
14
|
+
*/
|
|
15
|
+
payoutAddress?: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
/** Options for one route, passed to `route()`. */
|
|
18
|
+
export type RouteOptions = Omit<RouteConfig, 'accepts'> & {
|
|
19
|
+
/** Price per request in USD, such as `'$0.01'`. */
|
|
20
|
+
price: string;
|
|
21
|
+
/** Tempo address that receives this route's payments, such as a platform's seller. */
|
|
22
|
+
payoutAddress?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Wires the official x402 SDK to the Tempo x402 facilitator: buyers pay in USDC on Base and the
|
|
26
|
+
* seller is paid out on Tempo.
|
|
27
|
+
*
|
|
28
|
+
* Returns an `x402ResourceServer` with the exact EVM scheme registered and the API key on every
|
|
29
|
+
* facilitator request, and `route()`, which builds a route's config: it sets `payTo` to the
|
|
30
|
+
* facilitator's deposit address and `extra.tempoSettlement` to the payout address. The deposit
|
|
31
|
+
* address comes from the facilitator's `GET /supported`, which the x402 SDK reads when the
|
|
32
|
+
* middleware starts.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { paymentMiddleware } from '@x402/hono'
|
|
37
|
+
* import { tempoX402 } from 'mppx/x402/tempo'
|
|
38
|
+
*
|
|
39
|
+
* const tempo = tempoX402() // reads TEMPO_API_KEY and TEMPO_PAYOUT_ADDRESS
|
|
40
|
+
* app.use(paymentMiddleware({ 'GET /weather': tempo.route({ price: '$0.01' }) }, tempo.server))
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function tempoX402(options?: Options): {
|
|
44
|
+
payTo: () => string;
|
|
45
|
+
route: (parameters: RouteOptions) => RouteConfig;
|
|
46
|
+
server: x402ResourceServer;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=tempo.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { HTTPFacilitatorClient, x402ResourceServer } from '@x402/core/server';
|
|
2
|
+
import { ExactEvmScheme } from '@x402/evm/exact/server';
|
|
3
|
+
import { isAddress } from 'viem';
|
|
4
|
+
/** The Tempo x402 facilitator. Fixed, so the API key only ever goes to Tempo over HTTPS. */
|
|
5
|
+
export const url = 'https://api.tempo.xyz/v1/x402';
|
|
6
|
+
/** Base mainnet, the network the Tempo x402 facilitator settles USDC on. */
|
|
7
|
+
export const network = 'eip155:8453';
|
|
8
|
+
/**
|
|
9
|
+
* Wires the official x402 SDK to the Tempo x402 facilitator: buyers pay in USDC on Base and the
|
|
10
|
+
* seller is paid out on Tempo.
|
|
11
|
+
*
|
|
12
|
+
* Returns an `x402ResourceServer` with the exact EVM scheme registered and the API key on every
|
|
13
|
+
* facilitator request, and `route()`, which builds a route's config: it sets `payTo` to the
|
|
14
|
+
* facilitator's deposit address and `extra.tempoSettlement` to the payout address. The deposit
|
|
15
|
+
* address comes from the facilitator's `GET /supported`, which the x402 SDK reads when the
|
|
16
|
+
* middleware starts.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { paymentMiddleware } from '@x402/hono'
|
|
21
|
+
* import { tempoX402 } from 'mppx/x402/tempo'
|
|
22
|
+
*
|
|
23
|
+
* const tempo = tempoX402() // reads TEMPO_API_KEY and TEMPO_PAYOUT_ADDRESS
|
|
24
|
+
* app.use(paymentMiddleware({ 'GET /weather': tempo.route({ price: '$0.01' }) }, tempo.server))
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function tempoX402(options = {}) {
|
|
28
|
+
const env = globalThis.process
|
|
29
|
+
?.env;
|
|
30
|
+
const apiKey = options.apiKey || env?.TEMPO_API_KEY;
|
|
31
|
+
if (!apiKey)
|
|
32
|
+
throw new Error('tempoX402 requires `apiKey` or TEMPO_API_KEY.');
|
|
33
|
+
const payoutAddress = options.payoutAddress || env?.TEMPO_PAYOUT_ADDRESS;
|
|
34
|
+
const headers = { 'tempo-api-key': apiKey };
|
|
35
|
+
const server = new x402ResourceServer(new HTTPFacilitatorClient({
|
|
36
|
+
// GET /supported is public: the key goes only with verify and settle.
|
|
37
|
+
createAuthHeaders: async () => ({ settle: headers, supported: {}, verify: headers }),
|
|
38
|
+
url,
|
|
39
|
+
})).register(network, new ExactEvmScheme());
|
|
40
|
+
/** Tempo's deposit address for this network, from the SDK's `GET /supported` read. */
|
|
41
|
+
function payTo() {
|
|
42
|
+
const address = server.getSupportedKind(2, network, 'exact')?.extra?.payTo;
|
|
43
|
+
if (typeof address !== 'string')
|
|
44
|
+
throw new Error(`Tempo x402 facilitator publishes no payTo for exact on ${network}.`);
|
|
45
|
+
return address;
|
|
46
|
+
}
|
|
47
|
+
/** Builds a paid route's config. Throws when neither the route nor {@link tempoX402} names a payout address. */
|
|
48
|
+
function route(parameters) {
|
|
49
|
+
const { payoutAddress: routePayoutAddress, price, ...rest } = parameters;
|
|
50
|
+
const tempoSettlement = routePayoutAddress ?? payoutAddress;
|
|
51
|
+
if (!tempoSettlement)
|
|
52
|
+
throw new Error('tempoX402 requires a payout address: pass `payoutAddress` or set TEMPO_PAYOUT_ADDRESS.');
|
|
53
|
+
if (!isAddress(tempoSettlement, { strict: false }))
|
|
54
|
+
throw new Error(`tempoX402 payout address is not an address: ${tempoSettlement}`);
|
|
55
|
+
return {
|
|
56
|
+
...rest,
|
|
57
|
+
accepts: {
|
|
58
|
+
extra: { tempoSettlement },
|
|
59
|
+
network,
|
|
60
|
+
payTo: () => payTo(),
|
|
61
|
+
price,
|
|
62
|
+
scheme: 'exact',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return { payTo, route, server };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=tempo.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mppx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.2",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/wevm/mppx#readme",
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"types": "./dist/client/index.d.ts",
|
|
32
32
|
"default": "./dist/client/index.js"
|
|
33
33
|
},
|
|
34
|
+
"./client/core": {
|
|
35
|
+
"types": "./dist/client/core.d.ts",
|
|
36
|
+
"default": "./dist/client/core.js"
|
|
37
|
+
},
|
|
34
38
|
"./client/node": {
|
|
35
39
|
"types": "./dist/client/node.d.ts",
|
|
36
40
|
"default": "./dist/client/node.js"
|
|
@@ -123,10 +127,22 @@
|
|
|
123
127
|
"types": "./dist/x402/mcp.d.ts",
|
|
124
128
|
"default": "./dist/x402/mcp.js"
|
|
125
129
|
},
|
|
130
|
+
"./x402/tempo": {
|
|
131
|
+
"types": "./dist/x402/tempo.d.ts",
|
|
132
|
+
"default": "./dist/x402/tempo.js"
|
|
133
|
+
},
|
|
126
134
|
"./tempo": {
|
|
127
135
|
"types": "./dist/tempo/index.d.ts",
|
|
128
136
|
"default": "./dist/tempo/index.js"
|
|
129
137
|
},
|
|
138
|
+
"./tempo/client": {
|
|
139
|
+
"types": "./dist/tempo/client/index.d.ts",
|
|
140
|
+
"default": "./dist/tempo/client/index.js"
|
|
141
|
+
},
|
|
142
|
+
"./tempo/server": {
|
|
143
|
+
"types": "./dist/tempo/server/index.d.ts",
|
|
144
|
+
"default": "./dist/tempo/server/index.js"
|
|
145
|
+
},
|
|
130
146
|
"./extensions/identity": {
|
|
131
147
|
"types": "./dist/extensions/identity/index.d.ts",
|
|
132
148
|
"default": "./dist/extensions/identity/index.js"
|
|
@@ -200,6 +216,7 @@
|
|
|
200
216
|
"@modelcontextprotocol/sdk": ">=1.25.0",
|
|
201
217
|
"@stripe/agent-identity": ">=0.3.0",
|
|
202
218
|
"@x402/core": ">=2.22.0",
|
|
219
|
+
"@x402/evm": ">=2.22.0",
|
|
203
220
|
"@x402/express": ">=2.22.0",
|
|
204
221
|
"@x402/hono": ">=2.22.0",
|
|
205
222
|
"@x402/mcp": ">=2.22.0",
|
|
@@ -220,6 +237,9 @@
|
|
|
220
237
|
"@x402/core": {
|
|
221
238
|
"optional": true
|
|
222
239
|
},
|
|
240
|
+
"@x402/evm": {
|
|
241
|
+
"optional": true
|
|
242
|
+
},
|
|
223
243
|
"@x402/express": {
|
|
224
244
|
"optional": true
|
|
225
245
|
},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|