@xrpay/x402 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +191 -2
- package/dist/browser.js +2 -0
- package/dist/client.cjs +1552 -0
- package/dist/client.d.cts +46 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +1529 -0
- package/dist/commerce.cjs +1611 -0
- package/dist/commerce.d.cts +99 -0
- package/dist/commerce.d.ts +99 -0
- package/dist/commerce.js +1588 -0
- package/dist/mcp-tools.d.ts +56 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +1749 -0
- package/dist/protocol.cjs +1447 -0
- package/dist/protocol.d.cts +64 -0
- package/dist/protocol.d.ts +64 -0
- package/dist/protocol.js +1424 -0
- package/dist/server.cjs +1772 -0
- package/dist/server.d.cts +62 -0
- package/dist/server.d.ts +62 -0
- package/dist/server.js +1723 -0
- package/examples/buy-digital-product.mjs +44 -0
- package/examples/paid-api.mjs +25 -0
- package/package.json +101 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Client } from "xrpl";
|
|
2
|
+
import { type PaymentPayload, type PaymentRequired, type PaymentRequirements, type SettlementResponse, type VerifyResponse, type XrplNetwork } from "./protocol.cjs";
|
|
3
|
+
export * from "./protocol.cjs";
|
|
4
|
+
type LedgerClient = Pick<Client, "connect" | "disconnect" | "request" | "getLedgerIndex" | "submitAndWait">;
|
|
5
|
+
export interface FacilitatorOptions {
|
|
6
|
+
networks?: XrplNetwork[];
|
|
7
|
+
endpoints?: Partial<Record<XrplNetwork, string>>;
|
|
8
|
+
maxFeeDrops?: string;
|
|
9
|
+
createClient?: (network: XrplNetwork) => LedgerClient;
|
|
10
|
+
/** Must atomically claim a transaction hash across every serving process. */
|
|
11
|
+
reserveSettlement?: (txHash: string, ttlSeconds: number) => Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare class XrplFacilitator {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly pending;
|
|
16
|
+
constructor(options?: FacilitatorOptions);
|
|
17
|
+
supported(): {
|
|
18
|
+
kinds: {
|
|
19
|
+
x402Version: number;
|
|
20
|
+
scheme: string;
|
|
21
|
+
network: XrplNetwork;
|
|
22
|
+
extra: {
|
|
23
|
+
areFeesSponsored: boolean;
|
|
24
|
+
assetTransferMethod: string;
|
|
25
|
+
};
|
|
26
|
+
}[];
|
|
27
|
+
extensions: never[];
|
|
28
|
+
signers: {};
|
|
29
|
+
};
|
|
30
|
+
private newClient;
|
|
31
|
+
private verifyWithClient;
|
|
32
|
+
verify(payload: PaymentPayload, requirement: PaymentRequirements): Promise<VerifyResponse>;
|
|
33
|
+
private reserve;
|
|
34
|
+
/** Recover a previously persisted, purchase-owned attempt. Never creates a new
|
|
35
|
+
* authorization: a retry can only submit the identical signed transaction hash.
|
|
36
|
+
* Do not use this as a replay-permitting replacement for settle(). */
|
|
37
|
+
recoverSettlement(payload: PaymentPayload, requirement: PaymentRequirements, resubmit?: boolean): Promise<SettlementResponse>;
|
|
38
|
+
settle(payload: PaymentPayload, requirement: PaymentRequirements): Promise<SettlementResponse>;
|
|
39
|
+
}
|
|
40
|
+
export interface MiddlewareOptions {
|
|
41
|
+
payTo: string;
|
|
42
|
+
/** Human XRP or RLUSD amount; converted to the wire representation. */
|
|
43
|
+
amount: string;
|
|
44
|
+
currency: "XRP" | "RLUSD";
|
|
45
|
+
issuer?: string;
|
|
46
|
+
destinationTag?: number;
|
|
47
|
+
testnet?: boolean;
|
|
48
|
+
description?: string;
|
|
49
|
+
resource?: string;
|
|
50
|
+
ttlSeconds?: number;
|
|
51
|
+
challengeSecret?: string;
|
|
52
|
+
facilitatorUrl?: string;
|
|
53
|
+
facilitatorHeaders?: Record<string, string>;
|
|
54
|
+
facilitator?: Pick<XrplFacilitator, "settle">;
|
|
55
|
+
fetch?: typeof globalThis.fetch;
|
|
56
|
+
onSettled?: (payment: SettlementResponse, resource: string) => Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export declare function createPaymentRequirements(options: MiddlewareOptions, invoiceId: string): PaymentRequirements;
|
|
59
|
+
export declare function createPaymentRequired(options: MiddlewareOptions & {
|
|
60
|
+
resource: string;
|
|
61
|
+
}, invoiceId?: string): PaymentRequired;
|
|
62
|
+
export declare function x402Middleware(options: MiddlewareOptions): (req: any, res: any, next: any) => Promise<any>;
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Client } from "xrpl";
|
|
2
|
+
import { type PaymentPayload, type PaymentRequired, type PaymentRequirements, type SettlementResponse, type VerifyResponse, type XrplNetwork } from "./protocol.js";
|
|
3
|
+
export * from "./protocol.js";
|
|
4
|
+
type LedgerClient = Pick<Client, "connect" | "disconnect" | "request" | "getLedgerIndex" | "submitAndWait">;
|
|
5
|
+
export interface FacilitatorOptions {
|
|
6
|
+
networks?: XrplNetwork[];
|
|
7
|
+
endpoints?: Partial<Record<XrplNetwork, string>>;
|
|
8
|
+
maxFeeDrops?: string;
|
|
9
|
+
createClient?: (network: XrplNetwork) => LedgerClient;
|
|
10
|
+
/** Must atomically claim a transaction hash across every serving process. */
|
|
11
|
+
reserveSettlement?: (txHash: string, ttlSeconds: number) => Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare class XrplFacilitator {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly pending;
|
|
16
|
+
constructor(options?: FacilitatorOptions);
|
|
17
|
+
supported(): {
|
|
18
|
+
kinds: {
|
|
19
|
+
x402Version: number;
|
|
20
|
+
scheme: string;
|
|
21
|
+
network: XrplNetwork;
|
|
22
|
+
extra: {
|
|
23
|
+
areFeesSponsored: boolean;
|
|
24
|
+
assetTransferMethod: string;
|
|
25
|
+
};
|
|
26
|
+
}[];
|
|
27
|
+
extensions: never[];
|
|
28
|
+
signers: {};
|
|
29
|
+
};
|
|
30
|
+
private newClient;
|
|
31
|
+
private verifyWithClient;
|
|
32
|
+
verify(payload: PaymentPayload, requirement: PaymentRequirements): Promise<VerifyResponse>;
|
|
33
|
+
private reserve;
|
|
34
|
+
/** Recover a previously persisted, purchase-owned attempt. Never creates a new
|
|
35
|
+
* authorization: a retry can only submit the identical signed transaction hash.
|
|
36
|
+
* Do not use this as a replay-permitting replacement for settle(). */
|
|
37
|
+
recoverSettlement(payload: PaymentPayload, requirement: PaymentRequirements, resubmit?: boolean): Promise<SettlementResponse>;
|
|
38
|
+
settle(payload: PaymentPayload, requirement: PaymentRequirements): Promise<SettlementResponse>;
|
|
39
|
+
}
|
|
40
|
+
export interface MiddlewareOptions {
|
|
41
|
+
payTo: string;
|
|
42
|
+
/** Human XRP or RLUSD amount; converted to the wire representation. */
|
|
43
|
+
amount: string;
|
|
44
|
+
currency: "XRP" | "RLUSD";
|
|
45
|
+
issuer?: string;
|
|
46
|
+
destinationTag?: number;
|
|
47
|
+
testnet?: boolean;
|
|
48
|
+
description?: string;
|
|
49
|
+
resource?: string;
|
|
50
|
+
ttlSeconds?: number;
|
|
51
|
+
challengeSecret?: string;
|
|
52
|
+
facilitatorUrl?: string;
|
|
53
|
+
facilitatorHeaders?: Record<string, string>;
|
|
54
|
+
facilitator?: Pick<XrplFacilitator, "settle">;
|
|
55
|
+
fetch?: typeof globalThis.fetch;
|
|
56
|
+
onSettled?: (payment: SettlementResponse, resource: string) => Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export declare function createPaymentRequirements(options: MiddlewareOptions, invoiceId: string): PaymentRequirements;
|
|
59
|
+
export declare function createPaymentRequired(options: MiddlewareOptions & {
|
|
60
|
+
resource: string;
|
|
61
|
+
}, invoiceId?: string): PaymentRequired;
|
|
62
|
+
export declare function x402Middleware(options: MiddlewareOptions): (req: any, res: any, next: any) => Promise<any>;
|