@haven_ai/sdk 0.1.28-alpha.0 → 0.1.30-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/dist/index.d.cts CHANGED
@@ -334,6 +334,13 @@ interface X402Intent {
334
334
  network: string;
335
335
  /** Haven-authenticated binding over the x402 expected context. */
336
336
  expectedAuth: X402ExpectedAuth;
337
+ /**
338
+ * #1690: the payer identity Haven bound into the expected context (v3),
339
+ * relayed VERBATIM to the signer's wire shape. Absent until the backend
340
+ * flips X402_EMIT_PAYER_CONTEXT.
341
+ */
342
+ payerDelegate?: string;
343
+ payerAgentId?: string;
337
344
  /**
338
345
  * EIP-712 digest of `signData.typed_data`, present on the delegation rail
339
346
  * (#1138). The edge signer needs it to reconstruct the v2 expected-context
@@ -364,6 +371,16 @@ interface X402ExpectedContext {
364
371
  * this digest makes Haven's declaration cover the real payload.
365
372
  */
366
373
  typedDataHash?: string;
374
+ /**
375
+ * The DELEGATE ADDRESS this quote was created for (#1690). Present ⇒ the
376
+ * context is **version 3** and the signer refuses to sign when this is not
377
+ * its own delegate — the guard that turns "quote as agent A, sign as agent
378
+ * B" from an on-chain revert three layers later into a named refusal.
379
+ * Inside the Haven-signed message on purpose: outside it, it is forgeable.
380
+ */
381
+ payerDelegate?: string;
382
+ /** The paying agent's id, for the refusal message's diagnosis (#1690). */
383
+ payerAgentId?: string;
367
384
  }
