@haven_ai/sdk 0.8.0-alpha.0 → 0.9.0-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.
Files changed (39) hide show
  1. package/dist/base64-BZDPJ8M1.d.ts +1344 -0
  2. package/dist/base64-Cyxhsvqd.d.cts +1344 -0
  3. package/dist/{chunk-UXULZ3ZY.js → chunk-424S4QMG.js} +10 -5
  4. package/dist/chunk-424S4QMG.js.map +1 -0
  5. package/dist/{chunk-HX34HOW4.cjs → chunk-4Z6ATE44.cjs} +2 -2
  6. package/dist/chunk-4Z6ATE44.cjs.map +1 -0
  7. package/dist/chunk-7UTWSJC5.cjs +106 -0
  8. package/dist/chunk-7UTWSJC5.cjs.map +1 -0
  9. package/dist/{chunk-H4APV67M.js → chunk-J7N4LUZZ.js} +2 -2
  10. package/dist/chunk-J7N4LUZZ.js.map +1 -0
  11. package/dist/chunk-VRKWNJ7H.js +103 -0
  12. package/dist/chunk-VRKWNJ7H.js.map +1 -0
  13. package/dist/{chunk-WJFDXCYP.cjs → chunk-ZDKNPNI3.cjs} +41 -35
  14. package/dist/chunk-ZDKNPNI3.cjs.map +1 -0
  15. package/dist/edge.cjs +97 -89
  16. package/dist/edge.d.cts +4 -2
  17. package/dist/edge.d.ts +4 -2
  18. package/dist/edge.js +4 -4
  19. package/dist/index.cjs +1033 -490
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +103 -147
  22. package/dist/index.d.ts +103 -147
  23. package/dist/index.js +705 -189
  24. package/dist/index.js.map +1 -1
  25. package/dist/receipt-D4Roey3D.d.cts +130 -0
  26. package/dist/receipt-WkXHZGbu.d.ts +130 -0
  27. package/dist/test-support.cjs +71 -18
  28. package/dist/test-support.cjs.map +1 -1
  29. package/dist/test-support.d.cts +21 -1
  30. package/dist/test-support.d.ts +21 -1
  31. package/dist/test-support.js +53 -3
  32. package/dist/test-support.js.map +1 -1
  33. package/dist/{base64-znjJJQqu.d.cts → types-CrszUJ7Z.d.cts} +208 -1306
  34. package/dist/{base64-znjJJQqu.d.ts → types-CrszUJ7Z.d.ts} +208 -1306
  35. package/package.json +1 -1
  36. package/dist/chunk-H4APV67M.js.map +0 -1
  37. package/dist/chunk-HX34HOW4.cjs.map +0 -1
  38. package/dist/chunk-UXULZ3ZY.js.map +0 -1
  39. package/dist/chunk-WJFDXCYP.cjs.map +0 -1
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ var chunk4Z6ATE44_cjs = require('./chunk-4Z6ATE44.cjs');
4
+ var ethers = require('ethers');
5
+ var viem = require('viem');
6
+
7
+ var RECEIPT_VERSION = "haven-receipt-1";
8
+ var DELEGATION_MANAGER_CHAIN_IDS = /* @__PURE__ */ new Set([8453, 84532]);
9
+ var EIP712_DOMAIN_TYPEHASH = viem.keccak256(
10
+ viem.toBytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
11
+ );
12
+ function delegationDomainSeparator(chainId) {
13
+ return viem.keccak256(
14
+ viem.encodeAbiParameters(
15
+ [{ type: "bytes32" }, { type: "bytes32" }, { type: "bytes32" }, { type: "uint256" }, { type: "address" }],
16
+ [
17
+ EIP712_DOMAIN_TYPEHASH,
18
+ viem.keccak256(viem.toBytes("DelegationManager")),
19
+ viem.keccak256(viem.toBytes("1")),
20
+ BigInt(chainId),
21
+ chunk4Z6ATE44_cjs.DELEGATION_MANAGER
22
+ ]
23
+ )
24
+ );
25
+ }
26
+ function delegationDigest(structHash, chainId) {
27
+ return viem.keccak256(viem.concatHex(["0x1901", delegationDomainSeparator(chainId), structHash]));
28
+ }
29
+ function defaultRecover(hash, signature) {
30
+ return ethers.ethers.recoverAddress(hash, signature);
31
+ }
32
+ var NOT_A_SIGNED_RECEIPT = { verified: false, reason: "not_a_signed_receipt" };
33
+ function match(delegate, hash, signature, recover) {
34
+ let recovered;
35
+ try {
36
+ recovered = recover(hash, signature);
37
+ } catch {
38
+ return { ok: false, reason: "bad_signature" };
39
+ }
40
+ if (recovered.toLowerCase() !== delegate.toLowerCase()) {
41
+ return { ok: false, reason: "signer_mismatch", recoveredSigner: recovered };
42
+ }
43
+ return { ok: true, recoveredSigner: recovered };
44
+ }
45
+ function finish(result, verifiedOver) {
46
+ if (result.ok) {
47
+ return { verified: true, recoveredSigner: result.recoveredSigner, verifiedOver };
48
+ }
49
+ return result.recoveredSigner !== void 0 ? { verified: false, reason: result.reason, recoveredSigner: result.recoveredSigner } : { verified: false, reason: result.reason };
50
+ }
51
+ function verifyPaymentReceipt(receipt, recover = defaultRecover) {
52
+ if (typeof receipt !== "object" || receipt === null) return NOT_A_SIGNED_RECEIPT;
53
+ let source = receipt;
54
+ if (typeof source.authorization !== "object" || source.authorization === null) {
55
+ if (typeof source.receipt !== "object" || source.receipt === null) {
56
+ return NOT_A_SIGNED_RECEIPT;
57
+ }
58
+ source = source.receipt;
59
+ }
60
+ if (typeof source.authorization !== "object" || source.authorization === null) {
61
+ return NOT_A_SIGNED_RECEIPT;
62
+ }
63
+ const auth = source.authorization;
64
+ const { delegate, signHash, signature, signatureScheme } = auth;
65
+ if (typeof delegate !== "string" || delegate === "" || typeof signHash !== "string" || signHash === "") {
66
+ return NOT_A_SIGNED_RECEIPT;
67
+ }
68
+ if (typeof signature !== "string" || signature === "") {
69
+ return { verified: false, reason: "missing_signature" };
70
+ }
71
+ const chainId = typeof source.onChain?.chainId === "number" ? source.onChain.chainId : void 0;
72
+ const digestVerifiable = chainId !== void 0 && DELEGATION_MANAGER_CHAIN_IDS.has(chainId);
73
+ if (signatureScheme === "eip712_userop") {
74
+ return { verified: false, reason: "not_verifiable_offline" };
75
+ }
76
+ if (signatureScheme === "eip712_delegation") {
77
+ if (!digestVerifiable) {
78
+ return { verified: false, reason: "not_verifiable_offline" };
79
+ }
80
+ let digest;
81
+ try {
82
+ digest = delegationDigest(signHash, chainId);
83
+ } catch {
84
+ return { verified: false, reason: "bad_signature" };
85
+ }
86
+ return finish(match(delegate, digest, signature, recover), "delegation_digest");
87
+ }
88
+ const raw = match(delegate, signHash, signature, recover);
89
+ if (raw.ok) return finish(raw, "sign_hash");
90
+ if (digestVerifiable) {
91
+ let digest;
92
+ try {
93
+ digest = delegationDigest(signHash, chainId);
94
+ } catch {
95
+ return finish(raw, "sign_hash");
96
+ }
97
+ const delegated = match(delegate, digest, signature, recover);
98
+ if (delegated.ok) return finish(delegated, "delegation_digest");
99
+ }
100
+ return finish(raw, "sign_hash");
101
+ }
102
+
103
+ exports.RECEIPT_VERSION = RECEIPT_VERSION;
104
+ exports.verifyPaymentReceipt = verifyPaymentReceipt;
105
+ //# sourceMappingURL=chunk-7UTWSJC5.cjs.map
106
+ //# sourceMappingURL=chunk-7UTWSJC5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/receipt.ts"],"names":["keccak256","toBytes","encodeAbiParameters","DELEGATION_MANAGER","concatHex","ethers"],"mappings":";;;;;;AA6CO,IAAM,eAAA,GAAkB;AA6E/B,IAAM,+CAAoD,IAAI,GAAA,CAAI,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAE/E,IAAM,sBAAA,GAAyBA,cAAA;AAAA,EAC7BC,aAAQ,oFAAoF;AAC9F,CAAA;AAOA,SAAS,0BAA0B,OAAA,EAAsB;AACvD,EAAA,OAAOD,cAAA;AAAA,IACLE,wBAAA;AAAA,MACE,CAAC,EAAE,IAAA,EAAM,SAAA,IAAa,EAAE,IAAA,EAAM,WAAU,EAAG,EAAE,MAAM,SAAA,EAAU,EAAG,EAAE,IAAA,EAAM,SAAA,IAAa,EAAE,IAAA,EAAM,WAAW,CAAA;AAAA,MACxG;AAAA,QACE,sBAAA;AAAA,QACAF,cAAA,CAAUC,YAAA,CAAQ,mBAAmB,CAAC,CAAA;AAAA,QACtCD,cAAA,CAAUC,YAAA,CAAQ,GAAG,CAAC,CAAA;AAAA,QACtB,OAAO,OAAO,CAAA;AAAA,QACdE;AAAA;AACF;AACF,GACF;AACF;AAGA,SAAS,gBAAA,CAAiB,YAAoB,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A,CAAO,KAAK,WAAW,CAAA;AAChC","file":"chunk-7UTWSJC5.cjs","sourcesContent":["import { ethers } from 'ethers'\nimport { concatHex, encodeAbiParameters, keccak256, toBytes, type Hex } from 'viem'\nimport { DELEGATION_MANAGER } from './settlement-child.js'\nimport type { RawPaymentParties } from './types.js'\n\n/**\n * Verifiable payment receipts.\n *\n * A self-contained bundle for a settled Haven payment whose agent\n * authorisation can be checked offline. What `verifyPaymentReceipt` proves is\n * deliberately narrow: the `payment` block (amount, recipient) is\n * Haven-asserted and is NOT bound by the signature, and `verified: true` never\n * proves the payment settled on-chain — settlement stays an explorer check on\n * `onChain.txHash` / `settlementTxHash`.\n *\n * What `verified: true` means, per scheme:\n *\n * - erc7710 (`authorization.signatureScheme: 'eip712_delegation'`): the bundle\n * carries the settlement child's EIP-712 struct hash as `signHash`. The\n * verifier rebuilds the digest the delegate actually signed —\n * `keccak256(0x1901 ‖ domainSeparator(DelegationManager, chainId) ‖ signHash)`\n * — from the DelegationManager address the SDK pins and the bundle's\n * `onChain.chainId`, never from a value the receipt itself vouches for.\n * `verified: true` means the delegate key signed that settlement delegation\n * (`verifiedOver: 'delegation_digest'`).\n * - direct payments and the eip3009 funding leg\n * (`signatureScheme: 'eip712_userop'`) sign an ERC-4337 user operation the\n * bundle does not carry: they return `not_verifiable_offline` rather than a\n * false accusation.\n * - retired-rail bundles (no scheme) carry a raw-signed `signHash`; the\n * verifier recovers over it directly, then over the delegation digest when\n * the chain allows rebuilding it.\n *\n * Anything that is not a signed bundle — including a `haven_list_receipts`\n * history row, which carries no signature at all — returns\n * `not_a_signed_receipt`. Verification never throws.\n *\n * #3723: the response `GET /payments/{id}/receipt` returns —\n * `{ receipt, verification }` — is accepted AS-IS: when the top level carries\n * no `authorization`, the `.receipt` object inside is verified instead (one\n * level, no recursion). The wrapper's `verification` is never read — it is\n * Haven's own self-check, and trusting it would defeat an offline verifier.\n *\n * This lives in the SDK so agents and users can verify receipts client-side.\n */\nexport const RECEIPT_VERSION = 'haven-receipt-1'\n\nexport interface PaymentReceipt {\n version: typeof RECEIPT_VERSION\n paymentId: string\n payment: {\n token: string\n tokenAddress: string\n amount: string\n amountSek: string | null\n recipient: string\n /** The payer's smart-account address. */\n account: string\n /**\n * #2960: one party vocabulary for \"who paid\", additive alongside `account`\n * above (which is `parties.treasury_account` only). Optional: a server\n * from before #2960 emits neither. Ignored by `verifyPaymentReceipt`,\n * which reads only `authorization`.\n */\n parties?: RawPaymentParties\n chainId: number\n settledAt: string | null\n resourceUrl: string | null\n /**\n * #3770: the paying agent's own evidence-only verdict on what the\n * merchant DELIVERED (`ok` / `unusable` / `partial`, plus a bounded\n * note). Additive and OPTIONAL: a server from before #3770 emits\n * neither, and `null` means the agent has not reported. Ignored by\n * `verifyPaymentReceipt`, which reads only `authorization` — the same\n * rule `parties` follows. Evidence only: it never changes what the\n * payment itself is, and `settled`/amounts are untouched by a report.\n */\n deliveryQuality?: {\n quality: 'ok' | 'unusable' | 'partial'\n note: string | null\n reportedAt: string | null\n } | null\n }\n /** The agent's cryptographic authorisation — what makes the receipt verifiable. */\n authorization: {\n delegate: string\n signHash: string\n signature: string | null\n /**\n * #3418: which digest the delegate signed — selects what offline\n * verification rebuilds. `'eip712_delegation'`: the settlement\n * delegation's EIP-712 digest (erc7710). `'eip712_userop'`: an ERC-4337\n * user-operation digest the bundle does not carry (direct payments, the\n * eip3009 funding leg) — not verifiable offline. Absent on retired-rail\n * bundles and on backends older than #3418, whose `signHash` was signed\n * raw. The value is only a selector: a lying one cannot make a forged\n * signature verify, because recovery must still return `delegate`.\n */\n signatureScheme?: 'eip712_delegation' | 'eip712_userop'\n }\n onChain: {\n txHash: string | null\n chainId: number\n }\n}\n\nexport type ReceiptVerification =\n | { verified: true; recoveredSigner: string; verifiedOver: 'sign_hash' | 'delegation_digest' }\n | {\n verified: false\n reason:\n /** #3418: the input is not a haven-receipt-1 bundle (a haven_list_receipts row, null, undefined, a non-object). */\n | 'not_a_signed_receipt'\n /** #3418: eip712_userop bundle; or a delegation bundle on a chain the SDK pins no DelegationManager for. */\n | 'not_verifiable_offline'\n | 'missing_signature'\n | 'bad_signature'\n | 'signer_mismatch'\n recoveredSigner?: string\n }\n\n/** Chains whose DelegationManager the SDK pins (same address on both — rails/delegation-contracts.ts). */\nconst DELEGATION_MANAGER_CHAIN_IDS: ReadonlySet<number> = new Set([8453, 84532])\n\nconst EIP712_DOMAIN_TYPEHASH = keccak256(\n toBytes('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),\n)\n\n/**\n * The EIP-712 domain separator of the DelegationManager on `chainId`, rebuilt\n * from the manager's own constants (name/version, fixed in the contract) and\n * the address the SDK pins — never from a value the receipt vouches for.\n */\nfunction delegationDomainSeparator(chainId: number): Hex {\n return keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'bytes32' }, { type: 'bytes32' }, { type: 'uint256' }, { type: 'address' }],\n [\n EIP712_DOMAIN_TYPEHASH,\n keccak256(toBytes('DelegationManager')),\n keccak256(toBytes('1')),\n BigInt(chainId),\n DELEGATION_MANAGER as Hex,\n ],\n ),\n )\n}\n\n/** The EIP-712 digest over a delegation struct hash (what the delegate signs). */\nfunction delegationDigest(structHash: string, chainId: number): Hex {\n return keccak256(concatHex(['0x1901', delegationDomainSeparator(chainId), structHash as Hex]))\n}\n\n/** Default ECDSA recovery (raw ecrecover over the hash, no message prefix). */\nfunction defaultRecover(hash: string, signature: string): string {\n return ethers.recoverAddress(hash, signature)\n}\n\nconst NOT_A_SIGNED_RECEIPT = { verified: false, reason: 'not_a_signed_receipt' } as const\n\ntype RecoverFn = (hash: string, signature: string) => string\n\ntype MatchResult =\n | { ok: true; recoveredSigner: string }\n | { ok: false; reason: 'bad_signature' | 'signer_mismatch'; recoveredSigner?: string }\n\n/** Recover over one candidate hash and compare the signer with the named delegate. */\nfunction match(delegate: string, hash: string, signature: string, recover: RecoverFn): MatchResult {\n let recovered: string\n try {\n recovered = recover(hash, signature)\n } catch {\n return { ok: false, reason: 'bad_signature' }\n }\n if (recovered.toLowerCase() !== delegate.toLowerCase()) {\n return { ok: false, reason: 'signer_mismatch', recoveredSigner: recovered }\n }\n return { ok: true, recoveredSigner: recovered }\n}\n\nfunction finish(result: MatchResult, verifiedOver: 'sign_hash' | 'delegation_digest'): ReceiptVerification {\n if (result.ok) {\n return { verified: true, recoveredSigner: result.recoveredSigner, verifiedOver }\n }\n return result.recoveredSigner !== undefined\n ? { verified: false, reason: result.reason, recoveredSigner: result.recoveredSigner }\n : { verified: false, reason: result.reason }\n}\n\n/**\n * Verify a receipt's agent authorisation offline: recover the signer and\n * confirm it is the agent delegate, over whichever digest the bundle's scheme\n * names (see the module doc for what that proves — and what it does not).\n * Never throws: anything that is not a signed receipt — a\n * `haven_list_receipts` history row, null, undefined, a non-object — returns\n * `not_a_signed_receipt`. The `{ receipt, verification }` wrapper the receipt\n * endpoint returns is accepted as-is: `.receipt` is verified, and the\n * wrapper's `verification` — Haven's own self-check — is never read. Pure —\n * `recover` is injectable but defaults to\n * standard ECDSA recovery, so this runs anywhere (no Haven backend).\n */\nexport function verifyPaymentReceipt(\n receipt: unknown,\n recover: RecoverFn = defaultRecover,\n): ReceiptVerification {\n // #3418 rule 1: a list row (or any non-bundle) has no authorization object\n // holding string delegate/signHash — answer, never throw.\n if (typeof receipt !== 'object' || receipt === null) return NOT_A_SIGNED_RECEIPT\n let source = receipt as {\n authorization?: unknown\n receipt?: unknown\n onChain?: { chainId?: unknown }\n }\n // #3723: accept the endpoint's response as-is. When the top level carries no\n // `authorization` and `.receipt` is a non-null object, verify the bundle\n // inside the `{ receipt, verification }` wrapper (GET\n // /payments/{id}/receipt, and HavenClient.getReceipt's re-wrap). ONE level\n // only — no recursion — and the wrapper's `verification` is NEVER read: it\n // is Haven's own self-check, and trusting it would defeat an offline\n // verifier. A list row wrapped or bare still answers not_a_signed_receipt.\n if (typeof source.authorization !== 'object' || source.authorization === null) {\n if (typeof source.receipt !== 'object' || source.receipt === null) {\n return NOT_A_SIGNED_RECEIPT\n }\n source = source.receipt as typeof source\n }\n if (typeof source.authorization !== 'object' || source.authorization === null) {\n return NOT_A_SIGNED_RECEIPT\n }\n const auth = source.authorization as {\n delegate?: unknown\n signHash?: unknown\n signature?: unknown\n signatureScheme?: unknown\n }\n const { delegate, signHash, signature, signatureScheme } = auth\n if (typeof delegate !== 'string' || delegate === '' || typeof signHash !== 'string' || signHash === '') {\n return NOT_A_SIGNED_RECEIPT\n }\n if (typeof signature !== 'string' || signature === '') {\n return { verified: false, reason: 'missing_signature' }\n }\n\n const chainId =\n typeof source.onChain?.chainId === 'number' ? source.onChain.chainId : undefined\n const digestVerifiable = chainId !== undefined && DELEGATION_MANAGER_CHAIN_IDS.has(chainId)\n\n // #3418 rule 4: a userop digest needs the full UserOperation, which the\n // bundle does not carry. Return not_verifiable_offline — never\n // signer_mismatch, which would accuse a genuine payment.\n if (signatureScheme === 'eip712_userop') {\n return { verified: false, reason: 'not_verifiable_offline' }\n }\n\n // #3418 rule 3: rebuild the delegation digest from the pinned manager and\n // the bundle's chain id, then recover over it.\n if (signatureScheme === 'eip712_delegation') {\n if (!digestVerifiable) {\n return { verified: false, reason: 'not_verifiable_offline' }\n }\n let digest: string\n try {\n digest = delegationDigest(signHash, chainId as number)\n } catch {\n return { verified: false, reason: 'bad_signature' }\n }\n return finish(match(delegate, digest, signature, recover), 'delegation_digest')\n }\n\n // #3418 rule 5: absent or unknown scheme — retired-rail history (signed raw\n // over signHash) or a backend older than this change. Raw recovery first,\n // then the delegation digest when the chain allows rebuilding it. This is\n // the one remaining ambiguous case, limited to old bundles.\n const raw = match(delegate, signHash, signature, recover)\n if (raw.ok) return finish(raw, 'sign_hash')\n if (digestVerifiable) {\n let digest: string\n try {\n digest = delegationDigest(signHash, chainId as number)\n } catch {\n return finish(raw, 'sign_hash')\n }\n const delegated = match(delegate, digest, signature, recover)\n if (delegated.ok) return finish(delegated, 'delegation_digest')\n }\n return finish(raw, 'sign_hash')\n}\n"]}
@@ -1016,5 +1016,5 @@ function assertRedeemsOwnBudgetDelegation(redeemCalldata, ownAccount) {
1016
1016
  }
