moltspay 1.3.0 → 1.4.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/.env.example +14 -0
- package/README.md +319 -89
- package/dist/cdp/index.d.mts +4 -4
- package/dist/cdp/index.d.ts +4 -4
- package/dist/cdp/index.js +57 -0
- package/dist/cdp/index.js.map +1 -1
- package/dist/cdp/index.mjs +57 -0
- package/dist/cdp/index.mjs.map +1 -1
- package/dist/chains/index.d.mts +9 -8
- package/dist/chains/index.d.ts +9 -8
- package/dist/chains/index.js +57 -0
- package/dist/chains/index.js.map +1 -1
- package/dist/chains/index.mjs +57 -0
- package/dist/chains/index.mjs.map +1 -1
- package/dist/cli/index.js +2021 -285
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +2023 -277
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.d.mts +39 -3
- package/dist/client/index.d.ts +39 -3
- package/dist/client/index.js +563 -37
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +571 -35
- package/dist/client/index.mjs.map +1 -1
- package/dist/facilitators/index.d.mts +220 -1
- package/dist/facilitators/index.d.ts +220 -1
- package/dist/facilitators/index.js +664 -1
- package/dist/facilitators/index.js.map +1 -1
- package/dist/facilitators/index.mjs +670 -1
- package/dist/facilitators/index.mjs.map +1 -1
- package/dist/{index-On9ZaGDW.d.mts → index-D_2FkLwV.d.mts} +6 -2
- package/dist/{index-On9ZaGDW.d.ts → index-D_2FkLwV.d.ts} +6 -2
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1440 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1448 -151
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +13 -3
- package/dist/server/index.d.ts +13 -3
- package/dist/server/index.js +909 -54
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +919 -54
- package/dist/server/index.mjs.map +1 -1
- package/dist/verify/index.d.mts +1 -1
- package/dist/verify/index.d.ts +1 -1
- package/dist/verify/index.js +57 -0
- package/dist/verify/index.js.map +1 -1
- package/dist/verify/index.mjs +57 -0
- package/dist/verify/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +3 -3
- package/dist/wallet/index.d.ts +3 -3
- package/dist/wallet/index.js +57 -0
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +57 -0
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +5 -2
- package/schemas/moltspay.services.schema.json +27 -132
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { B as BaseFacilitator, H as HealthCheckResult, X as X402PaymentPayload, f as X402PaymentRequirements, V as VerifyResult, e as SettleResult } from '../registry-OsEO2dOu.js';
|
|
2
2
|
export { F as Facilitator, a as FacilitatorConfig, b as FacilitatorFee, c as FacilitatorRegistry, d as FacilitatorSelection, S as SelectionStrategy, g as createRegistry, h as getDefaultRegistry } from '../registry-OsEO2dOu.js';
|
|
3
3
|
export { C as CDPFacilitator, a as CDPFacilitatorConfig } from '../cdp-DeohBe1o.js';
|
|
4
|
+
import { Keypair, PublicKey, Transaction } from '@solana/web3.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Tempo Testnet Facilitator
|
|
@@ -26,4 +27,222 @@ declare class TempoFacilitator extends BaseFacilitator {
|
|
|
26
27
|
private getTransactionReceipt;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* BNB Chain Facilitator
|
|
32
|
+
*
|
|
33
|
+
* Handles pay-for-success payments on BNB Smart Chain.
|
|
34
|
+
*
|
|
35
|
+
* Flow:
|
|
36
|
+
* 1. Client pre-approves server wallet (one-time, via `moltspay init`)
|
|
37
|
+
* 2. Client signs EIP-712 intent (no gas, just signature)
|
|
38
|
+
* 3. Server verifies intent signature
|
|
39
|
+
* 4. Server executes service
|
|
40
|
+
* 5. Success → Server calls transferFrom (server pays gas)
|
|
41
|
+
* 6. Failure → No transfer, client keeps money
|
|
42
|
+
*
|
|
43
|
+
* Key difference from Tempo:
|
|
44
|
+
* - Tempo: Client pays first → service might fail → money lost
|
|
45
|
+
* - BNB: Service runs first → success = payment (pay-for-success)
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* BNB Payment Intent (signed by client)
|
|
50
|
+
*/
|
|
51
|
+
interface BNBPaymentIntent {
|
|
52
|
+
from: string;
|
|
53
|
+
to: string;
|
|
54
|
+
amount: string;
|
|
55
|
+
token: string;
|
|
56
|
+
service: string;
|
|
57
|
+
nonce: number;
|
|
58
|
+
deadline: number;
|
|
59
|
+
signature: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* BNB Chain Facilitator
|
|
63
|
+
*
|
|
64
|
+
* Handles pay-for-success payments on BNB mainnet (chainId 56) and testnet (chainId 97).
|
|
65
|
+
* Server wallet executes transferFrom after successful service delivery.
|
|
66
|
+
*/
|
|
67
|
+
declare class BNBFacilitator extends BaseFacilitator {
|
|
68
|
+
readonly name = "bnb";
|
|
69
|
+
readonly displayName = "BNB Smart Chain";
|
|
70
|
+
readonly supportedNetworks: string[];
|
|
71
|
+
private serverPrivateKey;
|
|
72
|
+
private spenderAddress;
|
|
73
|
+
private chainConfigs;
|
|
74
|
+
constructor(serverPrivateKey?: string);
|
|
75
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Verify a payment intent signature (before service execution)
|
|
78
|
+
*
|
|
79
|
+
* This verifies:
|
|
80
|
+
* 1. Signature is valid for the intent
|
|
81
|
+
* 2. Client has approved server wallet
|
|
82
|
+
* 3. Client has sufficient balance
|
|
83
|
+
* 4. Intent hasn't expired
|
|
84
|
+
*/
|
|
85
|
+
verify(paymentPayload: X402PaymentPayload, requirements: X402PaymentRequirements): Promise<VerifyResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Settle a payment by executing transferFrom
|
|
88
|
+
*
|
|
89
|
+
* This is called AFTER the service has been successfully delivered.
|
|
90
|
+
* Server pays gas, transfers tokens from client to provider.
|
|
91
|
+
*/
|
|
92
|
+
settle(paymentPayload: X402PaymentPayload, requirements: X402PaymentRequirements): Promise<SettleResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Check if client has approved the server wallet
|
|
95
|
+
*/
|
|
96
|
+
checkApproval(clientAddress: string, token: string, chainId: number): Promise<{
|
|
97
|
+
approved: boolean;
|
|
98
|
+
allowance: string;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Verify a completed transaction (for checking past payments)
|
|
102
|
+
*/
|
|
103
|
+
verifyTransaction(txHash: string, expected: {
|
|
104
|
+
to: string;
|
|
105
|
+
amount: string;
|
|
106
|
+
token: string;
|
|
107
|
+
}, chainId: number): Promise<VerifyResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Get the server's spender address (public, for 402 responses)
|
|
110
|
+
* Returns cached value computed at construction time.
|
|
111
|
+
*/
|
|
112
|
+
getSpenderAddress(): string | null;
|
|
113
|
+
private getServerAddress;
|
|
114
|
+
private recoverIntentSigner;
|
|
115
|
+
private getAllowance;
|
|
116
|
+
private getBalance;
|
|
117
|
+
private executeTransferFrom;
|
|
118
|
+
private getTransactionReceipt;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create EIP-712 typed data for signing a payment intent
|
|
122
|
+
*
|
|
123
|
+
* Used by clients to sign their payment intent.
|
|
124
|
+
*/
|
|
125
|
+
declare function createIntentTypedData(intent: Omit<BNBPaymentIntent, 'signature'>, chainId: number): {
|
|
126
|
+
domain: {
|
|
127
|
+
chainId: number;
|
|
128
|
+
name: string;
|
|
129
|
+
version: string;
|
|
130
|
+
};
|
|
131
|
+
types: {
|
|
132
|
+
PaymentIntent: {
|
|
133
|
+
name: string;
|
|
134
|
+
type: string;
|
|
135
|
+
}[];
|
|
136
|
+
};
|
|
137
|
+
primaryType: "PaymentIntent";
|
|
138
|
+
message: {
|
|
139
|
+
from: string;
|
|
140
|
+
to: string;
|
|
141
|
+
amount: string;
|
|
142
|
+
token: string;
|
|
143
|
+
service: string;
|
|
144
|
+
nonce: number;
|
|
145
|
+
deadline: number;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Solana Chain Configuration
|
|
151
|
+
*
|
|
152
|
+
* Solana is NOT an EVM chain - uses different:
|
|
153
|
+
* - Key format: ed25519 (EdDSA) vs secp256k1 (ECDSA)
|
|
154
|
+
* - Address format: Base58 vs 0x hex
|
|
155
|
+
* - Token standard: SPL vs ERC-20
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
type SolanaChainName = 'solana' | 'solana_devnet';
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Solana Facilitator
|
|
162
|
+
*
|
|
163
|
+
* Pay-for-success payment settlement for Solana SPL token transfers.
|
|
164
|
+
* Unlike EVM chains, Solana doesn't have a third-party facilitator -
|
|
165
|
+
* we verify and settle directly on-chain.
|
|
166
|
+
*
|
|
167
|
+
* Flow:
|
|
168
|
+
* 1. Client signs a SPL token transfer authorization
|
|
169
|
+
* 2. Server receives the signed transaction
|
|
170
|
+
* 3. Server verifies the signature and amount
|
|
171
|
+
* 4. Server submits the transaction to settle payment
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Solana payment payload structure
|
|
176
|
+
*/
|
|
177
|
+
interface SolanaPaymentPayload {
|
|
178
|
+
/** Base58 encoded signed transaction */
|
|
179
|
+
signedTransaction: string;
|
|
180
|
+
/** Sender's public key (Base58) */
|
|
181
|
+
sender: string;
|
|
182
|
+
/** Chain: solana or solana_devnet */
|
|
183
|
+
chain: SolanaChainName;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Solana Facilitator configuration
|
|
187
|
+
*/
|
|
188
|
+
interface SolanaFacilitatorConfig {
|
|
189
|
+
/** Optional fee payer keypair for gasless transactions */
|
|
190
|
+
feePayerKeypair?: Keypair;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Solana Facilitator for pay-for-success payments
|
|
194
|
+
*
|
|
195
|
+
* Supports gasless mode: if feePayerKeypair is provided, server pays tx fees
|
|
196
|
+
*/
|
|
197
|
+
declare class SolanaFacilitator extends BaseFacilitator {
|
|
198
|
+
readonly name = "solana";
|
|
199
|
+
readonly displayName = "Solana Direct";
|
|
200
|
+
readonly supportedNetworks: string[];
|
|
201
|
+
private connections;
|
|
202
|
+
private feePayerKeypair?;
|
|
203
|
+
constructor(config?: SolanaFacilitatorConfig);
|
|
204
|
+
/**
|
|
205
|
+
* Get fee payer public key (for gasless transactions)
|
|
206
|
+
*/
|
|
207
|
+
getFeePayerPubkey(): string | null;
|
|
208
|
+
private getConnection;
|
|
209
|
+
/**
|
|
210
|
+
* Convert our chain name to network identifier
|
|
211
|
+
*/
|
|
212
|
+
static chainToNetwork(chain: SolanaChainName): string;
|
|
213
|
+
/**
|
|
214
|
+
* Convert network identifier to chain name
|
|
215
|
+
*/
|
|
216
|
+
static networkToChain(network: string): SolanaChainName | null;
|
|
217
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
218
|
+
/**
|
|
219
|
+
* Verify a Solana payment
|
|
220
|
+
*
|
|
221
|
+
* Checks:
|
|
222
|
+
* 1. Transaction is valid and properly signed
|
|
223
|
+
* 2. Transfer instruction matches expected amount and recipient
|
|
224
|
+
*/
|
|
225
|
+
verify(paymentPayload: X402PaymentPayload, requirements: X402PaymentRequirements): Promise<VerifyResult>;
|
|
226
|
+
/**
|
|
227
|
+
* Settle a Solana payment
|
|
228
|
+
*
|
|
229
|
+
* Submits the signed transaction to the network.
|
|
230
|
+
* In gasless mode, adds fee payer signature before submitting.
|
|
231
|
+
*/
|
|
232
|
+
settle(paymentPayload: X402PaymentPayload, requirements: X402PaymentRequirements): Promise<SettleResult>;
|
|
233
|
+
supportsNetwork(network: string): boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Create a Solana payment transaction for signing
|
|
237
|
+
*
|
|
238
|
+
* This is called by the client to create the transaction to sign.
|
|
239
|
+
*
|
|
240
|
+
* @param senderPubkey - The sender's public key (token owner)
|
|
241
|
+
* @param recipientPubkey - The recipient's public key
|
|
242
|
+
* @param amount - Amount in token base units
|
|
243
|
+
* @param chain - Solana chain (solana or solana_devnet)
|
|
244
|
+
* @param feePayerPubkey - Optional fee payer public key for gasless transactions
|
|
245
|
+
*/
|
|
246
|
+
declare function createSolanaPaymentTransaction(senderPubkey: PublicKey, recipientPubkey: PublicKey, amount: bigint, chain: SolanaChainName, feePayerPubkey?: PublicKey): Promise<Transaction>;
|
|
247
|
+
|
|
248
|
+
export { BNBFacilitator, type BNBPaymentIntent, BaseFacilitator, HealthCheckResult, SettleResult, SolanaFacilitator, type SolanaPaymentPayload, TempoFacilitator, VerifyResult, X402PaymentPayload, X402PaymentRequirements, createIntentTypedData, createSolanaPaymentTransaction };
|