368
385
  interface X402ExpectedAuth {
369
386
  /**
@@ -653,6 +670,36 @@ interface HavenPaymentReceipt {
653
670
  createdAt: string;
654
671
  updatedAt: string;
655
672
  }
673
+ /**
674
+ * How long this SDK waits for an on-chain confirmation before it stops
675
+ * waiting (#1756).
676
+ *
677
+ * Lives here rather than in `client.ts` so the payment-confirmation poller
678
+ * and the delegate sweep share ONE number instead of forking it. The SDK's
679
+ * other chain waits are already bounded (`waitForFundingTx` at 30 s), so a
680
+ * fourth independently chosen literal is exactly the drift this constant
681
+ * exists to prevent.
682
+ */
683
+ declare const DEFAULT_CONFIRMATION_TIMEOUT_MS = 90000;
684
+ /**
685
+ * Whether a sweep transfer was observed to confirm (#1756).
686
+ *
687
+ * The distinction is the point: `unconfirmed` means the transfer was
688
+ * BROADCAST and may still land, which is neither success nor failure. It must
689
+ * never be collapsed into either — reporting a still-pending transaction as
690
+ * done, or as failed, are the same defect in opposite directions.
691
+ */
692
+ type SweepConfirmation =
693
+ /** A receipt was observed. The funds are in the Safe. */
694
+ 'confirmed'
695
+ /**
696
+ * Broadcast, but no receipt within `DEFAULT_CONFIRMATION_TIMEOUT_MS` (or the
697
+ * node returned no receipt). The transaction is still in the mempool and may
698
+ * mine at any time. `txHash` is the broadcast hash — check it on the
699
+ * explorer before re-running the sweep, and expect a re-run to find nothing
700
+ * stranded if it has since landed.
701
+ */
702
+ | 'unconfirmed';
656
703
  /** One transferred asset in a delegate sweep. */
657
704
  interface SweepEntry {
658
705
  /** 'USDC' or 'ETH' */
@@ -661,10 +708,24 @@ interface SweepEntry {
661
708
  amount: string;
662
709
  /** Atomic amount swept */
663
710
  amountAtomic: string;
664
- /** Transaction hash of the sweep transfer */
711
+ /**
712
+ * Transaction hash of the sweep transfer.
713
+ *
714
+ * The RECEIPT hash when `confirmation` is `confirmed`; the BROADCAST hash
715
+ * when it is `unconfirmed` — which is the whole reason the sweep returns
716
+ * instead of throwing on a deadline, since this hash is the only thing that
717
+ * lets a user recover the transfer by hand (#1756).
718
+ */
665
719
  txHash: string;
666
720
  /** Block explorer URL for the tx */
667
721
  explorerUrl: string;
722
+ /**
723
+ * Did this transfer confirm on-chain within the deadline? (#1756)
724
+ *
725
+ * `unconfirmed` entries have MOVED NOTHING YET and may still move. Do not
726
+ * report a sweep as complete without checking this on every entry.
727
+ */
728
+ confirmation: SweepConfirmation;
668
729
  }
669
730
  /** Result of a `sweepDelegate()` call. */
670
731
  interface SweepResult {
@@ -676,6 +737,16 @@ interface SweepResult {
676
737
  chainId: number;
677
738
  /** One entry per transferred asset. Empty when nothing was stranded. */
678
739
  transfers: SweepEntry[];
740
+ /**
741
+ * True when ANY entry is `unconfirmed` — i.e. the sweep broadcast something
742
+ * it could not confirm within the deadline (#1756).
743
+ *
744
+ * Derived from `transfers`, and present anyway because the consumer most
745
+ * likely to misread this result is an LLM reading the JSON of the
746
+ * `haven_sweep_delegate` tool, which will otherwise see a populated
747
+ * `transfers` array and report the money as recovered.
748
+ */
749
+ unconfirmed: boolean;
679
750
  }
680
751
  type PaymentStateKind = 'payment_intent' | 'approval_request';
681
752
  interface AgentPaymentEnumSchema {
@@ -2016,7 +2087,7 @@ declare const toolDescriptions: {
2016
2087
  readonly summary: "Sweep stranded USDC and/or ETH from the delegate wallet back to the originating Safe.";
2017
2088
  readonly selectionGuidance: string;
2018
2089
  readonly behavior: string;
2019
- readonly nextActionGuidance: "If transfers is non-empty, confirm the amounts with the user. No further action required — funds are on their way back to the Safe.";
2090
+ readonly nextActionGuidance: string;
2020
2091
  };
2021
2092
  readonly send: {
2022
2093
  readonly summary: "Send ETH or USDC directly from the agent's Haven wallet to a recipient address.";
@@ -2416,4 +2487,4 @@ declare function discoverMerchantMcpUrl(inputUrl: string): Promise<string | null
2416
2487
  /** Trailing-slash/percent-case echoes compare equal; unparseable never does. */
2417
2488
  declare function sameUrl(a: string, b: string): boolean;
2418
2489
 
2419
- export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentNextStep, type AgentPaymentEnumSchema, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type AgentPaymentSummary, type AgentPaymentWarning, AgentPaymentWarningCode, type AgentPurchaseSummary, type ClaudeTool, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, type HavenAgent, type HavenAgentAllowanceSummary, type HavenAgentReadiness, type HavenAgentSummary, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, type HavenCatalogEntry, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, type MachinePaymentRail, MerchantTimeoutError, type OpenAITool, type PaymentFee, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentReceipt, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type PostPurchaseAllowanceSummary, RECEIPT_VERSION, type ReceiptVerification, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, type SharedToolKey, type SignData, SignerRefusalCode, type SweepAuthorization, type SweepEip712Domain, type SweepEntry, type SweepExpectedAuth, type SweepPreparation, type SweepPrepareResponse, type SweepResult, type SweepSubmitResponse, type SweepSubmitResult, type SweepTypedData, TRANSFER_WITH_AUTHORIZATION_TYPES, type ToolDescription, type UnsupportedNodeVersionMessageOptions, X402AlreadySettledError, type X402AuthorizationOptions, type X402Erc7710Settlement, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402McpCallContext, type X402McpTransport, type X402MerchantCallContext, type X402PaymentHeaderContext, X402PaymentHeaderValidationError, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, type X402SchemeSelection, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
2490
+ export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentNextStep, type AgentPaymentEnumSchema, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type AgentPaymentSummary, type AgentPaymentWarning, AgentPaymentWarningCode, type AgentPurchaseSummary, type ClaudeTool, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, type HavenAgent, type HavenAgentAllowanceSummary, type HavenAgentReadiness, type HavenAgentSummary, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, type HavenCatalogEntry, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, type MachinePaymentRail, MerchantTimeoutError, type OpenAITool, type PaymentFee, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentReceipt, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type PostPurchaseAllowanceSummary, RECEIPT_VERSION, type ReceiptVerification, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, type SharedToolKey, type SignData, SignerRefusalCode, type SweepAuthorization, type SweepConfirmation, type SweepEip712Domain, type SweepEntry, type SweepExpectedAuth, type SweepPreparation, type SweepPrepareResponse, type SweepResult, type SweepSubmitResponse, type SweepSubmitResult, type SweepTypedData, TRANSFER_WITH_AUTHORIZATION_TYPES, type ToolDescription, type UnsupportedNodeVersionMessageOptions, X402AlreadySettledError, type X402AuthorizationOptions, type X402Erc7710Settlement, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402McpCallContext, type X402McpTransport, type X402MerchantCallContext, type X402PaymentHeaderContext, X402PaymentHeaderValidationError, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, type X402SchemeSelection, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
package/dist/index.d.ts CHANGED
@@ -334,6 +334,13 @@ interface X402Intent {
334
334
  network: string;
335
335
  /** Haven-authenticated binding over the x402 expected context. */
336
336
  expectedAuth: X402ExpectedAuth;
337
+ /**
338
+ * #1690: the payer identity Haven bound into the expected context (v3),
339
+ * relayed VERBATIM to the signer's wire shape. Absent until the backend
340
+ * flips X402_EMIT_PAYER_CONTEXT.
341
+ */
342
+ payerDelegate?: string;
343
+ payerAgentId?: string;
337
344
  /**
338
345
  * EIP-712 digest of `signData.typed_data`, present on the delegation rail
339
346
  * (#1138). The edge signer needs it to reconstruct the v2 expected-context
@@ -364,6 +371,16 @@ interface X402ExpectedContext {
364
371
  * this digest makes Haven's declaration cover the real payload.
365
372
  */
366
373
  typedDataHash?: string;
374
+ /**
375
+ * The DELEGATE ADDRESS this quote was created for (#1690). Present ⇒ the
376
+ * context is **version 3** and the signer refuses to sign when this is not
377
+ * its own delegate — the guard that turns "quote as agent A, sign as agent
378
+ * B" from an on-chain revert three layers later into a named refusal.
379
+ * Inside the Haven-signed message on purpose: outside it, it is forgeable.
380
+ */
381
+ payerDelegate?: string;
382
+ /** The paying agent's id, for the refusal message's diagnosis (#1690). */
383
+ payerAgentId?: string;
367
384
  }
368
385
  interface X402ExpectedAuth {
369
386
  /**
@@ -653,6 +670,36 @@ interface HavenPaymentReceipt {
653
670
  createdAt: string;
654
671
  updatedAt: string;
655
672
  }
673
+ /**
674
+ * How long this SDK waits for an on-chain confirmation before it stops
675
+ * waiting (#1756).
676
+ *
677
+ * Lives here rather than in `client.ts` so the payment-confirmation poller
678
+ * and the delegate sweep share ONE number instead of forking it. The SDK's
679
+ * other chain waits are already bounded (`waitForFundingTx` at 30 s), so a
680
+ * fourth independently chosen literal is exactly the drift this constant
681
+ * exists to prevent.
682
+ */
683
+ declare const DEFAULT_CONFIRMATION_TIMEOUT_MS = 90000;
684
+ /**
685
+ * Whether a sweep transfer was observed to confirm (#1756).
686
+ *
687
+ * The distinction is the point: `unconfirmed` means the transfer was
688
+ * BROADCAST and may still land, which is neither success nor failure. It must
689
+ * never be collapsed into either — reporting a still-pending transaction as
690
+ * done, or as failed, are the same defect in opposite directions.
691
+ */
692
+ type SweepConfirmation =
693
+ /** A receipt was observed. The funds are in the Safe. */
694
+ 'confirmed'
695
+ /**
696
+ * Broadcast, but no receipt within `DEFAULT_CONFIRMATION_TIMEOUT_MS` (or the
697
+ * node returned no receipt). The transaction is still in the mempool and may
698
+ * mine at any time. `txHash` is the broadcast hash — check it on the
699
+ * explorer before re-running the sweep, and expect a re-run to find nothing
700
+ * stranded if it has since landed.
701
+ */
702
+ | 'unconfirmed';
656
703
  /** One transferred asset in a delegate sweep. */
657
704
  interface SweepEntry {
658
705
  /** 'USDC' or 'ETH' */
@@ -661,10 +708,24 @@ interface SweepEntry {
661
708
  amount: string;
662
709
  /** Atomic amount swept */
663
710
  amountAtomic: string;
664
- /** Transaction hash of the sweep transfer */
711
+ /**
712
+ * Transaction hash of the sweep transfer.
713
+ *
714
+ * The RECEIPT hash when `confirmation` is `confirmed`; the BROADCAST hash
715
+ * when it is `unconfirmed` — which is the whole reason the sweep returns
716
+ * instead of throwing on a deadline, since this hash is the only thing that
717
+ * lets a user recover the transfer by hand (#1756).
718
+ */
665
719
  txHash: string;
666
720
  /** Block explorer URL for the tx */
667
721
  explorerUrl: string;
722
+ /**
723
+ * Did this transfer confirm on-chain within the deadline? (#1756)
724
+ *
725
+ * `unconfirmed` entries have MOVED NOTHING YET and may still move. Do not
726
+ * report a sweep as complete without checking this on every entry.
727
+ */
728
+ confirmation: SweepConfirmation;
668
729
  }
669
730
  /** Result of a `sweepDelegate()` call. */
670
731
  interface SweepResult {
@@ -676,6 +737,16 @@ interface SweepResult {
676
737
  chainId: number;
677
738
  /** One entry per transferred asset. Empty when nothing was stranded. */
678
739
  transfers: SweepEntry[];
740
+ /**
741
+ * True when ANY entry is `unconfirmed` — i.e. the sweep broadcast something
742
+ * it could not confirm within the deadline (#1756).
743
+ *
744
+ * Derived from `transfers`, and present anyway because the consumer most
745
+ * likely to misread this result is an LLM reading the JSON of the
746
+ * `haven_sweep_delegate` tool, which will otherwise see a populated
747
+ * `transfers` array and report the money as recovered.
748
+ */
749
+ unconfirmed: boolean;
679
750
  }
680
751
  type PaymentStateKind = 'payment_intent' | 'approval_request';
681
752
  interface AgentPaymentEnumSchema {
@@ -2016,7 +2087,7 @@ declare const toolDescriptions: {
2016
2087
  readonly summary: "Sweep stranded USDC and/or ETH from the delegate wallet back to the originating Safe.";
2017
2088
  readonly selectionGuidance: string;
2018
2089
  readonly behavior: string;
2019
- readonly nextActionGuidance: "If transfers is non-empty, confirm the amounts with the user. No further action required — funds are on their way back to the Safe.";
2090
+ readonly nextActionGuidance: string;
2020
2091
  };
2021
2092
  readonly send: {
2022
2093
  readonly summary: "Send ETH or USDC directly from the agent's Haven wallet to a recipient address.";
@@ -2416,4 +2487,4 @@ declare function discoverMerchantMcpUrl(inputUrl: string): Promise<string | null
2416
2487
  /** Trailing-slash/percent-case echoes compare equal; unparseable never does. */
2417
2488
  declare function sameUrl(a: string, b: string): boolean;
2418
2489
 
2419
- export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentNextStep, type AgentPaymentEnumSchema, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type AgentPaymentSummary, type AgentPaymentWarning, AgentPaymentWarningCode, type AgentPurchaseSummary, type ClaudeTool, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, type HavenAgent, type HavenAgentAllowanceSummary, type HavenAgentReadiness, type HavenAgentSummary, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, type HavenCatalogEntry, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, type MachinePaymentRail, MerchantTimeoutError, type OpenAITool, type PaymentFee, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentReceipt, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type PostPurchaseAllowanceSummary, RECEIPT_VERSION, type ReceiptVerification, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, type SharedToolKey, type SignData, SignerRefusalCode, type SweepAuthorization, type SweepEip712Domain, type SweepEntry, type SweepExpectedAuth, type SweepPreparation, type SweepPrepareResponse, type SweepResult, type SweepSubmitResponse, type SweepSubmitResult, type SweepTypedData, TRANSFER_WITH_AUTHORIZATION_TYPES, type ToolDescription, type UnsupportedNodeVersionMessageOptions, X402AlreadySettledError, type X402AuthorizationOptions, type X402Erc7710Settlement, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402McpCallContext, type X402McpTransport, type X402MerchantCallContext, type X402PaymentHeaderContext, X402PaymentHeaderValidationError, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, type X402SchemeSelection, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
2490
+ export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentNextStep, type AgentPaymentEnumSchema, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type AgentPaymentSummary, type AgentPaymentWarning, AgentPaymentWarningCode, type AgentPurchaseSummary, type ClaudeTool, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, type HavenAgent, type HavenAgentAllowanceSummary, type HavenAgentReadiness, type HavenAgentSummary, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, type HavenCatalogEntry, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, type MachinePaymentRail, MerchantTimeoutError, type OpenAITool, type PaymentFee, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentReceipt, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type PostPurchaseAllowanceSummary, RECEIPT_VERSION, type ReceiptVerification, type ResumeAuthorizedX402Input, type ResumeX402PaymentInput, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, type SharedToolKey, type SignData, SignerRefusalCode, type SweepAuthorization, type SweepConfirmation, type SweepEip712Domain, type SweepEntry, type SweepExpectedAuth, type SweepPreparation, type SweepPrepareResponse, type SweepResult, type SweepSubmitResponse, type SweepSubmitResult, type SweepTypedData, TRANSFER_WITH_AUTHORIZATION_TYPES, type ToolDescription, type UnsupportedNodeVersionMessageOptions, X402AlreadySettledError, type X402AuthorizationOptions, type X402Erc7710Settlement, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402McpCallContext, type X402McpTransport, type X402MerchantCallContext, type X402PaymentHeaderContext, X402PaymentHeaderValidationError, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, type X402SchemeSelection, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { privateKeyToAccount } from 'viem/accounts';
8
8
  // src/client.ts
9
9
 
10
10
  // src/types.ts
11
+ var DEFAULT_CONFIRMATION_TIMEOUT_MS = 9e4;
11
12
  var AgentPaymentPhase = {
12
13
  /** The agent must sign and submit the prepared payment before Haven can relay it. */
13
14
  AgentSignatureRequired: "agent_signature_required",
@@ -759,7 +760,7 @@ function x402AuthorizationAmount(option) {
759
760
  return amount;
760
761
  }
761
762
  function buildX402ExpectedMessage(context) {
762
- const version = context.typedDataHash ? 2 : 1;
763
+ const version = context.payerDelegate ? 3 : context.typedDataHash ? 2 : 1;
763
764
  const payload = {
764
765
  version,
765
766
  kind: "haven.x402.expected",
@@ -777,6 +778,12 @@ function buildX402ExpectedMessage(context) {
777
778
  if (context.typedDataHash) {
778
779
  payload.typedDataHash = context.typedDataHash.toLowerCase();
779
780
  }
781
+ if (context.payerDelegate) {
782
+ payload.payerDelegate = context.payerDelegate.toLowerCase();
783
+ if (context.payerAgentId) {
784
+ payload.payerAgentId = context.payerAgentId;
785
+ }
786
+ }
780
787
  return `Haven x402 expected context v${version}
781
788
  ${stableStringify2(payload)}`;
782
789
  }
@@ -1625,6 +1632,20 @@ function createErc20Contract(address, abi, runner) {
1625
1632
  }
1626
1633
 
1627
1634
  // src/delegate-sweep.ts
1635
+ function isWaitTimeout(err) {
1636
+ return err?.code === "TIMEOUT";
1637
+ }
1638
+ async function waitForSweepTx(tx) {
1639
+ let receipt;
1640
+ try {
1641
+ receipt = await tx.wait(1, DEFAULT_CONFIRMATION_TIMEOUT_MS);
1642
+ } catch (err) {
1643
+ if (!isWaitTimeout(err)) throw err;
1644
+ return { txHash: tx.hash, confirmation: "unconfirmed" };
1645
+ }
1646
+ if (!receipt) return { txHash: tx.hash, confirmation: "unconfirmed" };
1647
+ return { txHash: receipt.hash, confirmation: "confirmed" };
1648
+ }
1628
1649
  var DelegateSweepApi = class {
1629
1650
  constructor(options) {
1630
1651
  this.options = options;
@@ -1644,9 +1665,8 @@ var DelegateSweepApi = class {
1644
1665
  const balance2 = await contract.balanceOf(agent.delegateAddress);
1645
1666
  if (balance2 > 0n) {
1646
1667
  const tx = await contract.transfer(agent.safeAddress, balance2);
1647
- const receipt = await tx.wait(1);
1648
- const txHash = receipt?.hash ?? tx.hash;
1649
- transfers.push({ asset: "USDC", amount: format(balance2, 6), amountAtomic: balance2.toString(), txHash, explorerUrl: this.options.buildExplorerUrl(agent.chainId, txHash) });
1668
+ const { txHash, confirmation } = await waitForSweepTx(tx);
1669
+ transfers.push({ asset: "USDC", amount: format(balance2, 6), amountAtomic: balance2.toString(), txHash, explorerUrl: this.options.buildExplorerUrl(agent.chainId, txHash), confirmation });
1650
1670
  }
1651
1671
  }
1652
1672
  const balance = await provider.getBalance(agent.delegateAddress);
@@ -1655,12 +1675,11 @@ var DelegateSweepApi = class {
1655
1675
  const send = balance - (fee.maxFeePerGas ?? fee.gasPrice ?? 1000000n) * 21000n * 2n;
1656
1676
  if (send > 0n) {
1657
1677
  const tx = await wallet.sendTransaction({ to: agent.safeAddress, value: send });
1658
- const receipt = await tx.wait(1);
1659
- const txHash = receipt?.hash ?? tx.hash;
1660
- transfers.push({ asset: "ETH", amount: format(send, 18), amountAtomic: send.toString(), txHash, explorerUrl: this.options.buildExplorerUrl(agent.chainId, txHash) });
1678
+ const { txHash, confirmation } = await waitForSweepTx(tx);
1679
+ transfers.push({ asset: "ETH", amount: format(send, 18), amountAtomic: send.toString(), txHash, explorerUrl: this.options.buildExplorerUrl(agent.chainId, txHash), confirmation });
1661
1680
  }
1662
1681
  }
1663
- return { fromAddress: agent.delegateAddress, toAddress: agent.safeAddress, chainId: agent.chainId, transfers };
1682
+ return { fromAddress: agent.delegateAddress, toAddress: agent.safeAddress, chainId: agent.chainId, transfers, unconfirmed: transfers.some((t) => t.confirmation === "unconfirmed") };
1664
1683
  }
1665
1684
  prepareSweep() {
1666
1685
  return this.options.transport.post("/machine-payments/sweep/prepare", {});
@@ -2637,7 +2656,6 @@ function parseProtocolReceiptHeader(value) {
2637
2656
  }
2638
2657
 
2639
2658
  // src/client.ts
2640
- var DEFAULT_CONFIRMATION_TIMEOUT = 9e4;
2641
2659
  var DEFAULT_POLLING_INTERVAL = 3e3;
2642
2660
  function x402TypedDataDigest(typedData) {
2643
2661
  if (!typedData || typeof typedData !== "object") return void 0;
@@ -2712,7 +2730,7 @@ var HavenClient = class {
2712
2730
  });
2713
2731
  this.x402Wallet = config.x402Wallet;
2714
2732
  this.merchantTransport = new McpMerchantTransport({ merchantTimeout: config.merchantTimeout });
2715
- this.confirmationTimeout = config.confirmationTimeout ?? DEFAULT_CONFIRMATION_TIMEOUT;
2733
+ this.confirmationTimeout = config.confirmationTimeout ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
2716
2734
  this.pollingInterval = config.pollingInterval ?? DEFAULT_POLLING_INTERVAL;
2717
2735
  this.chainRpcs = config.chainRpcs ?? {};
2718
2736
  if (this.delegateKey) {
@@ -2883,6 +2901,8 @@ var HavenClient = class {
2883
2901
  asset: option.asset,
2884
2902
  network: option.network,
2885
2903
  expectedAuth: raw.x402_expected_auth,
2904
+ payerDelegate: raw.payer_delegate,
2905
+ payerAgentId: raw.payer_agent_id,
2886
2906
  // #1138: the digest the delegation-rail expected context commits to.
2887
2907
  // Re-derived locally, exactly like every other context field the edge
2888
2908
  // signer is handed (amount, merchantTo, …) — none of them are trusted
@@ -3777,8 +3797,8 @@ var toolDescriptions = {
3777
3797
  sweep_delegate: {
3778
3798
  summary: "Sweep stranded USDC and/or ETH from the delegate wallet back to the originating Safe.",
3779
3799
  selectionGuidance: "Use this when the user instructs you to recover stranded funds on the delegate wallet, or when a payment status returns nextAction=sweep_stranded_funds. Do NOT use for normal payments \u2014 use haven_pay_x402. Do NOT use to read balances only \u2014 use haven_get_allowances.",
3780
- behavior: "Reads the delegate EOA's on-chain USDC and ETH balances. For each non-zero balance, signs and submits a transfer from the delegate EOA to the originating Safe (hardcoded destination). The delegate key signs locally \u2014 Haven never sees it and the backend never constructs signed transactions (CASP/MiCA Red Line #2). Returns tx hashes and recovered amounts. Returns an empty transfers list when nothing is stranded.",
3781
- nextActionGuidance: "If transfers is non-empty, confirm the amounts with the user. No further action required \u2014 funds are on their way back to the Safe."
3800
+ behavior: `Reads the delegate EOA's on-chain USDC and ETH balances. For each non-zero balance, signs and submits a transfer from the delegate EOA to the originating Safe (hardcoded destination). The delegate key signs locally \u2014 Haven never sees it and the backend never constructs signed transactions (CASP/MiCA Red Line #2). Returns tx hashes and recovered amounts. Returns an empty transfers list when nothing is stranded. Each transfer carries confirmation: "confirmed" (a receipt was seen \u2014 the funds are in the Safe) or "unconfirmed" (broadcast but not confirmed within 90 seconds \u2014 still in the mempool, may still land). The top-level unconfirmed flag is true when any transfer is unconfirmed.`,
3801
+ nextActionGuidance: 'If transfers is non-empty, confirm the amounts with the user. Report a transfer as recovered ONLY when its confirmation is "confirmed". For an "unconfirmed" transfer, tell the user it was submitted but not yet confirmed, give them its txHash and explorerUrl to check, and do not re-run the sweep immediately \u2014 a re-run after it lands will simply find nothing stranded.'
3782
3802
  },
3783
3803
  send: {
3784
3804
  summary: "Send ETH or USDC directly from the agent's Haven wallet to a recipient address.",
@@ -4290,6 +4310,6 @@ function sameUrl(a, b) {
4290
4310
  }
4291
4311
  }
4292
4312
 
4293
- export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, HavenApiError, HavenClient, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, MerchantTimeoutError, RECEIPT_VERSION, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, SignerRefusalCode, TRANSFER_WITH_AUTHORIZATION_TYPES, X402AlreadySettledError, X402PaymentHeaderValidationError, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
4313
+ export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, HavenApiError, HavenClient, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, MerchantTimeoutError, RECEIPT_VERSION, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, SignerRefusalCode, TRANSFER_WITH_AUTHORIZATION_TYPES, X402AlreadySettledError, X402PaymentHeaderValidationError, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isErc7710Option, isSupportedNodeVersion, isSweepableChain, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses };
4294
4314
  //# sourceMappingURL=index.js.map
4295
4315
  //# sourceMappingURL=index.js.map