1017
1017
 
1018
1018
  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, CAVEAT_ENFORCERS, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DELEGATION_MANAGER, DELEGATION_TUPLE_COMPONENTS, DIRECT_SIGN_CONTEXT_VERSION, ENTRY_POINT_V07, HAVEN_CONNECTOR_CHANNEL, HYBRID_DELEGATOR_DOMAIN_NAME, HYBRID_DELEGATOR_DOMAIN_VERSION, HYBRID_DELEGATOR_IMPLEMENTATION, HavenApiError, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, HavenUserOpBindingError, HavenZeroSettlementHashError, MAX_SETTLEMENT_WINDOW_SECONDS, MerchantTimeoutError, PACKED_USER_OPERATION_FIELDS, REDEEM_DELEGATIONS_ABI, ROOT_AUTHORITY, SIGNER_UPDATE_FALLBACK, SIMPLE_FACTORY_ADDRESS, SINGLE_DEFAULT_MODE, SignerRefusalCode, TASK_SIGN_CONTEXT_VERSION, X402AlreadySettledError, X402Erc7710AlreadySettledError, X402TaskBudgetMismatchError, X402UnexpectedStatusError, assertRedeemsOwnBudgetDelegation, assertUserOpTypedDataBinding, chainIdForNetwork, connectorRerunCommand, connectorSpec, connectorUpgradeCommand, deriveDelegateAccountAddress, isConnectorChannel, isPackedUserOperationTypedData, isSettlementChildTypedData, packedUserOperationHash, resolveConnectorChannel, signerUpdateFallback, verifySettlementChild };
1019
- //# sourceMappingURL=chunk-H4APV67M.js.map
1020
- //# sourceMappingURL=chunk-H4APV67M.js.map
1019
+ //# sourceMappingURL=chunk-J7N4LUZZ.js.map
1020
+ //# sourceMappingURL=chunk-J7N4LUZZ.js.map