@haven_ai/sdk 0.1.31-alpha.0 → 0.1.33-alpha.0
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 +52 -6
- package/dist/index.cjs +210 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -13
- package/dist/index.d.ts +111 -13
- package/dist/index.js +206 -21
- package/dist/index.js.map +1 -1
- package/package.json +15 -9
package/README.md
CHANGED
|
@@ -125,7 +125,8 @@ if (apiResponse.status === 402) {
|
|
|
125
125
|
const receipt = await haven.authorizeX402(paymentRequired, {
|
|
126
126
|
idempotencyKey: 'paid-api-data-2026-05-22',
|
|
127
127
|
})
|
|
128
|
-
// Retry with { '
|
|
128
|
+
// Retry with { 'PAYMENT-SIGNATURE': receipt.paymentHeader }, and on the
|
|
129
|
+
// EIP-3009 bridge 'X-PAYMENT' too. NEVER both on erc7710 — see below.
|
|
129
130
|
console.log(receipt.explorerUrl)
|
|
130
131
|
}
|
|
131
132
|
```
|
|
@@ -209,7 +210,7 @@ const response = await haven.payX402Quote(quote)
|
|
|
209
210
|
const data = await response.json()
|
|
210
211
|
```
|
|
211
212
|
|
|
212
|
-
Merchant-verified x402 retries use the official EIP-3009 `exact` scheme on Base USDC (`base` / `eip155:8453`)
|
|
213
|
+
Merchant-verified x402 retries use the official EIP-3009 `exact` scheme on Base USDC (`base` / `eip155:8453`). `haven.fetch()` sends the payment under `PAYMENT-SIGNATURE` (the x402 v2 name), and on the EIP-3009 bridge also under `X-PAYMENT` (v1), so a merchant on either version reads it. **On erc7710 it sends the v2 name ALONE**: that payload is always x402 v2, and its header carries a whole delegation chain, so duplicating it overflows the merchant's header limit and the request is refused with HTTP 431. If you build the retry yourself, follow the same rule. Haven's older tx-hash proof helper remains exported for Haven-native integrations; it is a different payload that happens to have shared the v2 name, and it is not what `haven.fetch()` sends.
|
|
213
214
|
|
|
214
215
|
For standard x402, the `x402-wallet` identity is the agent delegate wallet, because that is the wallet that signs and settles the merchant payment. Integrations that scope access by Haven wallet/Safe address should use a Haven-native flow instead of standard merchant x402.
|
|
215
216
|
|
|
@@ -364,7 +365,7 @@ x402 tool-window failures:
|
|
|
364
365
|
| `expired` | Payment expired before completion. | yes |
|
|
365
366
|
| `failed` | Haven could not complete the payment. | yes |
|
|
366
367
|
|
|
367
|
-
The merchant settlement leg of x402 (and the MPP retry) is the agent's own request to the merchant — it does not have a Haven `phase`. The payment is `funding_sent` until the agent retries with `X-PAYMENT` (x402) or the MPP proof header; from Haven's perspective the payment becomes `executed` only after the agent successfully resumes.
|
|
368
|
+
The merchant settlement leg of x402 (and the MPP retry) is the agent's own request to the merchant — it does not have a Haven `phase`. The payment is `funding_sent` until the agent retries with the payment header (`PAYMENT-SIGNATURE`, plus `X-PAYMENT` on this bridged path) (x402) or the MPP proof header; from Haven's perspective the payment becomes `executed` only after the agent successfully resumes.
|
|
368
369
|
|
|
369
370
|
### `nextAction` reference
|
|
370
371
|
|
|
@@ -471,7 +472,9 @@ Think of bridged x402 as two separate legs:
|
|
|
471
472
|
`txHash` describe this leg. It is automatic and bounded by the budget — no
|
|
472
473
|
human step.
|
|
473
474
|
- Merchant x402 leg: after the funding leg is complete, the agent resumes the
|
|
474
|
-
same payment id and retries the original merchant request with
|
|
475
|
+
same payment id and retries the original merchant request with the payment
|
|
476
|
+
header, under `PAYMENT-SIGNATURE` and — on this bridged path only —
|
|
477
|
+
`X-PAYMENT`.
|
|
475
478
|
Do not treat a new 402 probe or a new MCP session as a resume.
|
|
476
479
|
|
|
477
480
|
For manual HTTP stacks, use `resumeAuthorizedX402()` to get the merchant header
|
|
@@ -485,15 +488,58 @@ const receipt = await haven.resumeAuthorizedX402({
|
|
|
485
488
|
})
|
|
486
489
|
|
|
487
490
|
await fetch('https://paid-api.example.com/data', {
|
|
488
|
-
headers: {
|
|
491
|
+
headers: {
|
|
492
|
+
'PAYMENT-SIGNATURE': receipt.paymentHeader!,
|
|
493
|
+
// Bridged (EIP-3009) resume only. On erc7710 send the v2 name ALONE —
|
|
494
|
+
// that header carries a delegation chain and duplicating it is refused
|
|
495
|
+
// with HTTP 431.
|
|
496
|
+
'X-PAYMENT': receipt.paymentHeader!,
|
|
497
|
+
},
|
|
489
498
|
})
|
|
490
499
|
```
|
|
491
500
|
|
|
501
|
+
**When YOU make the retry, report the outcome (#2292).** `haven.fetch()` and
|
|
502
|
+
the `payX402*` helpers call the merchant themselves and write the evidence or
|
|
503
|
+
reconciliation record from what they observed. `resumeAuthorizedX402()` and the
|
|
504
|
+
raw MCP/SSE flow below deliberately do not — you hold the header and make the
|
|
505
|
+
call — so Haven cannot learn what happened unless you tell it:
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
const response = await fetch('https://paid-api.example.com/data', {
|
|
509
|
+
headers: {
|
|
510
|
+
'PAYMENT-SIGNATURE': receipt.paymentHeader!,
|
|
511
|
+
// Bridged (EIP-3009) resume only — see the erc7710 note above.
|
|
512
|
+
'X-PAYMENT': receipt.paymentHeader!,
|
|
513
|
+
},
|
|
514
|
+
})
|
|
515
|
+
|
|
516
|
+
await haven.reportX402MerchantOutcome({
|
|
517
|
+
paymentId: status.paymentId,
|
|
518
|
+
outcome: response.ok ? 'accepted' : 'rejected',
|
|
519
|
+
merchantStatus: response.status,
|
|
520
|
+
})
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
A `rejected` report writes the same open `merchant_retry_rejected_after_payment`
|
|
524
|
+
reconciliation event the built-in retry writes, so the next
|
|
525
|
+
`getPaymentStatus()` answers `phase: funded_but_unsettled` /
|
|
526
|
+
`nextAction: sweep_stranded_funds` instead of reading as complete for the
|
|
527
|
+
fifteen-minute merchant-report grace window. An `accepted` report records the
|
|
528
|
+
merchant response so a delivered payment never enters that window at all.
|
|
529
|
+
|
|
530
|
+
It is evidence, not authority. The funding transaction hash and resource URL are
|
|
531
|
+
read from the payment's own record rather than taken from you — they are not
|
|
532
|
+
parameters — the call is scoped to your own agent's payments, and it changes no
|
|
533
|
+
amount, recipient or status. `outcome` must agree with `merchantStatus`
|
|
534
|
+
(`accepted` only for a 2xx), and an acceptance is terminal: a rejection reported
|
|
535
|
+
after a recorded merchant response is refused rather than re-flagging a
|
|
536
|
+
delivered payment as stranded.
|
|
537
|
+
|
|
492
538
|
For MCP/SSE x402 tools, keep the same MCP session and JSON-RPC payload where the
|
|
493
539
|
merchant requires it: initialize, retain `mcp-session-id`, send the original
|
|
494
540
|
`tools/call`, parse the 402 challenge, wait for the funding leg to confirm if
|
|
495
541
|
the payment is bridged, then resume with the same `payment_id` and retry the
|
|
496
|
-
original `tools/call`
|
|
542
|
+
original `tools/call`, setting BOTH `PAYMENT-SIGNATURE` (x402 v2) and `X-PAYMENT` (v1) to the header. Use a stable `idempotencyKey` for the
|
|
497
543
|
user intent so fresh merchant quotes or sessions do not become duplicate Haven
|
|
498
544
|
payments.
|
|
499
545
|
|
package/dist/index.cjs
CHANGED
|
@@ -667,6 +667,30 @@ var NETWORK_TOKENS = {
|
|
|
667
667
|
"eip155:84532": BASE_SEPOLIA_TOKENS,
|
|
668
668
|
"base-sepolia": BASE_SEPOLIA_TOKENS
|
|
669
669
|
};
|
|
670
|
+
var X402_PAYMENT_HEADER_NAME = "PAYMENT-SIGNATURE";
|
|
671
|
+
var X402_LEGACY_PAYMENT_HEADER_NAME = "X-PAYMENT";
|
|
672
|
+
var X402_PAYMENT_REQUIRED_HEADER_NAME = "PAYMENT-REQUIRED";
|
|
673
|
+
var X402_PAYMENT_RESPONSE_HEADER_NAME = "PAYMENT-RESPONSE";
|
|
674
|
+
var X402_PAYMENT_HEADER_NAMES_SENT = `${X402_PAYMENT_HEADER_NAME}, ${X402_LEGACY_PAYMENT_HEADER_NAME}`;
|
|
675
|
+
var X402_PAYMENT_HEADER_NAMES = [
|
|
676
|
+
X402_PAYMENT_HEADER_NAME,
|
|
677
|
+
X402_LEGACY_PAYMENT_HEADER_NAME
|
|
678
|
+
];
|
|
679
|
+
function x402PaymentHeaderNamesFor(paymentHeader) {
|
|
680
|
+
const both = [X402_PAYMENT_HEADER_NAME, X402_LEGACY_PAYMENT_HEADER_NAME];
|
|
681
|
+
let decoded;
|
|
682
|
+
try {
|
|
683
|
+
decoded = decodeBase64Json(paymentHeader);
|
|
684
|
+
} catch {
|
|
685
|
+
return both;
|
|
686
|
+
}
|
|
687
|
+
const accepted = decoded?.accepted;
|
|
688
|
+
if (!accepted || typeof accepted !== "object" || Array.isArray(accepted)) return both;
|
|
689
|
+
return isErc7710Option(accepted) ? [X402_PAYMENT_HEADER_NAME] : both;
|
|
690
|
+
}
|
|
691
|
+
function x402PaymentHeaderNamesSent(paymentHeader) {
|
|
692
|
+
return x402PaymentHeaderNamesFor(paymentHeader).join(", ");
|
|
693
|
+
}
|
|
670
694
|
function parsePaymentRequired(response) {
|
|
671
695
|
const v2Header = response.headers.get("PAYMENT-REQUIRED");
|
|
672
696
|
if (v2Header) {
|
|
@@ -1157,7 +1181,7 @@ function nextActionForStatus(status) {
|
|
|
1157
1181
|
if (status === "submitted") return AgentPaymentNextAction.CheckStatusLater;
|
|
1158
1182
|
if (status === "confirmed") return AgentPaymentNextAction.None;
|
|
1159
1183
|
if (status === "pending" || status === "pending_approval") return AgentPaymentNextAction.StopAndTellUser;
|
|
1160
|
-
if (status === "approved") return AgentPaymentNextAction.
|
|
1184
|
+
if (status === "approved") return AgentPaymentNextAction.StopAndTellUser;
|
|
1161
1185
|
if (status === "proposed") return AgentPaymentNextAction.StopAndTellUser;
|
|
1162
1186
|
if (status === "executed") return AgentPaymentNextAction.StopAndTellUser;
|
|
1163
1187
|
if (status === "rejected") return AgentPaymentNextAction.StopAndTellUser;
|
|
@@ -1169,6 +1193,9 @@ function messageForState(label, status, paymentId, nextAction) {
|
|
|
1169
1193
|
if (status === "pending" || status === "pending_approval") {
|
|
1170
1194
|
return `${label} is not payable: it is outside the agent's on-chain budget and no approval is pending (payment_id: ${paymentId}). Ask the user to grant or raise the budget in Haven.`;
|
|
1171
1195
|
}
|
|
1196
|
+
if (status === "approved") {
|
|
1197
|
+
return `This payment carries a retired status ("approved") that no live Haven rail produces (payment_id: ${paymentId}). Nothing is waiting to be completed \u2014 tell the user to review this payment in Haven.`;
|
|
1198
|
+
}
|
|
1172
1199
|
if (status === "executed") {
|
|
1173
1200
|
return `This payment carries a retired status ("executed") that no live Haven rail produces (payment_id: ${paymentId}). Do not retry it \u2014 tell the user to review this payment in Haven.`;
|
|
1174
1201
|
}
|
|
@@ -1386,10 +1413,37 @@ var McpMerchantTransport = class {
|
|
|
1386
1413
|
hasBazaarExtension(response) {
|
|
1387
1414
|
return responseHasBazaarExtension(response);
|
|
1388
1415
|
}
|
|
1389
|
-
/**
|
|
1416
|
+
/**
|
|
1417
|
+
* Deliver an already-signed x402 header without changing the caller body.
|
|
1418
|
+
*
|
|
1419
|
+
* #2289: x402 v2 reads `PAYMENT-SIGNATURE`; v1 reads `X-PAYMENT`. Sending
|
|
1420
|
+
* only the legacy name meant a strict v2 merchant never saw the header —
|
|
1421
|
+
* indistinguishable, from the merchant's side, from sending no header at
|
|
1422
|
+
* all, while on the EIP-3009 bridge the funding leg had already moved the
|
|
1423
|
+
* money.
|
|
1424
|
+
*
|
|
1425
|
+
* #2341: WHICH names go on is per-payload, not always both — see
|
|
1426
|
+
* `x402PaymentHeaderNamesFor`. Both for EIP-3009; `PAYMENT-SIGNATURE` alone
|
|
1427
|
+
* for erc7710, whose header carries a whole delegation chain and answered
|
|
1428
|
+
* HTTP 431 when duplicated. The decision is made here rather than by the
|
|
1429
|
+
* caller so every path inherits it, and it is read from the payload rather
|
|
1430
|
+
* than passed in, because a flag a caller supplies is a flag a caller can
|
|
1431
|
+
* get wrong.
|
|
1432
|
+
*
|
|
1433
|
+
* Always `set`, never `append`, so a stale header on the caller's `init` is
|
|
1434
|
+
* replaced rather than added to — a merchant that reads the first of two
|
|
1435
|
+
* values would otherwise verify a superseded authorization. The name NOT
|
|
1436
|
+
* being sent is deleted for the same reason: on erc7710 a stale `X-PAYMENT`
|
|
1437
|
+
* left in place would be a superseded authorization we chose not to
|
|
1438
|
+
* overwrite, which is worse than the duplicate this change removes.
|
|
1439
|
+
*/
|
|
1390
1440
|
async deliverPayment(url, init, paymentHeader) {
|
|
1391
1441
|
const headers = new Headers(init?.headers);
|
|
1392
|
-
|
|
1442
|
+
const send = x402PaymentHeaderNamesFor(paymentHeader);
|
|
1443
|
+
for (const name of X402_PAYMENT_HEADER_NAMES) {
|
|
1444
|
+
if (send.includes(name)) headers.set(name, paymentHeader);
|
|
1445
|
+
else headers.delete(name);
|
|
1446
|
+
}
|
|
1393
1447
|
return this.fetch(url, { ...init, headers });
|
|
1394
1448
|
}
|
|
1395
1449
|
async notifyInitialized(url, init, sessionId, wallet) {
|
|
@@ -2235,10 +2289,11 @@ var X402Erc7710 = class {
|
|
|
2235
2289
|
* settled when this returns** — that is why it does not return an
|
|
2236
2290
|
* `X402Receipt`.
|
|
2237
2291
|
*
|
|
2238
|
-
* Requires a delegation-rail account. The backend enforces that
|
|
2239
|
-
*
|
|
2240
|
-
*
|
|
2241
|
-
*
|
|
2292
|
+
* Requires a delegation-rail account. The backend enforces that at the
|
|
2293
|
+
* rail seam — a non-delegation account gets the #1986 retired-rail 410 from
|
|
2294
|
+
* `POST /x402/authorize` whatever scheme it asks for (#2245) — and so does
|
|
2295
|
+
* this method, before building a request the backend would only reject: an
|
|
2296
|
+
* error a client can explain is worth more than a refusal it has to decode.
|
|
2242
2297
|
*
|
|
2243
2298
|
* **MCP callers must pass `options.resourceUrl`.** An in-band MCP 402
|
|
2244
2299
|
* challenge frequently carries no `resource` object at all, so
|
|
@@ -2532,7 +2587,7 @@ var MerchantCompletion = class {
|
|
|
2532
2587
|
merchantStatus: retryResponse.status,
|
|
2533
2588
|
challengePayload: paymentRequired,
|
|
2534
2589
|
selectedPayment: receipt.accepted,
|
|
2535
|
-
paymentProofHeaderName:
|
|
2590
|
+
paymentProofHeaderName: x402PaymentHeaderNamesSent(receipt.paymentHeader),
|
|
2536
2591
|
paymentProofHeader: receipt.paymentHeader,
|
|
2537
2592
|
protocolReceiptHeaderName: "PAYMENT-RESPONSE",
|
|
2538
2593
|
protocolReceiptHeader: retryResponse.headers.get("PAYMENT-RESPONSE") ?? void 0
|
|
@@ -2642,6 +2697,109 @@ var MerchantCompletion = class {
|
|
|
2642
2697
|
} catch {
|
|
2643
2698
|
}
|
|
2644
2699
|
}
|
|
2700
|
+
/**
|
|
2701
|
+
* #2292: record what a merchant said to a retry **Haven did not make**.
|
|
2702
|
+
*
|
|
2703
|
+
* On the plain-HTTP x402 path Haven tells the agent to call the merchant
|
|
2704
|
+
* itself — that is the keyless design, not an oversight — so the two writes
|
|
2705
|
+
* above were reachable only from `completeX402MerchantCall`, where Haven IS
|
|
2706
|
+
* the caller. A manual retry had nowhere to put its outcome, which left
|
|
2707
|
+
* `intentStateFor`'s merchant-rejected branch dead on the one flow Haven
|
|
2708
|
+
* prescribes and made the 15-minute grace window the only route to
|
|
2709
|
+
* `funded_but_unsettled`.
|
|
2710
|
+
*
|
|
2711
|
+
* Three properties distinguish this from `recordRetryRejected` /
|
|
2712
|
+
* `reportEvidence`, and each is deliberate:
|
|
2713
|
+
*
|
|
2714
|
+
* 1. **It does not swallow.** Those two are bookkeeping hung off a call
|
|
2715
|
+
* whose outcome is already decided, so an exception there would turn a
|
|
2716
|
+
* completed payment into a reported failure. Here the report IS the
|
|
2717
|
+
* caller's request; silently dropping it would recreate the exact
|
|
2718
|
+
* unobservability #2292 exists to remove.
|
|
2719
|
+
* 2. **The anchor is server-side.** `txHash` and `resourceUrl` come from
|
|
2720
|
+
* the payment's own Haven record, never from the reporter — so a report
|
|
2721
|
+
* cannot be pointed at a different transaction or a different resource,
|
|
2722
|
+
* and it can never CONFIRM an intent (an erc7710 intent has no Haven
|
|
2723
|
+
* tx hash and is refused here rather than completed from a supplied one,
|
|
2724
|
+
* which is #2092's verified seam and stays its own path).
|
|
2725
|
+
* 3. **It is evidence, never authority.** Haven does not and must not check
|
|
2726
|
+
* the claim: verifying it would mean calling the merchant, which is the
|
|
2727
|
+
* property this whole path exists to preserve. What bounds a false
|
|
2728
|
+
* report is scope — the backend routes resolve the payment
|
|
2729
|
+
* `WHERE agent_id = $`, so a caller can only ever describe its own
|
|
2730
|
+
* payment — plus the fact that nothing financial keys off the claim:
|
|
2731
|
+
* the sweep is balance-driven, the intent's status/amount/recipient are
|
|
2732
|
+
* untouched, and a false `accepted` runs the server's own on-chain
|
|
2733
|
+
* residue check, which re-flags stranded funds independently.
|
|
2734
|
+
*/
|
|
2735
|
+
async reportMerchantOutcome(input) {
|
|
2736
|
+
if (!Number.isInteger(input.merchantStatus) || input.merchantStatus < 100 || input.merchantStatus > 599) {
|
|
2737
|
+
throw new HavenApiError(
|
|
2738
|
+
`merchant_status must be an integer HTTP status from 100 to 599 (received ${input.merchantStatus}).`,
|
|
2739
|
+
400,
|
|
2740
|
+
void 0,
|
|
2741
|
+
input.paymentId
|
|
2742
|
+
);
|
|
2743
|
+
}
|
|
2744
|
+
const looksAccepted = input.merchantStatus >= 200 && input.merchantStatus < 300;
|
|
2745
|
+
if (looksAccepted !== (input.outcome === "accepted")) {
|
|
2746
|
+
throw new HavenApiError(
|
|
2747
|
+
`outcome "${input.outcome}" contradicts merchant_status ${input.merchantStatus}: report "accepted" only for a 2xx and "rejected" only for a non-2xx.`,
|
|
2748
|
+
400,
|
|
2749
|
+
void 0,
|
|
2750
|
+
input.paymentId
|
|
2751
|
+
);
|
|
2752
|
+
}
|
|
2753
|
+
const status = await this.getPaymentStatus(input.paymentId);
|
|
2754
|
+
if (status.rail !== "x402") {
|
|
2755
|
+
throw new HavenPaymentStateError(
|
|
2756
|
+
`Payment ${status.paymentId} is ${status.rail}, not x402 \u2014 there is no merchant retry to report.`,
|
|
2757
|
+
409,
|
|
2758
|
+
status
|
|
2759
|
+
);
|
|
2760
|
+
}
|
|
2761
|
+
if (status.status !== "confirmed" || !status.txHash) {
|
|
2762
|
+
throw new HavenPaymentStateError(
|
|
2763
|
+
`Payment ${status.paymentId} has no confirmed Haven funding transaction to anchor a merchant report to (status ${status.status}). ${status.message}`,
|
|
2764
|
+
paymentStateStatusCode(status.status, 409),
|
|
2765
|
+
status
|
|
2766
|
+
);
|
|
2767
|
+
}
|
|
2768
|
+
const resourceUrl = status.resourceUrl ?? status.x402?.resourceUrl ?? null;
|
|
2769
|
+
if (!resourceUrl) {
|
|
2770
|
+
throw new HavenApiError(
|
|
2771
|
+
`Payment ${status.paymentId} has no recorded resource URL, so a merchant report cannot be stored.`,
|
|
2772
|
+
409,
|
|
2773
|
+
status,
|
|
2774
|
+
status.paymentId
|
|
2775
|
+
);
|
|
2776
|
+
}
|
|
2777
|
+
const txHash = status.txHash;
|
|
2778
|
+
if (input.outcome === "rejected") {
|
|
2779
|
+
await this.post("/machine-payments/reconciliation-events", {
|
|
2780
|
+
paymentId: status.paymentId,
|
|
2781
|
+
rail: "x402",
|
|
2782
|
+
eventType: "merchant_retry_rejected_after_payment",
|
|
2783
|
+
txHash,
|
|
2784
|
+
reason: `Agent-reported: merchant returned HTTP ${input.merchantStatus} to a manual retry after Haven payment confirmation`,
|
|
2785
|
+
details: {
|
|
2786
|
+
resource_url: resourceUrl,
|
|
2787
|
+
retry_status: input.merchantStatus,
|
|
2788
|
+
retry_body: input.merchantBody?.slice(0, MERCHANT_BODY_SNIPPET_LIMIT) || null,
|
|
2789
|
+
reported_by: "agent_manual_retry"
|
|
2790
|
+
}
|
|
2791
|
+
});
|
|
2792
|
+
return { paymentId: status.paymentId, outcome: "rejected", txHash, resourceUrl, recorded: "reconciliation_event" };
|
|
2793
|
+
}
|
|
2794
|
+
await this.post("/machine-payments/evidence", {
|
|
2795
|
+
paymentId: status.paymentId,
|
|
2796
|
+
rail: "x402",
|
|
2797
|
+
txHash,
|
|
2798
|
+
resourceUrl,
|
|
2799
|
+
merchantStatus: input.merchantStatus
|
|
2800
|
+
});
|
|
2801
|
+
return { paymentId: status.paymentId, outcome: "accepted", txHash, resourceUrl, recorded: "evidence" };
|
|
2802
|
+
}
|
|
2645
2803
|
async reportEvidence(input) {
|
|
2646
2804
|
const body = {
|
|
2647
2805
|
paymentId: input.paymentId,
|
|
@@ -3528,7 +3686,7 @@ var HavenClient = class {
|
|
|
3528
3686
|
* Deliver an already-signed x402 payment header to the merchant and return
|
|
3529
3687
|
* the merchant's response. Used by the hosted MCP server to complete the
|
|
3530
3688
|
* merchant leg of an MCP tool payment after the edge signer has built the
|
|
3531
|
-
*
|
|
3689
|
+
* merchant payment header.
|
|
3532
3690
|
*
|
|
3533
3691
|
* Custody note: this never needs the delegate key. It relays a signed,
|
|
3534
3692
|
* amount/merchant/nonce-bound EIP-3009 authorization the edge signer already
|
|
@@ -3538,13 +3696,14 @@ var HavenClient = class {
|
|
|
3538
3696
|
* says the merchant was Bazaar-discoverable, runs a fresh `initialize`
|
|
3539
3697
|
* handshake (the quote-time session is gone once funding confirms; the x402
|
|
3540
3698
|
* challenge is stateless w.r.t. the MCP session, so a fresh session is
|
|
3541
|
-
* accepted), threads the session + wallet headers, sets
|
|
3699
|
+
* accepted), threads the session + wallet headers, sets the x402 payment
|
|
3700
|
+
* header under the names that scheme requires (#2341), and
|
|
3542
3701
|
* collapses an SSE JSON-RPC response to its `result`.
|
|
3543
3702
|
*/
|
|
3544
3703
|
/**
|
|
3545
3704
|
* Wait for a payment's Safe→delegate funding tx to reach ≥1 on-chain
|
|
3546
3705
|
* confirmation. The hosted x402 completion path MUST call this after funding
|
|
3547
|
-
* and before delivering the
|
|
3706
|
+
* and before delivering the merchant payment header, so the merchant's
|
|
3548
3707
|
* balanceOf(delegate) / transferWithAuthorization verification sees the funded
|
|
3549
3708
|
* balance — otherwise it rejects with "Payment verification failed". The
|
|
3550
3709
|
* SDK's local path already does this (see `X402FundingLeg.authorize`); the hosted
|
|
@@ -3619,7 +3778,7 @@ var HavenClient = class {
|
|
|
3619
3778
|
txHash: evidenceTxHash,
|
|
3620
3779
|
resourceUrl: evidenceContext.resourceUrl,
|
|
3621
3780
|
merchantStatus: surfaced.status,
|
|
3622
|
-
paymentProofHeaderName:
|
|
3781
|
+
paymentProofHeaderName: x402PaymentHeaderNamesSent(input.paymentHeader),
|
|
3623
3782
|
paymentProofHeader: input.paymentHeader,
|
|
3624
3783
|
protocolReceiptHeaderName: protocolReceiptHeader ? "PAYMENT-RESPONSE" : void 0,
|
|
3625
3784
|
protocolReceiptHeader
|
|
@@ -3634,6 +3793,18 @@ var HavenClient = class {
|
|
|
3634
3793
|
settlementTxHash: settlement.settlementTxHash ?? void 0
|
|
3635
3794
|
};
|
|
3636
3795
|
}
|
|
3796
|
+
/**
|
|
3797
|
+
* #2292: report the outcome of a merchant retry the AGENT performed.
|
|
3798
|
+
*
|
|
3799
|
+
* The hosted `haven_complete_mcp_tool` / `completeX402MerchantCall` path is
|
|
3800
|
+
* for merchants Haven calls itself. On the plain-HTTP x402 path Haven never
|
|
3801
|
+
* talks to the merchant, so the outcome of that retry had no way back —
|
|
3802
|
+
* see `MerchantCompletion.reportMerchantOutcome` for what is verified about
|
|
3803
|
+
* a caller-asserted report and what deliberately is not.
|
|
3804
|
+
*/
|
|
3805
|
+
async reportX402MerchantOutcome(input) {
|
|
3806
|
+
return await this.merchantCompletion.reportMerchantOutcome(input);
|
|
3807
|
+
}
|
|
3637
3808
|
/**
|
|
3638
3809
|
* GET /x402/:id/merchant-call-context — the settle-leg twin of #1263's
|
|
3639
3810
|
* sign-context fetch (#1307). Re-serves the stored merchant MCP-tool call
|
|
@@ -3795,12 +3966,12 @@ var toolDescriptions = {
|
|
|
3795
3966
|
payX402OneShot: {
|
|
3796
3967
|
summary: "Fetch an x402 paid HTTP resource in a single call. Handles the full probe -> pay -> retry round trip and returns the merchant response.",
|
|
3797
3968
|
selectionGuidance: "Prefer this over the quote+pay split when the agent just wants the paid resource and does not need to inspect the price first. If you already have a quote from haven_quote_x402, use haven_pay_x402_quote instead. Do not use for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.",
|
|
3798
|
-
behavior: "Calls the URL, parses any HTTP 402 x402 challenge, signs the payment locally, then retries the original request with the X-PAYMENT
|
|
3969
|
+
behavior: "Calls the URL, parses any HTTP 402 x402 challenge, signs the payment locally, then retries the original request with the signed payment header (sent under PAYMENT-SIGNATURE, plus the legacy X-PAYMENT on the EIP-3009 path only) and returns the merchant response. Settlement is either direct account-to-merchant with no funding leg, or a bridge that first redeems the agent's budget delegation to fund the delegate wallet for an EIP-3009 authorization. A payment outside the on-chain budget is declined before any money moves; nothing is queued for a human to approve later. If the resource returns a non-402 status, returns it unchanged without contacting Haven.",
|
|
3799
3970
|
nextActionGuidance: "Preserve the returned resume_state or paymentId \u2014 either identifies this payment if you need to ask about it later. This tool performs the merchant retry itself, so do not wait on a signal while the call is in flight. If the process crashes after this call and a later haven_get_payment_status reports nextAction=retry_original_x402_request, Haven's funding leg confirmed but no merchant response was ever recorded \u2014 call the resume tool with the preserved resume_state or payment_id instead of paying again. If the response carries phase=insufficient_funds and nextAction=fund_safe_or_raise_allowance, the payment cannot be retried until the account is funded or the agent budget raised \u2014 stop and tell the user the shortfall reported on the response."
|
|
3800
3971
|
},
|
|
3801
3972
|
resumeX402: {
|
|
3802
3973
|
summary: "Resume an x402 payment whose Haven-side authorization already succeeded but whose merchant retry did not complete.",
|
|
3803
|
-
behavior: "Accepts either resume_state or payment_id, validates the original x402 details against the authorized Haven funding, and retries the merchant request with the X-PAYMENT
|
|
3974
|
+
behavior: "Accepts either resume_state or payment_id, validates the original x402 details against the authorized Haven funding, and retries the merchant request with the signed payment header (sent under PAYMENT-SIGNATURE, plus the legacy X-PAYMENT on the EIP-3009 path only). No new Haven payment is created.",
|
|
3804
3975
|
nextActionGuidance: "Only call this after haven_get_payment_status reports nextAction=retry_original_x402_request \u2014 that means Haven's funding leg confirmed but no merchant response was ever recorded, most often because the process crashed between funding and the merchant retry. Any other nextAction reports a conflict instead of retrying, so do not call this speculatively. Do not start a new merchant session and do not pay again \u2014 that would pay twice for one resource."
|
|
3805
3976
|
},
|
|
3806
3977
|
// #1328: quoteMpp / payMpp / resumeMpp (the mpp_demo challenge/quote/resume
|
|
@@ -3986,7 +4157,7 @@ var resumeX402Schema = {
|
|
|
3986
4157
|
var MAKE_PAYMENT_DESCRIPTION = "Request and sign a payment from the user-controlled account within its on-chain budget. For read-only allowance, budget, spend-limit, remaining-amount, or reset-period questions, use get_allowances instead of making a payment. Haven authenticates the agent and relays the signed transaction that redeems the agent budget delegation; it does not hold keys or control funds. Gnosis Chain tokens: EURe, USDC.e, xDAI. Base tokens: USDC, ETH.";
|
|
3987
4158
|
var GET_STATUS_DESCRIPTION = toolDescriptions.getPaymentStatus.summary + " Accepts payment intent IDs. Returns the current status, phase, next_action, transaction hash if available, and payment details.";
|
|
3988
4159
|
var GET_ALLOWANCES_DESCRIPTION = composeDescription(toolDescriptions.getAllowances);
|
|
3989
|
-
var AUTHORIZE_X402_DESCRIPTION = composeDescription(toolDescriptions.payX402) + " In this SDK tool set, the allowance lookup tool is get_allowances. When a paid API returns x402 payment requirements, use this tool to sign with the agent-owned delegate key; funding, when the scheme needs it, is redeemed from the agent budget delegation and is bounded by it. Haven relays signed transactions only; the agent key authorizes payment and on-chain limits enforce spend. A payment outside the on-chain budget is declined before any money moves \u2014 report the decline and ask the user to raise the budget in Haven; do not loop retries and do not wait for an approval, because none is queued. Preserve the original merchant/MCP session and x402 details.
|
|
4160
|
+
var AUTHORIZE_X402_DESCRIPTION = composeDescription(toolDescriptions.payX402) + " In this SDK tool set, the allowance lookup tool is get_allowances. When a paid API returns x402 payment requirements, use this tool to sign with the agent-owned delegate key; funding, when the scheme needs it, is redeemed from the agent budget delegation and is bounded by it. Haven relays signed transactions only; the agent key authorizes payment and on-chain limits enforce spend. A payment outside the on-chain budget is declined before any money moves \u2014 report the decline and ask the user to raise the budget in Haven; do not loop retries and do not wait for an approval, because none is queued. Preserve the original merchant/MCP session and x402 details. On a manual HTTP retry always set PAYMENT-SIGNATURE (x402 v2) to the returned payment_header; a strict v2 merchant reads only that name. Also set X-PAYMENT (v1) on the EIP-3009 funding path for legacy merchants, but NEVER on erc7710 \u2014 that header carries a delegation chain and duplicating it is refused with HTTP 431.";
|
|
3990
4161
|
var RESUME_X402_DESCRIPTION = toolDescriptions.resumeX402.summary + " Only call this after get_payment_status reports nextAction=retry_original_x402_request \u2014 that means Haven's funding leg confirmed but no merchant response was ever recorded (typically a crash between funding and the merchant retry). Any other nextAction reports a conflict instead of retrying \u2014 do not call this speculatively, and do not pay again.";
|
|
3991
4162
|
var SWEEP_DELEGATE_DESCRIPTION = composeDescription(toolDescriptions.sweep_delegate);
|
|
3992
4163
|
var sweepDelegateSchema = {
|
|
@@ -4209,8 +4380,20 @@ merchant leg for you.
|
|
|
4209
4380
|
recipient, amount, and token for a plain transfer. For an arbitrary,
|
|
4210
4381
|
non-MCP x402 paywall: \`mcp__haven__haven_quote_x402\` to get a quote, then
|
|
4211
4382
|
\`mcp__haven__haven_pay_x402_quote\` \u2014 follow the result's guidance fields
|
|
4212
|
-
first and sign in the local Haven signer.
|
|
4213
|
-
|
|
4383
|
+
first and sign in the local Haven signer. On THIS path Haven does not talk to
|
|
4384
|
+
the merchant: \`mcp__haven-signer__haven_sign_x402\` returns both
|
|
4385
|
+
\`signature\` and \`payment_header\`; relay \`signature\` with
|
|
4386
|
+
\`mcp__haven__haven_submit\`, then retry the paywalled URL yourself with
|
|
4387
|
+
\`payment_header\`. Do not pass that call's \`x402_binding\` to
|
|
4388
|
+
\`mcp__haven-signer__haven_x402_sign_header\` \u2014 the one-shot already spent it
|
|
4389
|
+
building the header, so the call can only refuse. Then tell Haven what the
|
|
4390
|
+
merchant answered: \`mcp__haven__haven_report_x402_outcome\` with the
|
|
4391
|
+
\`payment_id\`, \`outcome\` (\`"accepted"\` for a 2xx, else \`"rejected"\`)
|
|
4392
|
+
and the \`merchant_status\` you got. Because Haven never contacted that
|
|
4393
|
+
merchant, this is the only way it can learn the purchase failed \u2014 without it a
|
|
4394
|
+
failed purchase reads as complete for fifteen minutes. (The SDK's own
|
|
4395
|
+
\`haven_pay_x402\` tool does perform the merchant retry itself; that tool is
|
|
4396
|
+
not part of the hosted MCP surface.) If the process
|
|
4214
4397
|
crashes after payment, a later \`mcp__haven__haven_get_payment_status\` call
|
|
4215
4398
|
may report \`nextAction: 'retry_original_x402_request'\` \u2014 only then call
|
|
4216
4399
|
\`mcp__haven__haven_resume_x402_payment\` with the preserved resume state or
|
|
@@ -4225,9 +4408,11 @@ payment id, instead of paying again.
|
|
|
4225
4408
|
result, never a catalog price. \`haven_discover_tools\` prices are indicative
|
|
4226
4409
|
(\`price_is_indicative\`) and can be stale. A read-only quote is informational
|
|
4227
4410
|
only and does not reserve a price; the later paid call re-quotes and enforces
|
|
4228
|
-
the cap. The pay-tool result's \`amount\` / \`amount_atomic\` is the
|
|
4229
|
-
|
|
4230
|
-
so present it as the most the user will pay.
|
|
4411
|
+
the cap. The pay-tool result's \`amount\` / \`amount_atomic\` is the merchant's
|
|
4412
|
+
own quoted price for that call \u2014 a ceiling the merchant settles at or below \u2014
|
|
4413
|
+
so present it as the most the user will pay. It is a price, not an approval:
|
|
4414
|
+
the payment goes through only if it also fits the cap you set and the on-chain
|
|
4415
|
+
budget the user signed, which is enforced on-chain rather than by Haven.
|
|
4231
4416
|
|
|
4232
4417
|
**Status:** \`mcp__haven__haven_get_payment_status\` with a \`payment_id\` to
|
|
4233
4418
|
check on in-flight payments. Do not poll in a tight loop.
|
|
@@ -4422,7 +4607,12 @@ exports.TRANSFER_WITH_AUTHORIZATION_TYPES = TRANSFER_WITH_AUTHORIZATION_TYPES;
|
|
|
4422
4607
|
exports.X402AlreadySettledError = X402AlreadySettledError;
|
|
4423
4608
|
exports.X402PaymentHeaderValidationError = X402PaymentHeaderValidationError;
|
|
4424
4609
|
exports.X402UnexpectedStatusError = X402UnexpectedStatusError;
|
|
4610
|
+
exports.X402_LEGACY_PAYMENT_HEADER_NAME = X402_LEGACY_PAYMENT_HEADER_NAME;
|
|
4425
4611
|
exports.X402_MAX_AUTHORIZATION_WINDOW_SECONDS = X402_MAX_AUTHORIZATION_WINDOW_SECONDS;
|
|
4612
|
+
exports.X402_PAYMENT_HEADER_NAME = X402_PAYMENT_HEADER_NAME;
|
|
4613
|
+
exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
4614
|
+
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
4615
|
+
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
4426
4616
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
4427
4617
|
exports.addressFromKey = addressFromKey;
|
|
4428
4618
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|