@haven_ai/sdk 0.1.0 → 0.1.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/README.md +83 -11
- package/dist/index.cjs +809 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +136 -5
- package/dist/index.d.ts +136 -5
- package/dist/index.js +804 -55
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,8 @@ interface HavenClientConfig {
|
|
|
5
5
|
delegateKey?: string;
|
|
6
6
|
/** Haven API base URL (default: http://localhost:3001) */
|
|
7
7
|
baseUrl?: string;
|
|
8
|
+
/** Optional wallet identity to send as the x402-wallet header. */
|
|
9
|
+
x402Wallet?: string;
|
|
8
10
|
/** Timeout in ms for individual HTTP requests (default: 30000) */
|
|
9
11
|
requestTimeout?: number;
|
|
10
12
|
/** Timeout in ms when polling for tx confirmation (default: 90000) */
|
|
@@ -46,7 +48,7 @@ interface PaymentIntent {
|
|
|
46
48
|
/** Data needed to sign the payment */
|
|
47
49
|
signData: SignData;
|
|
48
50
|
}
|
|
49
|
-
type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'expired' | 'failed';
|
|
51
|
+
type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'pending_approval' | 'approved' | 'proposed' | 'executed' | 'rejected' | 'expired' | 'failed';
|
|
50
52
|
interface PaymentResult {
|
|
51
53
|
/** Unique payment ID */
|
|
52
54
|
paymentId: string;
|
|
@@ -87,6 +89,10 @@ interface X402PaymentOption {
|
|
|
87
89
|
scheme: string;
|
|
88
90
|
network: string;
|
|
89
91
|
amount: string;
|
|
92
|
+
maxAmountRequired?: string;
|
|
93
|
+
resource?: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
mimeType?: string;
|
|
90
96
|
asset: string;
|
|
91
97
|
payTo: string;
|
|
92
98
|
maxTimeoutSeconds: number;
|
|
@@ -102,6 +108,77 @@ interface X402Receipt {
|
|
|
102
108
|
to: string;
|
|
103
109
|
resourceUrl: string;
|
|
104
110
|
explorerUrl: string;
|
|
111
|
+
accepted?: X402PaymentOption;
|
|
112
|
+
paymentHeader?: string;
|
|
113
|
+
merchantTo?: string | null;
|
|
114
|
+
payer?: string;
|
|
115
|
+
chainId?: number;
|
|
116
|
+
}
|
|
117
|
+
type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
|
|
118
|
+
interface MachinePaymentChallenge {
|
|
119
|
+
rail: MachinePaymentRail;
|
|
120
|
+
version: string;
|
|
121
|
+
challengeId: string;
|
|
122
|
+
resource: string;
|
|
123
|
+
description: string;
|
|
124
|
+
network: {
|
|
125
|
+
chainId: number;
|
|
126
|
+
name: 'base';
|
|
127
|
+
};
|
|
128
|
+
asset: {
|
|
129
|
+
symbol: 'USDC';
|
|
130
|
+
address: string;
|
|
131
|
+
decimals: 6;
|
|
132
|
+
};
|
|
133
|
+
amount: {
|
|
134
|
+
display: string;
|
|
135
|
+
atomic: string;
|
|
136
|
+
};
|
|
137
|
+
recipient: string;
|
|
138
|
+
expiresAt: string;
|
|
139
|
+
metadata?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
interface MachinePaymentReceipt {
|
|
142
|
+
success: boolean;
|
|
143
|
+
rail: MachinePaymentRail;
|
|
144
|
+
paymentId: string;
|
|
145
|
+
challengeId: string;
|
|
146
|
+
txHash: string;
|
|
147
|
+
token: string;
|
|
148
|
+
amount: string;
|
|
149
|
+
to: string;
|
|
150
|
+
resourceUrl: string;
|
|
151
|
+
explorerUrl: string;
|
|
152
|
+
payer?: string;
|
|
153
|
+
chainId?: number;
|
|
154
|
+
proofHeader: string;
|
|
155
|
+
}
|
|
156
|
+
type PaymentStateKind = 'payment_intent' | 'approval_request';
|
|
157
|
+
type PaymentPhase = 'agent_signature_required' | 'payment_submitted' | 'payment_confirmed' | 'user_approval_required' | 'user_execution_required' | 'waiting_for_additional_approvals' | 'funding_sent' | 'rejected' | 'expired' | 'failed';
|
|
158
|
+
type PaymentNextAction = 'sign_and_submit_payment' | 'check_status_later' | 'none' | 'wait_for_user_approval' | 'wait_for_user_to_complete_payment' | 'retry_original_x402_request' | 'stop_and_tell_user' | 'request_again_if_user_still_wants_it';
|
|
159
|
+
interface PaymentStatusResult {
|
|
160
|
+
paymentId: string;
|
|
161
|
+
kind: PaymentStateKind;
|
|
162
|
+
rail: string;
|
|
163
|
+
status: PaymentStatus | string;
|
|
164
|
+
phase: PaymentPhase;
|
|
165
|
+
nextAction: PaymentNextAction;
|
|
166
|
+
amount: string;
|
|
167
|
+
token: string;
|
|
168
|
+
resourceUrl: string | null;
|
|
169
|
+
merchantAddress: string | null;
|
|
170
|
+
txHash: string | null;
|
|
171
|
+
expiresAt: string;
|
|
172
|
+
chainId: number;
|
|
173
|
+
message: string;
|
|
174
|
+
}
|
|
175
|
+
interface PendingApproval extends PaymentStatusResult {
|
|
176
|
+
kind: 'approval_request';
|
|
177
|
+
status: 'pending_approval' | 'pending' | string;
|
|
178
|
+
phase: 'user_approval_required';
|
|
179
|
+
nextAction: 'wait_for_user_approval';
|
|
180
|
+
requested?: string;
|
|
181
|
+
remaining?: string | null;
|
|
105
182
|
}
|
|
106
183
|
declare class HavenError extends Error {
|
|
107
184
|
readonly code: string;
|
|
@@ -111,7 +188,14 @@ declare class HavenError extends Error {
|
|
|
111
188
|
}
|
|
112
189
|
declare class HavenApiError extends HavenError {
|
|
113
190
|
readonly body?: unknown | undefined;
|
|
114
|
-
constructor(message: string, statusCode: number, body?: unknown | undefined);
|
|
191
|
+
constructor(message: string, statusCode: number, body?: unknown | undefined, paymentId?: string);
|
|
192
|
+
}
|
|
193
|
+
declare class HavenPaymentStateError extends HavenApiError {
|
|
194
|
+
readonly state: PaymentStatusResult;
|
|
195
|
+
constructor(message: string, statusCode: number, state: PaymentStatusResult, body?: unknown);
|
|
196
|
+
get status(): string;
|
|
197
|
+
get phase(): PaymentPhase;
|
|
198
|
+
get nextAction(): PaymentNextAction;
|
|
115
199
|
}
|
|
116
200
|
declare class HavenSigningError extends HavenError {
|
|
117
201
|
constructor(message: string);
|
|
@@ -124,9 +208,13 @@ declare class HavenClient {
|
|
|
124
208
|
private readonly apiKey;
|
|
125
209
|
private readonly delegateKey;
|
|
126
210
|
private readonly baseUrl;
|
|
211
|
+
private readonly x402Wallet;
|
|
127
212
|
private readonly requestTimeout;
|
|
128
213
|
private readonly confirmationTimeout;
|
|
129
214
|
private readonly pollingInterval;
|
|
215
|
+
private readonly inFlightX402;
|
|
216
|
+
private readonly x402ReceiptCache;
|
|
217
|
+
private readonly inFlightMachinePayments;
|
|
130
218
|
/** Delegate address derived from the private key (if provided) */
|
|
131
219
|
readonly delegateAddress: string | undefined;
|
|
132
220
|
constructor(config: HavenClientConfig);
|
|
@@ -165,6 +253,13 @@ declare class HavenClient {
|
|
|
165
253
|
* Get the current status of a payment.
|
|
166
254
|
*/
|
|
167
255
|
getPayment(paymentId: string): Promise<PaymentResult>;
|
|
256
|
+
/**
|
|
257
|
+
* Get agent-actionable status for a payment intent or approval request.
|
|
258
|
+
*
|
|
259
|
+
* Use this for IDs returned by agent tools and machine-payment/x402 flows.
|
|
260
|
+
* `getPayment()` remains available for payment-intent-only integrations.
|
|
261
|
+
*/
|
|
262
|
+
getPaymentStatus(paymentId: string): Promise<PaymentStatusResult>;
|
|
168
263
|
/**
|
|
169
264
|
* Poll until a payment reaches a terminal status (confirmed, failed, expired).
|
|
170
265
|
*/
|
|
@@ -172,12 +267,14 @@ declare class HavenClient {
|
|
|
172
267
|
/**
|
|
173
268
|
* Authorize an x402 payment.
|
|
174
269
|
*
|
|
175
|
-
* Takes the parsed PaymentRequired from a 402 response, selects a
|
|
176
|
-
*
|
|
270
|
+
* Takes the parsed PaymentRequired from a 402 response, selects a compatible
|
|
271
|
+
* option, funds the delegate wallet through Haven, and returns the standard
|
|
272
|
+
* x402 header that the merchant can verify and settle.
|
|
177
273
|
*
|
|
178
274
|
* Requires `delegateKey` to be set in the client config.
|
|
179
275
|
*/
|
|
180
276
|
authorizeX402(paymentRequired: X402PaymentRequired): Promise<X402Receipt>;
|
|
277
|
+
private authorizeStandardX402;
|
|
181
278
|
/**
|
|
182
279
|
* Fetch wrapper that automatically handles HTTP 402 responses.
|
|
183
280
|
*
|
|
@@ -192,6 +289,19 @@ declare class HavenClient {
|
|
|
192
289
|
* Requires `delegateKey` to be set in the client config.
|
|
193
290
|
*/
|
|
194
291
|
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
292
|
+
authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
|
|
293
|
+
private authorizeMppDemoPayment;
|
|
294
|
+
private fetchWithMachinePayment;
|
|
295
|
+
private createStandardX402Header;
|
|
296
|
+
private cacheX402Receipt;
|
|
297
|
+
private mapMachinePaymentReceipt;
|
|
298
|
+
private recordMerchantRetryRejected;
|
|
299
|
+
private reportMachinePaymentEvidence;
|
|
300
|
+
private throwIfNonSignableAuthorizationState;
|
|
301
|
+
private throwPaymentStateError;
|
|
302
|
+
private paymentStateFromRaw;
|
|
303
|
+
private x402PayerAddress;
|
|
304
|
+
private withX402Wallet;
|
|
195
305
|
/**
|
|
196
306
|
* Execute a tool call by name and input.
|
|
197
307
|
*
|
|
@@ -205,10 +315,12 @@ declare class HavenClient {
|
|
|
205
315
|
* ```
|
|
206
316
|
*/
|
|
207
317
|
executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
318
|
+
private toolError;
|
|
208
319
|
private post;
|
|
209
320
|
private get;
|
|
210
321
|
private request;
|
|
211
322
|
private mapPaymentResult;
|
|
323
|
+
private mapPaymentStatusResult;
|
|
212
324
|
}
|
|
213
325
|
|
|
214
326
|
/**
|
|
@@ -282,6 +394,7 @@ declare function verifySignature(hash: string, signature: string, expectedAddres
|
|
|
282
394
|
*
|
|
283
395
|
* Provides:
|
|
284
396
|
* - parsePaymentRequired() — extract payment requirements from a 402 response
|
|
397
|
+
* - parsePaymentRequiredResponse() — async parser with JSON body fallback
|
|
285
398
|
* - encodePaymentProof() — encode a receipt as a PAYMENT-SIGNATURE header
|
|
286
399
|
*
|
|
287
400
|
* The main authorizeX402() and fetchWithPayment() are methods on HavenClient
|
|
@@ -296,6 +409,15 @@ declare function verifySignature(hash: string, signature: string, expectedAddres
|
|
|
296
409
|
* - v1 fallback: X-PAYMENT header or response body
|
|
297
410
|
*/
|
|
298
411
|
declare function parsePaymentRequired(response: Response): X402PaymentRequired;
|
|
412
|
+
/**
|
|
413
|
+
* Parse an HTTP 402 response into x402 PaymentRequired data.
|
|
414
|
+
*
|
|
415
|
+
* Soundside and other Bazaar-style MCP endpoints return the PaymentRequired
|
|
416
|
+
* object in the JSON body, while older Haven demos and many x402 examples use
|
|
417
|
+
* base64 headers. This keeps the synchronous header parser intact and adds the
|
|
418
|
+
* body fallback needed for those endpoints.
|
|
419
|
+
*/
|
|
420
|
+
declare function parsePaymentRequiredResponse(response: Response): Promise<X402PaymentRequired>;
|
|
299
421
|
/**
|
|
300
422
|
* Select the best payment option from the x402 accepts array.
|
|
301
423
|
*
|
|
@@ -317,6 +439,15 @@ declare function encodePaymentProof(receipt: {
|
|
|
317
439
|
token: string;
|
|
318
440
|
amount: string;
|
|
319
441
|
to: string;
|
|
442
|
+
resourceUrl?: string;
|
|
443
|
+
accepted?: X402PaymentOption;
|
|
444
|
+
payer?: string;
|
|
445
|
+
chainId?: number;
|
|
320
446
|
}): string;
|
|
321
447
|
|
|
322
|
-
|
|
448
|
+
declare function parseMachinePaymentChallenge(response: Response): MachinePaymentChallenge;
|
|
449
|
+
declare function parseMachinePaymentChallengeResponse(response: Response): Promise<MachinePaymentChallenge>;
|
|
450
|
+
declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
|
|
451
|
+
declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
|
|
452
|
+
|
|
453
|
+
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ interface HavenClientConfig {
|
|
|
5
5
|
delegateKey?: string;
|
|
6
6
|
/** Haven API base URL (default: http://localhost:3001) */
|
|
7
7
|
baseUrl?: string;
|
|
8
|
+
/** Optional wallet identity to send as the x402-wallet header. */
|
|
9
|
+
x402Wallet?: string;
|
|
8
10
|
/** Timeout in ms for individual HTTP requests (default: 30000) */
|
|
9
11
|
requestTimeout?: number;
|
|
10
12
|
/** Timeout in ms when polling for tx confirmation (default: 90000) */
|
|
@@ -46,7 +48,7 @@ interface PaymentIntent {
|
|
|
46
48
|
/** Data needed to sign the payment */
|
|
47
49
|
signData: SignData;
|
|
48
50
|
}
|
|
49
|
-
type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'expired' | 'failed';
|
|
51
|
+
type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'pending_approval' | 'approved' | 'proposed' | 'executed' | 'rejected' | 'expired' | 'failed';
|
|
50
52
|
interface PaymentResult {
|
|
51
53
|
/** Unique payment ID */
|
|
52
54
|
paymentId: string;
|
|
@@ -87,6 +89,10 @@ interface X402PaymentOption {
|
|
|
87
89
|
scheme: string;
|
|
88
90
|
network: string;
|
|
89
91
|
amount: string;
|
|
92
|
+
maxAmountRequired?: string;
|
|
93
|
+
resource?: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
mimeType?: string;
|
|
90
96
|
asset: string;
|
|
91
97
|
payTo: string;
|
|
92
98
|
maxTimeoutSeconds: number;
|
|
@@ -102,6 +108,77 @@ interface X402Receipt {
|
|
|
102
108
|
to: string;
|
|
103
109
|
resourceUrl: string;
|
|
104
110
|
explorerUrl: string;
|
|
111
|
+
accepted?: X402PaymentOption;
|
|
112
|
+
paymentHeader?: string;
|
|
113
|
+
merchantTo?: string | null;
|
|
114
|
+
payer?: string;
|
|
115
|
+
chainId?: number;
|
|
116
|
+
}
|
|
117
|
+
type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
|
|
118
|
+
interface MachinePaymentChallenge {
|
|
119
|
+
rail: MachinePaymentRail;
|
|
120
|
+
version: string;
|
|
121
|
+
challengeId: string;
|
|
122
|
+
resource: string;
|
|
123
|
+
description: string;
|
|
124
|
+
network: {
|
|
125
|
+
chainId: number;
|
|
126
|
+
name: 'base';
|
|
127
|
+
};
|
|
128
|
+
asset: {
|
|
129
|
+
symbol: 'USDC';
|
|
130
|
+
address: string;
|
|
131
|
+
decimals: 6;
|
|
132
|
+
};
|
|
133
|
+
amount: {
|
|
134
|
+
display: string;
|
|
135
|
+
atomic: string;
|
|
136
|
+
};
|
|
137
|
+
recipient: string;
|
|
138
|
+
expiresAt: string;
|
|
139
|
+
metadata?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
interface MachinePaymentReceipt {
|
|
142
|
+
success: boolean;
|
|
143
|
+
rail: MachinePaymentRail;
|
|
144
|
+
paymentId: string;
|
|
145
|
+
challengeId: string;
|
|
146
|
+
txHash: string;
|
|
147
|
+
token: string;
|
|
148
|
+
amount: string;
|
|
149
|
+
to: string;
|
|
150
|
+
resourceUrl: string;
|
|
151
|
+
explorerUrl: string;
|
|
152
|
+
payer?: string;
|
|
153
|
+
chainId?: number;
|
|
154
|
+
proofHeader: string;
|
|
155
|
+
}
|
|
156
|
+
type PaymentStateKind = 'payment_intent' | 'approval_request';
|
|
157
|
+
type PaymentPhase = 'agent_signature_required' | 'payment_submitted' | 'payment_confirmed' | 'user_approval_required' | 'user_execution_required' | 'waiting_for_additional_approvals' | 'funding_sent' | 'rejected' | 'expired' | 'failed';
|
|
158
|
+
type PaymentNextAction = 'sign_and_submit_payment' | 'check_status_later' | 'none' | 'wait_for_user_approval' | 'wait_for_user_to_complete_payment' | 'retry_original_x402_request' | 'stop_and_tell_user' | 'request_again_if_user_still_wants_it';
|
|
159
|
+
interface PaymentStatusResult {
|
|
160
|
+
paymentId: string;
|
|
161
|
+
kind: PaymentStateKind;
|
|
162
|
+
rail: string;
|
|
163
|
+
status: PaymentStatus | string;
|
|
164
|
+
phase: PaymentPhase;
|
|
165
|
+
nextAction: PaymentNextAction;
|
|
166
|
+
amount: string;
|
|
167
|
+
token: string;
|
|
168
|
+
resourceUrl: string | null;
|
|
169
|
+
merchantAddress: string | null;
|
|
170
|
+
txHash: string | null;
|
|
171
|
+
expiresAt: string;
|
|
172
|
+
chainId: number;
|
|
173
|
+
message: string;
|
|
174
|
+
}
|
|
175
|
+
interface PendingApproval extends PaymentStatusResult {
|
|
176
|
+
kind: 'approval_request';
|
|
177
|
+
status: 'pending_approval' | 'pending' | string;
|
|
178
|
+
phase: 'user_approval_required';
|
|
179
|
+
nextAction: 'wait_for_user_approval';
|
|
180
|
+
requested?: string;
|
|
181
|
+
remaining?: string | null;
|
|
105
182
|
}
|
|
106
183
|
declare class HavenError extends Error {
|
|
107
184
|
readonly code: string;
|
|
@@ -111,7 +188,14 @@ declare class HavenError extends Error {
|
|
|
111
188
|
}
|
|
112
189
|
declare class HavenApiError extends HavenError {
|
|
113
190
|
readonly body?: unknown | undefined;
|
|
114
|
-
constructor(message: string, statusCode: number, body?: unknown | undefined);
|
|
191
|
+
constructor(message: string, statusCode: number, body?: unknown | undefined, paymentId?: string);
|
|
192
|
+
}
|
|
193
|
+
declare class HavenPaymentStateError extends HavenApiError {
|
|
194
|
+
readonly state: PaymentStatusResult;
|
|
195
|
+
constructor(message: string, statusCode: number, state: PaymentStatusResult, body?: unknown);
|
|
196
|
+
get status(): string;
|
|
197
|
+
get phase(): PaymentPhase;
|
|
198
|
+
get nextAction(): PaymentNextAction;
|
|
115
199
|
}
|
|
116
200
|
declare class HavenSigningError extends HavenError {
|
|
117
201
|
constructor(message: string);
|
|
@@ -124,9 +208,13 @@ declare class HavenClient {
|
|
|
124
208
|
private readonly apiKey;
|
|
125
209
|
private readonly delegateKey;
|
|
126
210
|
private readonly baseUrl;
|
|
211
|
+
private readonly x402Wallet;
|
|
127
212
|
private readonly requestTimeout;
|
|
128
213
|
private readonly confirmationTimeout;
|
|
129
214
|
private readonly pollingInterval;
|
|
215
|
+
private readonly inFlightX402;
|
|
216
|
+
private readonly x402ReceiptCache;
|
|
217
|
+
private readonly inFlightMachinePayments;
|
|
130
218
|
/** Delegate address derived from the private key (if provided) */
|
|
131
219
|
readonly delegateAddress: string | undefined;
|
|
132
220
|
constructor(config: HavenClientConfig);
|
|
@@ -165,6 +253,13 @@ declare class HavenClient {
|
|
|
165
253
|
* Get the current status of a payment.
|
|
166
254
|
*/
|
|
167
255
|
getPayment(paymentId: string): Promise<PaymentResult>;
|
|
256
|
+
/**
|
|
257
|
+
* Get agent-actionable status for a payment intent or approval request.
|
|
258
|
+
*
|
|
259
|
+
* Use this for IDs returned by agent tools and machine-payment/x402 flows.
|
|
260
|
+
* `getPayment()` remains available for payment-intent-only integrations.
|
|
261
|
+
*/
|
|
262
|
+
getPaymentStatus(paymentId: string): Promise<PaymentStatusResult>;
|
|
168
263
|
/**
|
|
169
264
|
* Poll until a payment reaches a terminal status (confirmed, failed, expired).
|
|
170
265
|
*/
|
|
@@ -172,12 +267,14 @@ declare class HavenClient {
|
|
|
172
267
|
/**
|
|
173
268
|
* Authorize an x402 payment.
|
|
174
269
|
*
|
|
175
|
-
* Takes the parsed PaymentRequired from a 402 response, selects a
|
|
176
|
-
*
|
|
270
|
+
* Takes the parsed PaymentRequired from a 402 response, selects a compatible
|
|
271
|
+
* option, funds the delegate wallet through Haven, and returns the standard
|
|
272
|
+
* x402 header that the merchant can verify and settle.
|
|
177
273
|
*
|
|
178
274
|
* Requires `delegateKey` to be set in the client config.
|
|
179
275
|
*/
|
|
180
276
|
authorizeX402(paymentRequired: X402PaymentRequired): Promise<X402Receipt>;
|
|
277
|
+
private authorizeStandardX402;
|
|
181
278
|
/**
|
|
182
279
|
* Fetch wrapper that automatically handles HTTP 402 responses.
|
|
183
280
|
*
|
|
@@ -192,6 +289,19 @@ declare class HavenClient {
|
|
|
192
289
|
* Requires `delegateKey` to be set in the client config.
|
|
193
290
|
*/
|
|
194
291
|
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
292
|
+
authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
|
|
293
|
+
private authorizeMppDemoPayment;
|
|
294
|
+
private fetchWithMachinePayment;
|
|
295
|
+
private createStandardX402Header;
|
|
296
|
+
private cacheX402Receipt;
|
|
297
|
+
private mapMachinePaymentReceipt;
|
|
298
|
+
private recordMerchantRetryRejected;
|
|
299
|
+
private reportMachinePaymentEvidence;
|
|
300
|
+
private throwIfNonSignableAuthorizationState;
|
|
301
|
+
private throwPaymentStateError;
|
|
302
|
+
private paymentStateFromRaw;
|
|
303
|
+
private x402PayerAddress;
|
|
304
|
+
private withX402Wallet;
|
|
195
305
|
/**
|
|
196
306
|
* Execute a tool call by name and input.
|
|
197
307
|
*
|
|
@@ -205,10 +315,12 @@ declare class HavenClient {
|
|
|
205
315
|
* ```
|
|
206
316
|
*/
|
|
207
317
|
executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
318
|
+
private toolError;
|
|
208
319
|
private post;
|
|
209
320
|
private get;
|
|
210
321
|
private request;
|
|
211
322
|
private mapPaymentResult;
|
|
323
|
+
private mapPaymentStatusResult;
|
|
212
324
|
}
|
|
213
325
|
|
|
214
326
|
/**
|
|
@@ -282,6 +394,7 @@ declare function verifySignature(hash: string, signature: string, expectedAddres
|
|
|
282
394
|
*
|
|
283
395
|
* Provides:
|
|
284
396
|
* - parsePaymentRequired() — extract payment requirements from a 402 response
|
|
397
|
+
* - parsePaymentRequiredResponse() — async parser with JSON body fallback
|
|
285
398
|
* - encodePaymentProof() — encode a receipt as a PAYMENT-SIGNATURE header
|
|
286
399
|
*
|
|
287
400
|
* The main authorizeX402() and fetchWithPayment() are methods on HavenClient
|
|
@@ -296,6 +409,15 @@ declare function verifySignature(hash: string, signature: string, expectedAddres
|
|
|
296
409
|
* - v1 fallback: X-PAYMENT header or response body
|
|
297
410
|
*/
|
|
298
411
|
declare function parsePaymentRequired(response: Response): X402PaymentRequired;
|
|
412
|
+
/**
|
|
413
|
+
* Parse an HTTP 402 response into x402 PaymentRequired data.
|
|
414
|
+
*
|
|
415
|
+
* Soundside and other Bazaar-style MCP endpoints return the PaymentRequired
|
|
416
|
+
* object in the JSON body, while older Haven demos and many x402 examples use
|
|
417
|
+
* base64 headers. This keeps the synchronous header parser intact and adds the
|
|
418
|
+
* body fallback needed for those endpoints.
|
|
419
|
+
*/
|
|
420
|
+
declare function parsePaymentRequiredResponse(response: Response): Promise<X402PaymentRequired>;
|
|
299
421
|
/**
|
|
300
422
|
* Select the best payment option from the x402 accepts array.
|
|
301
423
|
*
|
|
@@ -317,6 +439,15 @@ declare function encodePaymentProof(receipt: {
|
|
|
317
439
|
token: string;
|
|
318
440
|
amount: string;
|
|
319
441
|
to: string;
|
|
442
|
+
resourceUrl?: string;
|
|
443
|
+
accepted?: X402PaymentOption;
|
|
444
|
+
payer?: string;
|
|
445
|
+
chainId?: number;
|
|
320
446
|
}): string;
|
|
321
447
|
|
|
322
|
-
|
|
448
|
+
declare function parseMachinePaymentChallenge(response: Response): MachinePaymentChallenge;
|
|
449
|
+
declare function parseMachinePaymentChallengeResponse(response: Response): Promise<MachinePaymentChallenge>;
|
|
450
|
+
declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
|
|
451
|
+
declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
|
|
452
|
+
|
|
453
|
+
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|