@relai-fi/x402 0.6.5 → 0.6.7
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 +251 -0
- package/dist/bridge.cjs +109 -0
- package/dist/bridge.cjs.map +1 -0
- package/dist/bridge.d.cts +78 -0
- package/dist/bridge.d.ts +78 -0
- package/dist/bridge.js +80 -0
- package/dist/bridge.js.map +1 -0
- package/dist/client.cjs +131 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +13 -1
- package/dist/client.d.ts +13 -1
- package/dist/client.js +131 -1
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +586 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +291 -30
- package/dist/index.d.ts +291 -30
- package/dist/index.js +578 -105
- package/dist/index.js.map +1 -1
- package/dist/mpp/bridge-client.cjs +23922 -0
- package/dist/mpp/bridge-client.cjs.map +1 -0
- package/dist/mpp/bridge-client.d.cts +58 -0
- package/dist/mpp/bridge-client.d.ts +58 -0
- package/dist/mpp/bridge-client.js +23892 -0
- package/dist/mpp/bridge-client.js.map +1 -0
- package/dist/mpp/bridge-method.cjs +13202 -0
- package/dist/mpp/bridge-method.cjs.map +1 -0
- package/dist/mpp/bridge-method.d.cts +69 -0
- package/dist/mpp/bridge-method.d.ts +69 -0
- package/dist/mpp/bridge-method.js +13181 -0
- package/dist/mpp/bridge-method.js.map +1 -0
- package/dist/mpp/bridge-server.cjs +13887 -0
- package/dist/mpp/bridge-server.cjs.map +1 -0
- package/dist/mpp/bridge-server.d.cts +62 -0
- package/dist/mpp/bridge-server.d.ts +62 -0
- package/dist/mpp/bridge-server.js +13866 -0
- package/dist/mpp/bridge-server.js.map +1 -0
- package/dist/mpp/evm-server.cjs +49 -33
- package/dist/mpp/evm-server.cjs.map +1 -1
- package/dist/mpp/evm-server.js +49 -33
- package/dist/mpp/evm-server.js.map +1 -1
- package/dist/mpp/verify-erc20.cjs +71 -0
- package/dist/mpp/verify-erc20.cjs.map +1 -0
- package/dist/mpp/verify-erc20.d.cts +27 -0
- package/dist/mpp/verify-erc20.d.ts +27 -0
- package/dist/mpp/verify-erc20.js +46 -0
- package/dist/mpp/verify-erc20.js.map +1 -0
- package/dist/mpp/verify-spl.cjs +96 -0
- package/dist/mpp/verify-spl.cjs.map +1 -0
- package/dist/mpp/verify-spl.d.cts +30 -0
- package/dist/mpp/verify-spl.d.ts +30 -0
- package/dist/mpp/verify-spl.js +71 -0
- package/dist/mpp/verify-spl.js.map +1 -0
- package/dist/mpp/with-bridge.cjs +23956 -0
- package/dist/mpp/with-bridge.cjs.map +1 -0
- package/dist/mpp/with-bridge.d.cts +53 -0
- package/dist/mpp/with-bridge.d.ts +53 -0
- package/dist/mpp/with-bridge.js +23926 -0
- package/dist/mpp/with-bridge.js.map +1 -0
- package/dist/plugins.d.cts +2 -2
- package/dist/plugins.d.ts +2 -2
- package/dist/react/index.cjs +131 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +131 -1
- package/dist/react/index.js.map +1 -1
- package/dist/{server-DaySqG5H.d.ts → server-D9ZfrFFx.d.ts} +1 -1
- package/dist/{server-CBZ2RjEP.d.cts → server-DgMG2zhy.d.cts} +1 -1
- package/dist/server.cjs +6 -39
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +6 -39
- package/dist/server.js.map +1 -1
- package/dist/{types-Y9ni5XwY.d.cts → types-DjEveKgt.d.cts} +1 -1
- package/dist/{types-Y9ni5XwY.d.ts → types-DjEveKgt.d.ts} +1 -1
- package/package.json +31 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { B as BridgePluginConfig, D as DynamicPrice, j as FeedbackPluginConfig, F as FreeTierPluginConfig, M as MppServerHandler, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, i as ScorePluginConfig, S as SettleResult, k as SolanaFeedbackPluginConfig, c as StripePayTo, R as default, s as stripePayTo } from './server-
|
|
1
|
+
export { B as BridgePluginConfig, D as DynamicPrice, j as FeedbackPluginConfig, F as FreeTierPluginConfig, M as MppServerHandler, b as PaymentInfo, g as PluginContext, h as PluginResult, P as ProtectOptions, R as Relai, d as RelaiIntegritasFlow, e as RelaiIntegritasOptions, f as RelaiPlugin, a as RelaiServerConfig, i as ScorePluginConfig, S as SettleResult, k as SolanaFeedbackPluginConfig, c as StripePayTo, R as default, s as stripePayTo } from './server-D9ZfrFFx.js';
|
|
2
2
|
export { MppHandler, RelayWebSocketFactory, RelayWebSocketLike, X402Client, X402ClientConfig, X402FetchInit, X402IntegritasConfig, X402IntegritasFlow, X402NetworkSelectionMode, X402RelayWsConfig, X402RelayWsError, X402RelayWsResponse, X402RequestOptions, default as createX402Client } from './client.js';
|
|
3
3
|
export { RelayFeedbackConfig, submitRelayFeedback } from './relay-feedback.js';
|
|
4
|
-
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired,
|
|
4
|
+
export { A as AcceptsExtra, B as BASE_MAINNET_NETWORK, C as CAIP2_TO_NETWORK, b as CHAIN_IDS, E as EXPLORER_TX_URL, l as EvmWallet, N as NETWORK_CAIP2, e as NETWORK_LABELS, d as NETWORK_TOKENS, c as NetworkToken, P as PaymentAccept, o as PaymentRequired, a as RELAI_FACILITATOR_URL, i as RELAI_NETWORKS, R as RelaiNetwork, m as ResourceInfo, f as SOLANA_MAINNET_NETWORK, S as SolanaWallet, U as USDC_ADDRESSES, h as USDC_BASE, g as USDC_SOLANA, W as WalletSet, k as isEvm, j as isSolana, n as normalizeNetwork, r as resolveToken } from './types-DjEveKgt.js';
|
|
5
5
|
export { BridgeBalances, BridgeQuoteResult, BridgeResult } from './management.js';
|
|
6
6
|
export { NETWORK_V1_TO_V2, NETWORK_V2_TO_V1, convertPayloadToVersion, convertV1ToV2, convertV2ToV1, detectPayloadVersion, formatUsd, fromAtomicUnits, isEvmNetwork, isSolanaNetwork, networkV1ToV2, networkV2ToV1, normalizePaymentHeader, toAtomicUnits } from './utils/index.js';
|
|
7
7
|
export { charge as evmChargeMethod } from './mpp/evm-method.js';
|
|
@@ -15,32 +15,96 @@ import 'viem';
|
|
|
15
15
|
/**
|
|
16
16
|
* Payment Code API — BLIK-style x402 payment codes
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* createPrivateKeySigner() — create a signer from a raw private key (for agents/bots)
|
|
19
|
+
* generatePaymentCode() — sign EIP-3009 authorization and register on SKALE L3
|
|
20
|
+
* generatePaymentCodesBatch() — register up to 20 codes in one call (agent budget)
|
|
21
|
+
* redeemPaymentCode() — redeem a code (payee calls this, triggers Base L2 settlement)
|
|
22
|
+
* getPaymentCode() — check code status
|
|
23
|
+
* cancelPaymentCode() — cancel/revoke a code before redemption
|
|
21
24
|
*/
|
|
25
|
+
type PaymentCodeNetwork = "base" | "base-sepolia" | "skale-base" | "skale-base-sepolia";
|
|
26
|
+
interface NetworkConfig {
|
|
27
|
+
chainId: number;
|
|
28
|
+
usdc: string;
|
|
29
|
+
/** EIP-712 domain name of the USDC contract on this network */
|
|
30
|
+
domainName: string;
|
|
31
|
+
rpc: string;
|
|
32
|
+
settlementNetwork: string;
|
|
33
|
+
}
|
|
34
|
+
declare const NETWORK_CONFIGS: Record<PaymentCodeNetwork, NetworkConfig>;
|
|
35
|
+
interface PaymentCodeSigner {
|
|
36
|
+
getAddress(): Promise<string>;
|
|
37
|
+
signTypedData(domain: object, types: object, value: object): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an EIP-712 signer from a raw private key.
|
|
41
|
+
* Intended for agents/bots running server-side with a custodial wallet.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const signer = createPrivateKeySigner(process.env.AGENT_PRIVATE_KEY!);
|
|
45
|
+
* const { code } = await generatePaymentCode(config, { signer, value: 1_000_000n });
|
|
46
|
+
*/
|
|
47
|
+
declare function createPrivateKeySigner(privateKey: string): PaymentCodeSigner;
|
|
22
48
|
interface PaymentCodeConfig {
|
|
49
|
+
/** RelAI facilitator base URL (default: https://relai.fi/facilitator) */
|
|
23
50
|
facilitatorUrl?: string;
|
|
24
51
|
}
|
|
25
52
|
interface GeneratePaymentCodeParams {
|
|
26
|
-
/** EIP-3009 signer —
|
|
27
|
-
signer:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/** Payee wallet address */
|
|
32
|
-
to: string;
|
|
33
|
-
/** Amount in USDC micro-units (6 decimals), e.g. 1000 = $0.001 */
|
|
53
|
+
/** EIP-3009 signer — use createPrivateKeySigner() for agents */
|
|
54
|
+
signer: PaymentCodeSigner;
|
|
55
|
+
/** Settlement network (default: "base-sepolia") */
|
|
56
|
+
network?: PaymentCodeNetwork;
|
|
57
|
+
/** Amount in USDC micro-units (6 decimals), e.g. 1_000_000 = $1.00 */
|
|
34
58
|
value: string | bigint;
|
|
35
|
-
/**
|
|
59
|
+
/** TTL in seconds (default: 86400 = 24 h) */
|
|
60
|
+
ttl?: number;
|
|
61
|
+
/** Optional message shown to the recipient when they claim */
|
|
62
|
+
description?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Lock the code to a specific payee address — only that address can redeem it.
|
|
65
|
+
* Useful for agent-to-agent payments or scheduled disbursements.
|
|
66
|
+
*/
|
|
67
|
+
payee?: string;
|
|
68
|
+
/** Override the USDC contract address */
|
|
36
69
|
usdcContract?: string;
|
|
37
|
-
|
|
70
|
+
}
|
|
71
|
+
interface BatchCodeItem {
|
|
72
|
+
/** Amount in USDC micro-units */
|
|
73
|
+
value: string | bigint;
|
|
74
|
+
/** TTL in seconds (default: 86400) */
|
|
38
75
|
ttl?: number;
|
|
39
76
|
}
|
|
77
|
+
interface GeneratePaymentCodesBatchParams {
|
|
78
|
+
signer: PaymentCodeSigner;
|
|
79
|
+
/** Settlement network (default: "base-sepolia") */
|
|
80
|
+
network?: PaymentCodeNetwork;
|
|
81
|
+
/** Up to 20 codes to register */
|
|
82
|
+
codes: BatchCodeItem[];
|
|
83
|
+
/** Lock all codes to a specific payee */
|
|
84
|
+
payee?: string;
|
|
85
|
+
/** Override the USDC contract address */
|
|
86
|
+
usdcContract?: string;
|
|
87
|
+
/** RelAI auth token (required — batch endpoint is authenticated) */
|
|
88
|
+
authToken: string;
|
|
89
|
+
}
|
|
40
90
|
interface PaymentCode {
|
|
41
91
|
code: string;
|
|
42
92
|
validBefore: number;
|
|
43
93
|
expiresIn: number;
|
|
94
|
+
relayerAddress: string;
|
|
95
|
+
settlementNetwork: string;
|
|
96
|
+
locked: boolean;
|
|
97
|
+
description?: string | null;
|
|
98
|
+
}
|
|
99
|
+
interface BatchPaymentCodesResult {
|
|
100
|
+
registered: number;
|
|
101
|
+
codes: Pick<PaymentCode, "code" | "validBefore" | "expiresIn" | "locked">[];
|
|
102
|
+
failed: {
|
|
103
|
+
index: number;
|
|
104
|
+
error: string;
|
|
105
|
+
}[];
|
|
106
|
+
relayerAddress: string;
|
|
107
|
+
settlementNetwork: string;
|
|
44
108
|
}
|
|
45
109
|
interface RedeemResult {
|
|
46
110
|
success: boolean;
|
|
@@ -48,9 +112,17 @@ interface RedeemResult {
|
|
|
48
112
|
l3TxHash: string;
|
|
49
113
|
l2TxHash: string;
|
|
50
114
|
explorerUrl: string;
|
|
115
|
+
settlementNetwork: string;
|
|
116
|
+
private: boolean;
|
|
51
117
|
amount: string;
|
|
52
118
|
from: string;
|
|
53
|
-
|
|
119
|
+
payee: string;
|
|
120
|
+
/** Amount returned as change (µUSDC), present when invoiceAmount < code value */
|
|
121
|
+
change?: string;
|
|
122
|
+
/** How the change was returned: 'code' = new payment code, 'wallet' = sent to from address */
|
|
123
|
+
changeMode?: 'code' | 'wallet';
|
|
124
|
+
/** New payment code for the change amount (present when changeMode === 'code') */
|
|
125
|
+
changeCode?: string;
|
|
54
126
|
}
|
|
55
127
|
interface CodeStatus {
|
|
56
128
|
code: string;
|
|
@@ -61,31 +133,220 @@ interface CodeStatus {
|
|
|
61
133
|
redeemed: boolean;
|
|
62
134
|
expired: boolean;
|
|
63
135
|
redeemable: boolean;
|
|
136
|
+
settlementNetwork: string | null;
|
|
137
|
+
description: string | null;
|
|
64
138
|
}
|
|
65
139
|
/**
|
|
66
|
-
* Generate a BLIK-style x402 payment code backed by EIP-3009.
|
|
140
|
+
* Generate a BLIK-style x402 payment code backed by an EIP-3009 authorization.
|
|
141
|
+
* The facilitator registers it on SKALE L3 — no gas cost for the payer.
|
|
142
|
+
* The `to` address (settler/relayer) is fetched automatically from the facilitator.
|
|
143
|
+
*
|
|
144
|
+
* @example Agent usage (Node.js / server-side):
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { createPrivateKeySigner, generatePaymentCode } from '@relai-fi/x402';
|
|
147
|
+
*
|
|
148
|
+
* const signer = createPrivateKeySigner(process.env.AGENT_PRIVATE_KEY!);
|
|
149
|
+
* const { code } = await generatePaymentCode(
|
|
150
|
+
* { facilitatorUrl: 'https://relai.fi/facilitator' },
|
|
151
|
+
* { signer, value: 1_000_000n, ttl: 3600, description: 'coffee' },
|
|
152
|
+
* );
|
|
153
|
+
* // code = "X7K9P2AB" — share with the payee, e.g. via SMS / email / QR
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function generatePaymentCode(config: PaymentCodeConfig, params: GeneratePaymentCodeParams): Promise<PaymentCode>;
|
|
157
|
+
/**
|
|
158
|
+
* Generate multiple payment codes in one call — agent budget allocation pattern.
|
|
159
|
+
* Each code is independently signed. Max 20 codes per call.
|
|
160
|
+
* Requires a valid RelAI `authToken`.
|
|
67
161
|
*
|
|
68
162
|
* @example
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* ttl:
|
|
163
|
+
* ```ts
|
|
164
|
+
* const { codes } = await generatePaymentCodesBatch(config, {
|
|
165
|
+
* signer,
|
|
166
|
+
* authToken: process.env.RELAI_API_KEY!,
|
|
167
|
+
* codes: Array(10).fill({ value: 1_000_000n, ttl: 3600 }), // 10 × $1.00
|
|
74
168
|
* });
|
|
75
|
-
* // code = "X7K9P2AB"
|
|
169
|
+
* // codes[0].code = "X7K9P2AB", codes[1].code = "B3R5N7QA", …
|
|
170
|
+
* ```
|
|
76
171
|
*/
|
|
77
|
-
declare function
|
|
172
|
+
declare function generatePaymentCodesBatch(config: PaymentCodeConfig, params: GeneratePaymentCodesBatchParams): Promise<BatchPaymentCodesResult>;
|
|
78
173
|
/**
|
|
79
|
-
* Redeem a payment code. Triggers Base L2
|
|
174
|
+
* Redeem a payment code. Triggers USDC settlement on Base L2 or SKALE.
|
|
175
|
+
* No wallet connection needed on the payee side — just provide a destination address.
|
|
80
176
|
*
|
|
81
177
|
* @example
|
|
82
|
-
*
|
|
83
|
-
*
|
|
178
|
+
* ```ts
|
|
179
|
+
* const result = await redeemPaymentCode(config, "X7K9P2AB", "0xYourWallet...");
|
|
180
|
+
* console.log(result.explorerUrl); // https://sepolia.basescan.org/tx/0x...
|
|
181
|
+
* ```
|
|
84
182
|
*/
|
|
85
|
-
declare function redeemPaymentCode(config: PaymentCodeConfig, code: string
|
|
183
|
+
declare function redeemPaymentCode(config: PaymentCodeConfig, code: string,
|
|
184
|
+
/** Address to receive the USDC (required unless code was registered with a locked payee) */
|
|
185
|
+
payee?: string): Promise<RedeemResult>;
|
|
86
186
|
/**
|
|
87
|
-
* Get the status of a payment code.
|
|
187
|
+
* Get the current status of a payment code.
|
|
88
188
|
*/
|
|
89
189
|
declare function getPaymentCode(config: PaymentCodeConfig, code: string): Promise<CodeStatus>;
|
|
190
|
+
/**
|
|
191
|
+
* Cancel a payment code before it is redeemed.
|
|
192
|
+
* Soft-cancels immediately (relayer will refuse to settle);
|
|
193
|
+
* also attempts a hard-cancel on SKALE L3 to mark it used on-chain.
|
|
194
|
+
*/
|
|
195
|
+
declare function cancelPaymentCode(config: PaymentCodeConfig, code: string): Promise<{
|
|
196
|
+
success: boolean;
|
|
197
|
+
l3TxHash: string | null;
|
|
198
|
+
}>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Payment Request API — Merchant-initiated x402 payment codes
|
|
202
|
+
*
|
|
203
|
+
* Flow (reverse of payment-codes):
|
|
204
|
+
* 1. Merchant calls createPayRequest() → gets a short code
|
|
205
|
+
* 2. Merchant shares the code with the buyer (QR, link, message)
|
|
206
|
+
* 3. Buyer calls getPayRequest() → sees amount, merchant, description
|
|
207
|
+
* 4. Buyer calls payPayRequest() with their signer → USDC sent directly to merchant
|
|
208
|
+
*
|
|
209
|
+
* createPayRequest() — merchant creates a payment request (no signature needed)
|
|
210
|
+
* getPayRequest() — buyer reads request details (amount, merchant, description)
|
|
211
|
+
* payPayRequest() — buyer signs EIP-3009 and submits payment
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
interface PaymentRequestConfig {
|
|
215
|
+
/** RelAI facilitator base URL (default: https://relai.fi/facilitator) */
|
|
216
|
+
facilitatorUrl?: string;
|
|
217
|
+
}
|
|
218
|
+
interface CreatePayRequestParams {
|
|
219
|
+
/** Merchant wallet address — receives the USDC */
|
|
220
|
+
to: string;
|
|
221
|
+
/** Amount in USDC micro-units (6 decimals), e.g. 1_000_000 = $1.00 */
|
|
222
|
+
amount: number | bigint;
|
|
223
|
+
/** Settlement network (default: "base-sepolia") */
|
|
224
|
+
network?: PaymentCodeNetwork;
|
|
225
|
+
/** Payment description shown to the buyer, e.g. "Coffee ☕" */
|
|
226
|
+
description?: string;
|
|
227
|
+
/** Code TTL in seconds (min 60, max 86400, default 3600) */
|
|
228
|
+
ttlSeconds?: number;
|
|
229
|
+
}
|
|
230
|
+
interface PayRequest {
|
|
231
|
+
/** 8-character alphanumeric code, e.g. "X7K9P2AB" */
|
|
232
|
+
code: string;
|
|
233
|
+
/** Unix timestamp when the request expires */
|
|
234
|
+
validUntil: number;
|
|
235
|
+
/** Address the buyer must use as EIP-3009 `to` (settler/relayer, NOT merchant directly) */
|
|
236
|
+
toAddress: string;
|
|
237
|
+
/** USDC contract on the settlement network */
|
|
238
|
+
usdcContract: string;
|
|
239
|
+
}
|
|
240
|
+
interface PayRequestInfo {
|
|
241
|
+
code: string;
|
|
242
|
+
/** Merchant wallet address */
|
|
243
|
+
to: string;
|
|
244
|
+
/** EIP-3009 `to` address (settler/relayer) */
|
|
245
|
+
toAddress: string;
|
|
246
|
+
amount: number;
|
|
247
|
+
network: string;
|
|
248
|
+
usdcContract: string;
|
|
249
|
+
description: string | null;
|
|
250
|
+
validUntil: number;
|
|
251
|
+
expiresIn: number;
|
|
252
|
+
status: "pending" | "processing" | "paid";
|
|
253
|
+
payable: boolean;
|
|
254
|
+
}
|
|
255
|
+
interface PayRequestResult {
|
|
256
|
+
success: boolean;
|
|
257
|
+
code: string;
|
|
258
|
+
payTxHash: string | null;
|
|
259
|
+
explorerUrl?: string;
|
|
260
|
+
network?: string;
|
|
261
|
+
private?: boolean;
|
|
262
|
+
amount?: string;
|
|
263
|
+
/** Merchant address that received the USDC */
|
|
264
|
+
to?: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Create a payment request — merchant/seller side.
|
|
268
|
+
* No signing required. Returns a short code to share with the buyer.
|
|
269
|
+
*
|
|
270
|
+
* @example Merchant/agent creates a $5 invoice:
|
|
271
|
+
* ```ts
|
|
272
|
+
* const req = await createPayRequest(config, {
|
|
273
|
+
* to: '0xMerchantWallet...',
|
|
274
|
+
* amount: 5_000_000, // $5.00 USDC
|
|
275
|
+
* network: 'base-sepolia',
|
|
276
|
+
* description: 'Order #1234 — 2× coffee',
|
|
277
|
+
* ttlSeconds: 900, // 15 minutes
|
|
278
|
+
* });
|
|
279
|
+
* // req.code = "X7K9P2AB" — share via QR / link / message
|
|
280
|
+
* // link: https://relai.fi/pay#X7K9P2AB
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
declare function createPayRequest(config: PaymentRequestConfig, params: CreatePayRequestParams): Promise<PayRequest>;
|
|
284
|
+
/**
|
|
285
|
+
* Get the status and details of a payment request — buyer side.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* const info = await getPayRequest(config, 'X7K9P2AB');
|
|
290
|
+
* console.log(`Pay $${info.amount / 1e6} to ${info.to}`);
|
|
291
|
+
* console.log('Description:', info.description);
|
|
292
|
+
* console.log('Payable:', info.payable);
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
declare function getPayRequest(config: PaymentRequestConfig, code: string): Promise<PayRequestInfo>;
|
|
296
|
+
/**
|
|
297
|
+
* Pay a payment request — buyer side.
|
|
298
|
+
* Signs an EIP-3009 authorization and submits it to the facilitator,
|
|
299
|
+
* which executes the on-chain transfer to the merchant.
|
|
300
|
+
*
|
|
301
|
+
* @example Buyer pays using a private key (agent):
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { createPrivateKeySigner } from '@relai-fi/x402';
|
|
304
|
+
*
|
|
305
|
+
* const signer = createPrivateKeySigner(process.env.BUYER_PRIVATE_KEY!);
|
|
306
|
+
* const result = await payPayRequest(config, 'X7K9P2AB', signer);
|
|
307
|
+
* console.log('Paid! Explorer:', result.explorerUrl);
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function payPayRequest(config: PaymentRequestConfig, code: string, signer: PaymentCodeSigner): Promise<PayRequestResult>;
|
|
311
|
+
/**
|
|
312
|
+
* Pay a merchant's payment request using a pre-generated payment code.
|
|
313
|
+
* The buyer already holds a BLIK-style code (created via generatePaymentCode) —
|
|
314
|
+
* instead of signing on the spot, they redeem that code and USDC goes to the merchant.
|
|
315
|
+
*
|
|
316
|
+
* The payment code must have enough value to cover the request amount.
|
|
317
|
+
* If the code was created without a locked payee, the merchant address is set at redemption time.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* // Merchant shares their invoice code: "SHOP1234"
|
|
322
|
+
* // Buyer has a pre-generated payment code: "MYBLIK78"
|
|
323
|
+
* const result = await payPayRequestWithCode(config, 'SHOP1234', 'MYBLIK78');
|
|
324
|
+
* console.log('Paid! Explorer:', result.explorerUrl);
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
interface PayPayRequestWithCodeOptions {
|
|
328
|
+
/**
|
|
329
|
+
* How to return the change when the payment code value exceeds the invoice amount.
|
|
330
|
+
* - `'code'` (default) — relayer pays the merchant, then generates a new payment
|
|
331
|
+
* code for the remainder and returns it as `result.changeCode`. Works even when
|
|
332
|
+
* the buyer has no wallet (pure code-based flow).
|
|
333
|
+
* - `'wallet'` — uses `settler.settleExact()` on-chain: merchant receives exact
|
|
334
|
+
* invoice amount, surplus is returned atomically to the buyer's wallet (`from`).
|
|
335
|
+
* Requires the payment code was created with `to = settler` (atomic mode).
|
|
336
|
+
*
|
|
337
|
+
* Set `allowOverpayment: false` to throw instead of handling the difference.
|
|
338
|
+
*/
|
|
339
|
+
returnChange?: 'code' | 'wallet';
|
|
340
|
+
/**
|
|
341
|
+
* If false, throws when code value ≠ invoice amount (strict match).
|
|
342
|
+
* Default: true — difference is handled per `returnChange`.
|
|
343
|
+
*/
|
|
344
|
+
allowOverpayment?: boolean;
|
|
345
|
+
}
|
|
346
|
+
declare function payPayRequestWithCode(config: PaymentRequestConfig,
|
|
347
|
+
/** The merchant's payment request code */
|
|
348
|
+
requestCode: string,
|
|
349
|
+
/** The buyer's pre-generated BLIK-style payment code */
|
|
350
|
+
paymentCode: string, options?: PayPayRequestWithCodeOptions): Promise<RedeemResult>;
|
|
90
351
|
|
|
91
|
-
export { type CodeStatus, type GeneratePaymentCodeParams, type PaymentCode, type PaymentCodeConfig, type RedeemResult, generatePaymentCode, getPaymentCode, redeemPaymentCode };
|
|
352
|
+
export { type BatchCodeItem, type BatchPaymentCodesResult, type CodeStatus, type CreatePayRequestParams, type GeneratePaymentCodeParams, type GeneratePaymentCodesBatchParams, NETWORK_CONFIGS, type NetworkConfig, type PayPayRequestWithCodeOptions, type PayRequest, type PayRequestInfo, type PayRequestResult, type PaymentCode, type PaymentCodeConfig, type PaymentCodeNetwork, type PaymentCodeSigner, type PaymentRequestConfig, type RedeemResult, cancelPaymentCode, createPayRequest, createPrivateKeySigner, generatePaymentCode, generatePaymentCodesBatch, getPayRequest, getPaymentCode, payPayRequest, payPayRequestWithCode, redeemPaymentCode };
|