@haven_ai/sdk 0.0.0-dev.202609231741.b88d644 → 0.0.0-dev.202609241737.2d2b91b
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 +8 -2
- package/dist/{base64-CNakwKE8.d.cts → base64-fVc9Cnn-.d.cts} +64 -1
- package/dist/{base64-CNakwKE8.d.ts → base64-fVc9Cnn-.d.ts} +64 -1
- package/dist/{chunk-AS6BCA42.cjs → chunk-CSWZXQ2L.cjs} +143 -3
- package/dist/chunk-CSWZXQ2L.cjs.map +1 -0
- package/dist/{chunk-7FXW3IKZ.js → chunk-YGSM2WRP.js} +135 -4
- package/dist/chunk-YGSM2WRP.js.map +1 -0
- package/dist/edge.cjs +50 -26
- package/dist/edge.d.cts +2 -1
- package/dist/edge.d.ts +2 -1
- package/dist/edge.js +2 -2
- package/dist/index.cjs +287 -249
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/chunk-7FXW3IKZ.js.map +0 -1
- package/dist/chunk-AS6BCA42.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -112,8 +112,14 @@ const intent = await haven.createIntent({
|
|
|
112
112
|
to: '0xabc...',
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
// Step 2: Sign the
|
|
116
|
-
|
|
115
|
+
// Step 2: Sign externally. On the delegation rail (the only rail that pays)
|
|
116
|
+
// the account validates the EIP-712 typed data in intent.signData.typed_data,
|
|
117
|
+
// never the bare hash — a signature over signData.hash is rejected on-chain
|
|
118
|
+
// (AA24). Sign that typed data with your delegate key (viem signTypedData),
|
|
119
|
+
// after checking it with assertUserOpTypedDataBinding(typed_data, hash).
|
|
120
|
+
// There is no public HavenClient method for this step yet; pay() does it
|
|
121
|
+
// for you.
|
|
122
|
+
const signature = await signTypedDataWithYourDelegateKey(intent.signData.typed_data)
|
|
117
123
|
|
|
118
124
|
// Step 3: Submit the signature
|
|
119
125
|
await haven.submitSignature(intent.paymentId, signature)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PaymentRequirements } from 'x402/types';
|
|
2
|
+
import { Hex } from 'viem';
|
|
2
3
|
|
|
3
4
|
interface HavenClientConfig {
|
|
4
5
|
/** Haven API key (sk_agent_xxx) */
|
|
@@ -2309,6 +2310,68 @@ declare function resolveTokenFromAddress(address: string, network?: string): {
|
|
|
2309
2310
|
decimals: number;
|
|
2310
2311
|
} | null;
|
|
2311
2312
|
|
|
2313
|
+
/**
|
|
2314
|
+
* #3271: the integrity check every client runs before signing a direct
|
|
2315
|
+
* delegation-rail payment's typed data.
|
|
2316
|
+
*
|
|
2317
|
+
* A direct payment (`POST /payments`, surfaced as `haven_send` / `haven_pay`)
|
|
2318
|
+
* is signed as the HybridDeleGator's EIP-712 `PackedUserOperation`, and Haven
|
|
2319
|
+
* returns two things for it: that typed data, and `payload_hash` — the
|
|
2320
|
+
* ERC-4337 v0.7 UserOperation hash of the same operation. Nothing used to tie
|
|
2321
|
+
* the two together at signing time. The typed data is multi-KB and reaches the
|
|
2322
|
+
* signer through a language model when it is relayed by hand, so one corrupted
|
|
2323
|
+
* character produced a valid-looking signature over the wrong digest, and the
|
|
2324
|
+
* first sign of it was `AA24 signature error` from the bundler (#3271,
|
|
2325
|
+
* reproduced on dev 2026-09-24).
|
|
2326
|
+
*
|
|
2327
|
+
* This recomputes the v0.7 hash from the typed data's own message and domain
|
|
2328
|
+
* and refuses unless it equals `payload_hash`, and it pins the parts of the
|
|
2329
|
+
* typed data the hash does NOT cover (domain name/version/verifyingContract,
|
|
2330
|
+
* the field list, the EntryPoint). It is a CORRUPTION check: the caller supplies
|
|
2331
|
+
* both values, so it proves they describe the same operation, never that Haven
|
|
2332
|
+
* prepared it. Provenance is the byte-free sign context (`payment_id`); what the
|
|
2333
|
+
* signer will sign at all is #3272.
|
|
2334
|
+
*
|
|
2335
|
+
* Pure viem, no ethers: `@haven_ai/sdk/edge` re-exports it for the edge signer,
|
|
2336
|
+
* and `edge-imports.test.ts` pins that graph.
|
|
2337
|
+
*/
|
|
2338
|
+
/** Version of the direct-payment sign context (`GET /payments/:id/sign-context`). */
|
|
2339
|
+
declare const DIRECT_SIGN_CONTEXT_VERSION = 1;
|
|
2340
|
+
/** The ERC-4337 v0.7 EntryPoint — the only one the delegation rail submits to. */
|
|
2341
|
+
declare const ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
2342
|
+
/**
|
|
2343
|
+
* The HybridDeleGator EIP-712 domain constants and the `PackedUserOperation`
|
|
2344
|
+
* field list, vendored from `@metamask/smart-accounts-kit`
|
|
2345
|
+
* (`contracts.HybridDeleGator.constants`, `SIGNABLE_USER_OP_TYPED_DATA`) so the
|
|
2346
|
+
* published packages need no runtime dependency on the kit. Pinned equal to the
|
|
2347
|
+
* kit's values by `userop-binding.test.ts`.
|
|
2348
|
+
*/
|
|
2349
|
+
declare const HYBRID_DELEGATOR_DOMAIN_NAME = "HybridDeleGator";
|
|
2350
|
+
declare const HYBRID_DELEGATOR_DOMAIN_VERSION = "1";
|
|
2351
|
+
declare const PACKED_USER_OPERATION_FIELDS: ReadonlyArray<{
|
|
2352
|
+
name: string;
|
|
2353
|
+
type: string;
|
|
2354
|
+
}>;
|
|
2355
|
+
/** Refusal raised when UserOperation typed data (a direct payment, or the SDK's x402 funding leg) does not match its `payload_hash`. */
|
|
2356
|
+
declare class HavenUserOpBindingError extends HavenError {
|
|
2357
|
+
constructor(message: string);
|
|
2358
|
+
}
|
|
2359
|
+
/** True when the typed data is a `PackedUserOperation` (the direct-payment shape). */
|
|
2360
|
+
declare function isPackedUserOperationTypedData(value: unknown): boolean;
|
|
2361
|
+
/**
|
|
2362
|
+
* Compute the ERC-4337 v0.7 UserOperation hash from a HybridDeleGator
|
|
2363
|
+
* `PackedUserOperation` typed-data object — the value Haven returns as
|
|
2364
|
+
* `payload_hash` for a direct payment (`getUserOperationHash`, entryPoint 0.7).
|
|
2365
|
+
*/
|
|
2366
|
+
declare function packedUserOperationHash(typedData: unknown): Hex;
|
|
2367
|
+
/**
|
|
2368
|
+
* Refuse (throw `HavenUserOpBindingError`) unless this `PackedUserOperation`
|
|
2369
|
+
* typed data is the operation `payloadHash` names, in the HybridDeleGator
|
|
2370
|
+
* domain of its own sender, against the v0.7 EntryPoint. Returns the
|
|
2371
|
+
* recomputed hash.
|
|
2372
|
+
*/
|
|
2373
|
+
declare function assertUserOpTypedDataBinding(typedData: unknown, payloadHash: string): Hex;
|
|
2374
|
+
|
|
2312
2375
|
/**
|
|
2313
2376
|
* Runtime-agnostic base64 helpers — the single source of truth for the wire
|
|
2314
2377
|
* encoding shared by the SDK and the edge signer (#325).
|
|
@@ -2347,4 +2410,4 @@ declare function encodeBase64Json(value: unknown): string;
|
|
|
2347
2410
|
*/
|
|
2348
2411
|
declare function decodeBase64Json<T>(value: string, label?: string): T;
|
|
2349
2412
|
|
|
2350
|
-
export { type AgentPaymentSummary as $, type AgentPaymentWarning as A, type X402McpTransport as B, type X402MerchantCallContext as C, HavenError as D, AGENT_PAYMENT_FAILURE_CODE_VALUES as E, AGENT_PAYMENT_NEXT_ACTION_VALUES as F, AGENT_PAYMENT_PHASE_VALUES as G, type HavenClientConfig as H, AGENT_PAYMENT_RAIL_VALUES as I, type AgentNextStep as J, type AgentPaymentEnumSchema as K, AgentPaymentFailureCode as L, AgentPaymentFailureCodeDescriptions as M, AgentPaymentFailureCodeSchema as N, AgentPaymentNextAction as O, type PaymentRequest as P, AgentPaymentNextActionDescriptions as Q, type RawPaymentParties as R, type SweepResult as S, AgentPaymentNextActionSchema as T, AgentPaymentPhase as U, AgentPaymentPhaseDescriptions as V, AgentPaymentPhaseSchema as W, type X402PaymentRequired as X, AgentPaymentRail as Y, AgentPaymentRailDescriptions as Z, AgentPaymentRailSchema as _, type PaymentResult as a,
|
|
2413
|
+
export { type AgentPaymentSummary as $, type AgentPaymentWarning as A, type X402McpTransport as B, type X402MerchantCallContext as C, HavenError as D, AGENT_PAYMENT_FAILURE_CODE_VALUES as E, AGENT_PAYMENT_NEXT_ACTION_VALUES as F, AGENT_PAYMENT_PHASE_VALUES as G, type HavenClientConfig as H, AGENT_PAYMENT_RAIL_VALUES as I, type AgentNextStep as J, type AgentPaymentEnumSchema as K, AgentPaymentFailureCode as L, AgentPaymentFailureCodeDescriptions as M, AgentPaymentFailureCodeSchema as N, AgentPaymentNextAction as O, type PaymentRequest as P, AgentPaymentNextActionDescriptions as Q, type RawPaymentParties as R, type SweepResult as S, AgentPaymentNextActionSchema as T, AgentPaymentPhase as U, AgentPaymentPhaseDescriptions as V, AgentPaymentPhaseSchema as W, type X402PaymentRequired as X, AgentPaymentRail as Y, AgentPaymentRailDescriptions as Z, AgentPaymentRailSchema as _, type PaymentResult as a, type X402SchemeSelection as a$, AgentPaymentWarningCode as a0, type AgentPurchaseSummary as a1, CONNECTOR_PACKAGE_NAME as a2, type CatalogSubmissionAccepted as a3, DEFAULT_CONFIRMATION_TIMEOUT_MS as a4, DEFAULT_NEXT_TOOL_BY_ACTION as a5, DIRECT_SIGN_CONTEXT_VERSION as a6, ENTRY_POINT_V07 as a7, ERC7710_ASSET_TRANSFER_METHOD as a8, HAVEN_CONNECTOR_CHANNEL as a9, PACKED_USER_OPERATION_FIELDS as aA, type PaymentFee as aB, type PaymentNextAction as aC, type PaymentPhase as aD, type PaymentStatus as aE, SIGNER_UPDATE_FALLBACK as aF, SWEEP_BASE_CHAIN_ID as aG, SWEEP_BASE_SEPOLIA_CHAIN_ID as aH, SWEEP_BASE_SEPOLIA_USDC_ADDRESS as aI, SWEEP_BASE_USDC_ADDRESS as aJ, SignerRefusalCode as aK, type SweepConfirmation as aL, type SweepEip712Domain as aM, type SweepEntry as aN, type SweepExpectedAuth as aO, type SweepPreparation as aP, type SweepSubmitResult as aQ, type SweepTypedData as aR, TRANSFER_WITH_AUTHORIZATION_TYPES as aS, type UnsupportedNodeVersionMessageOptions as aT, X402AlreadySettledError as aU, type X402ExpectedAuth as aV, type X402ExpectedContext as aW, type X402PaymentHeaderContext as aX, X402PaymentHeaderValidationError as aY, type X402PaymentOption as aZ, type X402RequestSnapshot as a_, HAVEN_MINIMUM_NODE_VERSION as aa, HYBRID_DELEGATOR_DOMAIN_NAME as ab, HYBRID_DELEGATOR_DOMAIN_VERSION as ac, type HavenAgentAllowanceSummary as ad, type HavenAgentReadiness as ae, type HavenAllowance as af, HavenApiError as ag, type HavenCatalogMerchant as ah, type HavenListScope as ai, HavenPaymentStateError as aj, HavenSigningError as ak, HavenTimeoutError as al, HavenUnsupportedSignerVersionError as am, HavenUserOpBindingError as an, HavenZeroSettlementHashError as ao, type MachinePaymentRail as ap, MerchantTimeoutError as aq, NEXT_TOOL_SERVER_NAMES as ar, NEXT_TOOL_SERVER_ROLES as as, type NextStep as at, type NextStepArguments as au, type NextStepHandoff as av, type NextStepInput as aw, type NextStepTarget as ax, type NextStepTargets as ay, type NextToolServerRole as az, type PaymentIntent as b, X402UnexpectedStatusError as b0, X402_LEGACY_PAYMENT_HEADER_NAME as b1, X402_MAX_AUTHORIZATION_WINDOW_SECONDS as b2, X402_PAYMENT_HEADER_NAME as b3, X402_PAYMENT_HEADER_NAMES_SENT as b4, X402_PAYMENT_REQUIRED_HEADER_NAME as b5, X402_PAYMENT_RESPONSE_HEADER_NAME as b6, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS as b7, assertUserOpTypedDataBinding as b8, buildSweepAuthorizationMessage as b9, selectPaymentOption as bA, selectStandardPaymentOption as bB, selectX402SettlementScheme as bC, signerUpdateFallback as bD, sweepUsdcAddress as bE, sweepUsdcDomain as bF, toStandardPaymentRequirements as bG, unsupportedNodeVersionMessage as bH, validateStandardX402PaymentHeader as bI, x402AssetTransferMethod as bJ, x402AuthorizationAmount as bK, x402FacilitatorAddresses as bL, x402V2PaymentEnvelope as bM, buildSweepTypedData as ba, buildX402ExpectedMessage as bb, compareNodeVersions as bc, connectorRerunCommand as bd, connectorSpec as be, createNextStepBuilder as bf, decodeBase64Json as bg, decodeBase64Utf8 as bh, defaultNextToolFor as bi, encodeBase64Json as bj, encodeBase64Utf8 as bk, encodePaymentProof as bl, isConnectorChannel as bm, isErc7710Option as bn, isPackedUserOperationTypedData as bo, isSupportedNodeVersion as bp, isSweepableChain as bq, normalizePaymentRequired as br, packedUserOperationHash as bs, parseNextTool as bt, parsePaymentRequired as bu, parsePaymentRequiredResponse as bv, renderNextTool as bw, resolveConnectorChannel as bx, resolveTokenFromAddress as by, selectErc7710PaymentOption as bz, type X402AuthorizationOptions as c, type X402Intent as d, type PaymentStatusResult as e, type HavenAgent as f, type HavenAgentSummary as g, type SweepPrepareResponse as h, type SweepAuthorization as i, type SweepSubmitResponse as j, type HavenAllowanceSummary as k, type HavenBalanceCoverage as l, type PostPurchaseAllowanceSummary as m, type HavenCatalogEntry as n, type HavenCatalogSubmission as o, type HavenPaymentReceipt as p, type HavenPaymentReceiptsPage as q, type PaymentResumeState as r, type X402Receipt as s, type X402Quote as t, type X402Erc7710Settlement as u, type X402McpCallContext as v, type SignData as w, type ResumeAuthorizedX402Input as x, type ResumeX402PaymentInput as y, type X402ResumeState as z };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PaymentRequirements } from 'x402/types';
|
|
2
|
+
import { Hex } from 'viem';
|
|
2
3
|
|
|
3
4
|
interface HavenClientConfig {
|
|
4
5
|
/** Haven API key (sk_agent_xxx) */
|
|
@@ -2309,6 +2310,68 @@ declare function resolveTokenFromAddress(address: string, network?: string): {
|
|
|
2309
2310
|
decimals: number;
|
|
2310
2311
|
} | null;
|
|
2311
2312
|
|
|
2313
|
+
/**
|
|
2314
|
+
* #3271: the integrity check every client runs before signing a direct
|
|
2315
|
+
* delegation-rail payment's typed data.
|
|
2316
|
+
*
|
|
2317
|
+
* A direct payment (`POST /payments`, surfaced as `haven_send` / `haven_pay`)
|
|
2318
|
+
* is signed as the HybridDeleGator's EIP-712 `PackedUserOperation`, and Haven
|
|
2319
|
+
* returns two things for it: that typed data, and `payload_hash` — the
|
|
2320
|
+
* ERC-4337 v0.7 UserOperation hash of the same operation. Nothing used to tie
|
|
2321
|
+
* the two together at signing time. The typed data is multi-KB and reaches the
|
|
2322
|
+
* signer through a language model when it is relayed by hand, so one corrupted
|
|
2323
|
+
* character produced a valid-looking signature over the wrong digest, and the
|
|
2324
|
+
* first sign of it was `AA24 signature error` from the bundler (#3271,
|
|
2325
|
+
* reproduced on dev 2026-09-24).
|
|
2326
|
+
*
|
|
2327
|
+
* This recomputes the v0.7 hash from the typed data's own message and domain
|
|
2328
|
+
* and refuses unless it equals `payload_hash`, and it pins the parts of the
|
|
2329
|
+
* typed data the hash does NOT cover (domain name/version/verifyingContract,
|
|
2330
|
+
* the field list, the EntryPoint). It is a CORRUPTION check: the caller supplies
|
|
2331
|
+
* both values, so it proves they describe the same operation, never that Haven
|
|
2332
|
+
* prepared it. Provenance is the byte-free sign context (`payment_id`); what the
|
|
2333
|
+
* signer will sign at all is #3272.
|
|
2334
|
+
*
|
|
2335
|
+
* Pure viem, no ethers: `@haven_ai/sdk/edge` re-exports it for the edge signer,
|
|
2336
|
+
* and `edge-imports.test.ts` pins that graph.
|
|
2337
|
+
*/
|
|
2338
|
+
/** Version of the direct-payment sign context (`GET /payments/:id/sign-context`). */
|
|
2339
|
+
declare const DIRECT_SIGN_CONTEXT_VERSION = 1;
|
|
2340
|
+
/** The ERC-4337 v0.7 EntryPoint — the only one the delegation rail submits to. */
|
|
2341
|
+
declare const ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
2342
|
+
/**
|
|
2343
|
+
* The HybridDeleGator EIP-712 domain constants and the `PackedUserOperation`
|
|
2344
|
+
* field list, vendored from `@metamask/smart-accounts-kit`
|
|
2345
|
+
* (`contracts.HybridDeleGator.constants`, `SIGNABLE_USER_OP_TYPED_DATA`) so the
|
|
2346
|
+
* published packages need no runtime dependency on the kit. Pinned equal to the
|
|
2347
|
+
* kit's values by `userop-binding.test.ts`.
|
|
2348
|
+
*/
|
|
2349
|
+
declare const HYBRID_DELEGATOR_DOMAIN_NAME = "HybridDeleGator";
|
|
2350
|
+
declare const HYBRID_DELEGATOR_DOMAIN_VERSION = "1";
|
|
2351
|
+
declare const PACKED_USER_OPERATION_FIELDS: ReadonlyArray<{
|
|
2352
|
+
name: string;
|
|
2353
|
+
type: string;
|
|
2354
|
+
}>;
|
|
2355
|
+
/** Refusal raised when UserOperation typed data (a direct payment, or the SDK's x402 funding leg) does not match its `payload_hash`. */
|
|
2356
|
+
declare class HavenUserOpBindingError extends HavenError {
|
|
2357
|
+
constructor(message: string);
|
|
2358
|
+
}
|
|
2359
|
+
/** True when the typed data is a `PackedUserOperation` (the direct-payment shape). */
|
|
2360
|
+
declare function isPackedUserOperationTypedData(value: unknown): boolean;
|
|
2361
|
+
/**
|
|
2362
|
+
* Compute the ERC-4337 v0.7 UserOperation hash from a HybridDeleGator
|
|
2363
|
+
* `PackedUserOperation` typed-data object — the value Haven returns as
|
|
2364
|
+
* `payload_hash` for a direct payment (`getUserOperationHash`, entryPoint 0.7).
|
|
2365
|
+
*/
|
|
2366
|
+
declare function packedUserOperationHash(typedData: unknown): Hex;
|
|
2367
|
+
/**
|
|
2368
|
+
* Refuse (throw `HavenUserOpBindingError`) unless this `PackedUserOperation`
|
|
2369
|
+
* typed data is the operation `payloadHash` names, in the HybridDeleGator
|
|
2370
|
+
* domain of its own sender, against the v0.7 EntryPoint. Returns the
|
|
2371
|
+
* recomputed hash.
|
|
2372
|
+
*/
|
|
2373
|
+
declare function assertUserOpTypedDataBinding(typedData: unknown, payloadHash: string): Hex;
|
|
2374
|
+
|
|
2312
2375
|
/**
|
|
2313
2376
|
* Runtime-agnostic base64 helpers — the single source of truth for the wire
|
|
2314
2377
|
* encoding shared by the SDK and the edge signer (#325).
|
|
@@ -2347,4 +2410,4 @@ declare function encodeBase64Json(value: unknown): string;
|
|
|
2347
2410
|
*/
|
|
2348
2411
|
declare function decodeBase64Json<T>(value: string, label?: string): T;
|
|
2349
2412
|
|
|
2350
|
-
export { type AgentPaymentSummary as $, type AgentPaymentWarning as A, type X402McpTransport as B, type X402MerchantCallContext as C, HavenError as D, AGENT_PAYMENT_FAILURE_CODE_VALUES as E, AGENT_PAYMENT_NEXT_ACTION_VALUES as F, AGENT_PAYMENT_PHASE_VALUES as G, type HavenClientConfig as H, AGENT_PAYMENT_RAIL_VALUES as I, type AgentNextStep as J, type AgentPaymentEnumSchema as K, AgentPaymentFailureCode as L, AgentPaymentFailureCodeDescriptions as M, AgentPaymentFailureCodeSchema as N, AgentPaymentNextAction as O, type PaymentRequest as P, AgentPaymentNextActionDescriptions as Q, type RawPaymentParties as R, type SweepResult as S, AgentPaymentNextActionSchema as T, AgentPaymentPhase as U, AgentPaymentPhaseDescriptions as V, AgentPaymentPhaseSchema as W, type X402PaymentRequired as X, AgentPaymentRail as Y, AgentPaymentRailDescriptions as Z, AgentPaymentRailSchema as _, type PaymentResult as a,
|
|
2413
|
+
export { type AgentPaymentSummary as $, type AgentPaymentWarning as A, type X402McpTransport as B, type X402MerchantCallContext as C, HavenError as D, AGENT_PAYMENT_FAILURE_CODE_VALUES as E, AGENT_PAYMENT_NEXT_ACTION_VALUES as F, AGENT_PAYMENT_PHASE_VALUES as G, type HavenClientConfig as H, AGENT_PAYMENT_RAIL_VALUES as I, type AgentNextStep as J, type AgentPaymentEnumSchema as K, AgentPaymentFailureCode as L, AgentPaymentFailureCodeDescriptions as M, AgentPaymentFailureCodeSchema as N, AgentPaymentNextAction as O, type PaymentRequest as P, AgentPaymentNextActionDescriptions as Q, type RawPaymentParties as R, type SweepResult as S, AgentPaymentNextActionSchema as T, AgentPaymentPhase as U, AgentPaymentPhaseDescriptions as V, AgentPaymentPhaseSchema as W, type X402PaymentRequired as X, AgentPaymentRail as Y, AgentPaymentRailDescriptions as Z, AgentPaymentRailSchema as _, type PaymentResult as a, type X402SchemeSelection as a$, AgentPaymentWarningCode as a0, type AgentPurchaseSummary as a1, CONNECTOR_PACKAGE_NAME as a2, type CatalogSubmissionAccepted as a3, DEFAULT_CONFIRMATION_TIMEOUT_MS as a4, DEFAULT_NEXT_TOOL_BY_ACTION as a5, DIRECT_SIGN_CONTEXT_VERSION as a6, ENTRY_POINT_V07 as a7, ERC7710_ASSET_TRANSFER_METHOD as a8, HAVEN_CONNECTOR_CHANNEL as a9, PACKED_USER_OPERATION_FIELDS as aA, type PaymentFee as aB, type PaymentNextAction as aC, type PaymentPhase as aD, type PaymentStatus as aE, SIGNER_UPDATE_FALLBACK as aF, SWEEP_BASE_CHAIN_ID as aG, SWEEP_BASE_SEPOLIA_CHAIN_ID as aH, SWEEP_BASE_SEPOLIA_USDC_ADDRESS as aI, SWEEP_BASE_USDC_ADDRESS as aJ, SignerRefusalCode as aK, type SweepConfirmation as aL, type SweepEip712Domain as aM, type SweepEntry as aN, type SweepExpectedAuth as aO, type SweepPreparation as aP, type SweepSubmitResult as aQ, type SweepTypedData as aR, TRANSFER_WITH_AUTHORIZATION_TYPES as aS, type UnsupportedNodeVersionMessageOptions as aT, X402AlreadySettledError as aU, type X402ExpectedAuth as aV, type X402ExpectedContext as aW, type X402PaymentHeaderContext as aX, X402PaymentHeaderValidationError as aY, type X402PaymentOption as aZ, type X402RequestSnapshot as a_, HAVEN_MINIMUM_NODE_VERSION as aa, HYBRID_DELEGATOR_DOMAIN_NAME as ab, HYBRID_DELEGATOR_DOMAIN_VERSION as ac, type HavenAgentAllowanceSummary as ad, type HavenAgentReadiness as ae, type HavenAllowance as af, HavenApiError as ag, type HavenCatalogMerchant as ah, type HavenListScope as ai, HavenPaymentStateError as aj, HavenSigningError as ak, HavenTimeoutError as al, HavenUnsupportedSignerVersionError as am, HavenUserOpBindingError as an, HavenZeroSettlementHashError as ao, type MachinePaymentRail as ap, MerchantTimeoutError as aq, NEXT_TOOL_SERVER_NAMES as ar, NEXT_TOOL_SERVER_ROLES as as, type NextStep as at, type NextStepArguments as au, type NextStepHandoff as av, type NextStepInput as aw, type NextStepTarget as ax, type NextStepTargets as ay, type NextToolServerRole as az, type PaymentIntent as b, X402UnexpectedStatusError as b0, X402_LEGACY_PAYMENT_HEADER_NAME as b1, X402_MAX_AUTHORIZATION_WINDOW_SECONDS as b2, X402_PAYMENT_HEADER_NAME as b3, X402_PAYMENT_HEADER_NAMES_SENT as b4, X402_PAYMENT_REQUIRED_HEADER_NAME as b5, X402_PAYMENT_RESPONSE_HEADER_NAME as b6, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS as b7, assertUserOpTypedDataBinding as b8, buildSweepAuthorizationMessage as b9, selectPaymentOption as bA, selectStandardPaymentOption as bB, selectX402SettlementScheme as bC, signerUpdateFallback as bD, sweepUsdcAddress as bE, sweepUsdcDomain as bF, toStandardPaymentRequirements as bG, unsupportedNodeVersionMessage as bH, validateStandardX402PaymentHeader as bI, x402AssetTransferMethod as bJ, x402AuthorizationAmount as bK, x402FacilitatorAddresses as bL, x402V2PaymentEnvelope as bM, buildSweepTypedData as ba, buildX402ExpectedMessage as bb, compareNodeVersions as bc, connectorRerunCommand as bd, connectorSpec as be, createNextStepBuilder as bf, decodeBase64Json as bg, decodeBase64Utf8 as bh, defaultNextToolFor as bi, encodeBase64Json as bj, encodeBase64Utf8 as bk, encodePaymentProof as bl, isConnectorChannel as bm, isErc7710Option as bn, isPackedUserOperationTypedData as bo, isSupportedNodeVersion as bp, isSweepableChain as bq, normalizePaymentRequired as br, packedUserOperationHash as bs, parseNextTool as bt, parsePaymentRequired as bu, parsePaymentRequiredResponse as bv, renderNextTool as bw, resolveConnectorChannel as bx, resolveTokenFromAddress as by, selectErc7710PaymentOption as bz, type X402AuthorizationOptions as c, type X402Intent as d, type PaymentStatusResult as e, type HavenAgent as f, type HavenAgentSummary as g, type SweepPrepareResponse as h, type SweepAuthorization as i, type SweepSubmitResponse as j, type HavenAllowanceSummary as k, type HavenBalanceCoverage as l, type PostPurchaseAllowanceSummary as m, type HavenCatalogEntry as n, type HavenCatalogSubmission as o, type HavenPaymentReceipt as p, type HavenPaymentReceiptsPage as q, type PaymentResumeState as r, type X402Receipt as s, type X402Quote as t, type X402Erc7710Settlement as u, type X402McpCallContext as v, type SignData as w, type ResumeAuthorizedX402Input as x, type ResumeX402PaymentInput as y, type X402ResumeState as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
3
|
var viem = require('viem');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
5
|
|
|
6
6
|
// src/connector-channel.ts
|
|
7
7
|
var CONNECTOR_PACKAGE_NAME = "@haven_ai/connect";
|
|
@@ -453,6 +453,137 @@ var HavenTimeoutError = class extends HavenError {
|
|
|
453
453
|
this.name = "HavenTimeoutError";
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
|
+
var DIRECT_SIGN_CONTEXT_VERSION = 1;
|
|
457
|
+
var EIP712_DOMAIN_FIELDS = [
|
|
458
|
+
{ name: "name", type: "string" },
|
|
459
|
+
{ name: "version", type: "string" },
|
|
460
|
+
{ name: "chainId", type: "uint256" },
|
|
461
|
+
{ name: "verifyingContract", type: "address" }
|
|
462
|
+
];
|
|
463
|
+
var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
464
|
+
var HYBRID_DELEGATOR_DOMAIN_NAME = "HybridDeleGator";
|
|
465
|
+
var HYBRID_DELEGATOR_DOMAIN_VERSION = "1";
|
|
466
|
+
var PACKED_USER_OPERATION_FIELDS = [
|
|
467
|
+
{ name: "sender", type: "address" },
|
|
468
|
+
{ name: "nonce", type: "uint256" },
|
|
469
|
+
{ name: "initCode", type: "bytes" },
|
|
470
|
+
{ name: "callData", type: "bytes" },
|
|
471
|
+
{ name: "accountGasLimits", type: "bytes32" },
|
|
472
|
+
{ name: "preVerificationGas", type: "uint256" },
|
|
473
|
+
{ name: "gasFees", type: "bytes32" },
|
|
474
|
+
{ name: "paymasterAndData", type: "bytes" },
|
|
475
|
+
{ name: "entryPoint", type: "address" }
|
|
476
|
+
];
|
|
477
|
+
var HavenUserOpBindingError = class extends HavenError {
|
|
478
|
+
constructor(message) {
|
|
479
|
+
super(message, "USEROP_BINDING_MISMATCH");
|
|
480
|
+
this.name = "HavenUserOpBindingError";
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
function isPackedUserOperationTypedData(value) {
|
|
484
|
+
return typeof value === "object" && value !== null && value.primaryType === "PackedUserOperation";
|
|
485
|
+
}
|
|
486
|
+
var HEX = /^0x[0-9a-fA-F]*$/;
|
|
487
|
+
var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
|
|
488
|
+
function refuse(detail) {
|
|
489
|
+
throw new HavenUserOpBindingError(
|
|
490
|
+
`Refusing to sign: this UserOperation typed data does not match its payload_hash (${detail}). The payload was altered between the Haven result and this call \u2014 sign by payment_id so the signer fetches the exact bytes, or pass typed_data_b64 from the result unchanged.`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
function hexField(message, key, pattern) {
|
|
494
|
+
const value = message[key];
|
|
495
|
+
if (typeof value !== "string" || !pattern.test(value)) refuse(`message.${key} is not well-formed`);
|
|
496
|
+
return value;
|
|
497
|
+
}
|
|
498
|
+
function uintField(message, key) {
|
|
499
|
+
const value = message[key];
|
|
500
|
+
try {
|
|
501
|
+
if (typeof value === "bigint") return value;
|
|
502
|
+
if (typeof value === "string" && /^(0x[0-9a-fA-F]+|[0-9]+)$/.test(value) || typeof value === "number") {
|
|
503
|
+
const n = BigInt(value);
|
|
504
|
+
if (n >= 0n) return n;
|
|
505
|
+
}
|
|
506
|
+
} catch {
|
|
507
|
+
}
|
|
508
|
+
return refuse(`message.${key} is not an unsigned integer`);
|
|
509
|
+
}
|
|
510
|
+
function addressField(value, where) {
|
|
511
|
+
if (typeof value !== "string" || !viem.isAddress(value, { strict: false })) refuse(`${where} is not an address`);
|
|
512
|
+
return viem.getAddress(value);
|
|
513
|
+
}
|
|
514
|
+
function packedUserOperationHash(typedData) {
|
|
515
|
+
if (!isPackedUserOperationTypedData(typedData)) refuse("primaryType is not PackedUserOperation");
|
|
516
|
+
const td = typedData;
|
|
517
|
+
const message = td.message;
|
|
518
|
+
if (!message || typeof message !== "object") refuse("message is missing");
|
|
519
|
+
const chainId = uintField({ chainId: td.domain?.chainId }, "chainId");
|
|
520
|
+
const inner = viem.keccak256(
|
|
521
|
+
viem.encodeAbiParameters(
|
|
522
|
+
[
|
|
523
|
+
{ type: "address" },
|
|
524
|
+
{ type: "uint256" },
|
|
525
|
+
{ type: "bytes32" },
|
|
526
|
+
{ type: "bytes32" },
|
|
527
|
+
{ type: "bytes32" },
|
|
528
|
+
{ type: "uint256" },
|
|
529
|
+
{ type: "bytes32" },
|
|
530
|
+
{ type: "bytes32" }
|
|
531
|
+
],
|
|
532
|
+
[
|
|
533
|
+
addressField(message.sender, "message.sender"),
|
|
534
|
+
uintField(message, "nonce"),
|
|
535
|
+
viem.keccak256(hexField(message, "initCode", HEX)),
|
|
536
|
+
viem.keccak256(hexField(message, "callData", HEX)),
|
|
537
|
+
hexField(message, "accountGasLimits", BYTES32),
|
|
538
|
+
uintField(message, "preVerificationGas"),
|
|
539
|
+
hexField(message, "gasFees", BYTES32),
|
|
540
|
+
viem.keccak256(hexField(message, "paymasterAndData", HEX))
|
|
541
|
+
]
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
return viem.keccak256(
|
|
545
|
+
viem.encodeAbiParameters(
|
|
546
|
+
[{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
|
|
547
|
+
[inner, addressField(message.entryPoint, "message.entryPoint"), chainId]
|
|
548
|
+
)
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
function assertUserOpTypedDataBinding(typedData, payloadHash) {
|
|
552
|
+
if (typeof payloadHash !== "string" || !BYTES32.test(payloadHash)) refuse("payload_hash is not a 32-byte hex string");
|
|
553
|
+
if (!isPackedUserOperationTypedData(typedData)) refuse("primaryType is not PackedUserOperation");
|
|
554
|
+
const td = typedData;
|
|
555
|
+
const domain = td.domain ?? {};
|
|
556
|
+
const message = td.message ?? {};
|
|
557
|
+
if (domain.name !== HYBRID_DELEGATOR_DOMAIN_NAME) refuse("domain.name is not HybridDeleGator");
|
|
558
|
+
if (domain.version !== HYBRID_DELEGATOR_DOMAIN_VERSION) refuse("domain.version is not 1");
|
|
559
|
+
if (addressField(domain.verifyingContract, "domain.verifyingContract") !== addressField(message.sender, "message.sender")) {
|
|
560
|
+
refuse("domain.verifyingContract is not message.sender");
|
|
561
|
+
}
|
|
562
|
+
if (addressField(message.entryPoint, "message.entryPoint") !== viem.getAddress(ENTRY_POINT_V07)) {
|
|
563
|
+
refuse("message.entryPoint is not the v0.7 EntryPoint");
|
|
564
|
+
}
|
|
565
|
+
const fields = (td.types ?? {}).PackedUserOperation;
|
|
566
|
+
if (!Array.isArray(fields) || fields.length !== PACKED_USER_OPERATION_FIELDS.length || fields.some(
|
|
567
|
+
(f, i) => !f || f.name !== PACKED_USER_OPERATION_FIELDS[i].name || f.type !== PACKED_USER_OPERATION_FIELDS[i].type
|
|
568
|
+
)) {
|
|
569
|
+
refuse("types.PackedUserOperation is not the HybridDeleGator field list");
|
|
570
|
+
}
|
|
571
|
+
const extraTypes = Object.keys(td.types ?? {}).filter((k) => k !== "PackedUserOperation" && k !== "EIP712Domain");
|
|
572
|
+
if (extraTypes.length > 0) refuse(`unexpected types: ${extraTypes.join(", ")}`);
|
|
573
|
+
const domainKeys = Object.keys(domain).sort();
|
|
574
|
+
if (domainKeys.join(",") !== [...EIP712_DOMAIN_FIELDS.map((f) => f.name)].sort().join(",")) {
|
|
575
|
+
refuse(`domain keys are not exactly ${EIP712_DOMAIN_FIELDS.map((f) => f.name).join(", ")}`);
|
|
576
|
+
}
|
|
577
|
+
const declaredDomain = (td.types ?? {}).EIP712Domain;
|
|
578
|
+
if (declaredDomain !== void 0 && (!Array.isArray(declaredDomain) || declaredDomain.length !== EIP712_DOMAIN_FIELDS.length || declaredDomain.some(
|
|
579
|
+
(f, i) => !f || f.name !== EIP712_DOMAIN_FIELDS[i].name || f.type !== EIP712_DOMAIN_FIELDS[i].type
|
|
580
|
+
))) {
|
|
581
|
+
refuse("types.EIP712Domain is not the canonical name/version/chainId/verifyingContract list");
|
|
582
|
+
}
|
|
583
|
+
const recomputed = packedUserOperationHash(typedData);
|
|
584
|
+
if (recomputed.toLowerCase() !== payloadHash.toLowerCase()) refuse("recomputed UserOperation hash differs");
|
|
585
|
+
return recomputed;
|
|
586
|
+
}
|
|
456
587
|
|
|
457
588
|
// src/base64.ts
|
|
458
589
|
function normalizeBase64(value) {
|
|
@@ -1182,19 +1313,25 @@ exports.AgentPaymentWarningCode = AgentPaymentWarningCode;
|
|
|
1182
1313
|
exports.CONNECTOR_PACKAGE_NAME = CONNECTOR_PACKAGE_NAME;
|
|
1183
1314
|
exports.DEFAULT_CONFIRMATION_TIMEOUT_MS = DEFAULT_CONFIRMATION_TIMEOUT_MS;
|
|
1184
1315
|
exports.DEFAULT_NEXT_TOOL_BY_ACTION = DEFAULT_NEXT_TOOL_BY_ACTION;
|
|
1316
|
+
exports.DIRECT_SIGN_CONTEXT_VERSION = DIRECT_SIGN_CONTEXT_VERSION;
|
|
1317
|
+
exports.ENTRY_POINT_V07 = ENTRY_POINT_V07;
|
|
1185
1318
|
exports.ERC7710_ASSET_TRANSFER_METHOD = ERC7710_ASSET_TRANSFER_METHOD;
|
|
1186
1319
|
exports.HAVEN_CONNECTOR_CHANNEL = HAVEN_CONNECTOR_CHANNEL;
|
|
1187
1320
|
exports.HAVEN_MINIMUM_NODE_VERSION = HAVEN_MINIMUM_NODE_VERSION;
|
|
1321
|
+
exports.HYBRID_DELEGATOR_DOMAIN_NAME = HYBRID_DELEGATOR_DOMAIN_NAME;
|
|
1322
|
+
exports.HYBRID_DELEGATOR_DOMAIN_VERSION = HYBRID_DELEGATOR_DOMAIN_VERSION;
|
|
1188
1323
|
exports.HavenApiError = HavenApiError;
|
|
1189
1324
|
exports.HavenError = HavenError;
|
|
1190
1325
|
exports.HavenPaymentStateError = HavenPaymentStateError;
|
|
1191
1326
|
exports.HavenSigningError = HavenSigningError;
|
|
1192
1327
|
exports.HavenTimeoutError = HavenTimeoutError;
|
|
1193
1328
|
exports.HavenUnsupportedSignerVersionError = HavenUnsupportedSignerVersionError;
|
|
1329
|
+
exports.HavenUserOpBindingError = HavenUserOpBindingError;
|
|
1194
1330
|
exports.HavenZeroSettlementHashError = HavenZeroSettlementHashError;
|
|
1195
1331
|
exports.MerchantTimeoutError = MerchantTimeoutError;
|
|
1196
1332
|
exports.NEXT_TOOL_SERVER_NAMES = NEXT_TOOL_SERVER_NAMES;
|
|
1197
1333
|
exports.NEXT_TOOL_SERVER_ROLES = NEXT_TOOL_SERVER_ROLES;
|
|
1334
|
+
exports.PACKED_USER_OPERATION_FIELDS = PACKED_USER_OPERATION_FIELDS;
|
|
1198
1335
|
exports.SIGNER_UPDATE_FALLBACK = SIGNER_UPDATE_FALLBACK;
|
|
1199
1336
|
exports.SWEEP_BASE_CHAIN_ID = SWEEP_BASE_CHAIN_ID;
|
|
1200
1337
|
exports.SWEEP_BASE_SEPOLIA_CHAIN_ID = SWEEP_BASE_SEPOLIA_CHAIN_ID;
|
|
@@ -1213,6 +1350,7 @@ exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
|
1213
1350
|
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
1214
1351
|
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
1215
1352
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
1353
|
+
exports.assertUserOpTypedDataBinding = assertUserOpTypedDataBinding;
|
|
1216
1354
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
1217
1355
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
1218
1356
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
@@ -1229,9 +1367,11 @@ exports.encodeBase64Utf8 = encodeBase64Utf8;
|
|
|
1229
1367
|
exports.encodePaymentProof = encodePaymentProof;
|
|
1230
1368
|
exports.isConnectorChannel = isConnectorChannel;
|
|
1231
1369
|
exports.isErc7710Option = isErc7710Option;
|
|
1370
|
+
exports.isPackedUserOperationTypedData = isPackedUserOperationTypedData;
|
|
1232
1371
|
exports.isSupportedNodeVersion = isSupportedNodeVersion;
|
|
1233
1372
|
exports.isSweepableChain = isSweepableChain;
|
|
1234
1373
|
exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
1374
|
+
exports.packedUserOperationHash = packedUserOperationHash;
|
|
1235
1375
|
exports.parseNextTool = parseNextTool;
|
|
1236
1376
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
1237
1377
|
exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;
|
|
@@ -1254,5 +1394,5 @@ exports.x402FacilitatorAddresses = x402FacilitatorAddresses;
|
|
|
1254
1394
|
exports.x402PaymentHeaderNamesFor = x402PaymentHeaderNamesFor;
|
|
1255
1395
|
exports.x402PaymentHeaderNamesSent = x402PaymentHeaderNamesSent;
|
|
1256
1396
|
exports.x402V2PaymentEnvelope = x402V2PaymentEnvelope;
|
|
1257
|
-
//# sourceMappingURL=chunk-
|
|
1258
|
-
//# sourceMappingURL=chunk-
|
|
1397
|
+
//# sourceMappingURL=chunk-CSWZXQ2L.cjs.map
|
|
1398
|
+
//# sourceMappingURL=chunk-CSWZXQ2L.cjs.map
|