@haven_ai/sdk 0.4.0-alpha.0 → 0.6.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.
@@ -0,0 +1,215 @@
1
+ 'use strict';
2
+
3
+ var chunkS42QSWJY_cjs = require('./chunk-S42QSWJY.cjs');
4
+ var viem = require('viem');
5
+
6
+ var ZERO_BYTES32 = `0x${"00".repeat(32)}`;
7
+ var ROOT_AUTHORITY = `0x${"ff".repeat(32)}`;
8
+ var DEFAULT_DELEGATOR = "0x98989898989898989898989898989898989898De";
9
+ var DELEGATION_ARRAY_PARAM = [
10
+ { type: "tuple[]", components: chunkS42QSWJY_cjs.DELEGATION_TUPLE_COMPONENTS }
11
+ ];
12
+ var EXECUTE_ABI = [
13
+ {
14
+ type: "function",
15
+ name: "execute",
16
+ inputs: [
17
+ {
18
+ name: "_execution",
19
+ type: "tuple",
20
+ components: [
21
+ { name: "target", type: "address" },
22
+ { name: "value", type: "uint256" },
23
+ { name: "callData", type: "bytes" }
24
+ ]
25
+ }
26
+ ],
27
+ outputs: [],
28
+ stateMutability: "payable"
29
+ }
30
+ ];
31
+ var TRANSFER_ABI = [
32
+ {
33
+ type: "function",
34
+ name: "transfer",
35
+ inputs: [
36
+ { name: "to", type: "address" },
37
+ { name: "amount", type: "uint256" }
38
+ ],
39
+ outputs: [{ type: "bool" }],
40
+ stateMutability: "nonpayable"
41
+ }
42
+ ];
43
+ function buildDelegation(overrides) {
44
+ return {
45
+ delegate: overrides.delegate,
46
+ delegator: overrides.delegator ?? DEFAULT_DELEGATOR,
47
+ authority: overrides.authority ?? ROOT_AUTHORITY,
48
+ caveats: overrides.caveats ?? [
49
+ // A real-shaped (if inert for test purposes) TimestampEnforcer term —
50
+ // real budget delegations always carry at least one caveat.
51
+ { enforcer: "0x1046bb45C8d673d4ea75321280DB34899413c069", terms: `0x${"00".repeat(32)}`, args: "0x" }
52
+ ],
53
+ salt: overrides.salt ?? 1n,
54
+ signature: overrides.signature ?? `0x${"ab".repeat(65)}`
55
+ };
56
+ }
57
+ function buildPermissionContext(delegation) {
58
+ return viem.encodeAbiParameters(DELEGATION_ARRAY_PARAM, [[delegation]]);
59
+ }
60
+ function buildChainPermissionContext(chain) {
61
+ return viem.encodeAbiParameters(DELEGATION_ARRAY_PARAM, [chain]);
62
+ }
63
+ function buildEmptyPermissionContext() {
64
+ return viem.encodeAbiParameters(DELEGATION_ARRAY_PARAM, [[]]);
65
+ }
66
+ function buildSingleExecutionCallData(target, value, innerCallData) {
67
+ return viem.encodePacked(["address", "uint256", "bytes"], [target, value, innerCallData]);
68
+ }
69
+ function buildTransferExecutionCallData(token, to, amount) {
70
+ return buildSingleExecutionCallData(
71
+ token,
72
+ 0n,
73
+ viem.encodeFunctionData({ abi: TRANSFER_ABI, functionName: "transfer", args: [to, amount] })
74
+ );
75
+ }
76
+ function buildBoundRedeemDelegationsCallData(options) {
77
+ const delegation = buildDelegation({ delegate: options.delegate, delegator: options.delegator, caveats: options.caveats });
78
+ const permissionContext = buildPermissionContext(delegation);
79
+ const executionCallData = options.executionCallData ?? buildTransferExecutionCallData(
80
+ "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
81
+ // Base Sepolia USDC, matches the real captured fixture
82
+ "0x98ffBf30459a98FD80fAce18f519967769641F76",
83
+ 10000n
84
+ );
85
+ return viem.encodeFunctionData({
86
+ abi: chunkS42QSWJY_cjs.REDEEM_DELEGATIONS_ABI,
87
+ functionName: "redeemDelegations",
88
+ args: [[permissionContext], [chunkS42QSWJY_cjs.SINGLE_DEFAULT_MODE], [executionCallData]]
89
+ });
90
+ }
91
+ function buildEmptyPermissionContextRedemption(selfCallCallData) {
92
+ return viem.encodeFunctionData({
93
+ abi: chunkS42QSWJY_cjs.REDEEM_DELEGATIONS_ABI,
94
+ functionName: "redeemDelegations",
95
+ args: [[buildEmptyPermissionContext()], [chunkS42QSWJY_cjs.SINGLE_DEFAULT_MODE], [selfCallCallData]]
96
+ });
97
+ }
98
+ function buildExecuteCallData(target, value, innerCallData) {
99
+ return viem.encodeFunctionData({
100
+ abi: EXECUTE_ABI,
101
+ functionName: "execute",
102
+ args: [{ target, value, callData: innerCallData }]
103
+ });
104
+ }
105
+ function buildBoundDirectUserOp(options) {
106
+ const chainId = options.chainId ?? 84532;
107
+ const sender = options.sender ?? chunkS42QSWJY_cjs.deriveDelegateAccountAddress(options.delegate);
108
+ const callData = options.callData ?? buildExecuteCallData(
109
+ options.target ?? chunkS42QSWJY_cjs.DELEGATION_MANAGER,
110
+ options.value ?? 0n,
111
+ buildBoundRedeemDelegationsCallData({ delegate: sender, delegator: options.delegator })
112
+ );
113
+ const typedData = {
114
+ domain: {
115
+ name: chunkS42QSWJY_cjs.HYBRID_DELEGATOR_DOMAIN_NAME,
116
+ version: chunkS42QSWJY_cjs.HYBRID_DELEGATOR_DOMAIN_VERSION,
117
+ chainId,
118
+ verifyingContract: sender
119
+ },
120
+ types: { PackedUserOperation: chunkS42QSWJY_cjs.PACKED_USER_OPERATION_FIELDS.map((field) => ({ ...field })) },
121
+ primaryType: "PackedUserOperation",
122
+ message: {
123
+ sender,
124
+ nonce: "0",
125
+ initCode: "0x",
126
+ callData,
127
+ accountGasLimits: ZERO_BYTES32,
128
+ preVerificationGas: "0",
129
+ gasFees: ZERO_BYTES32,
130
+ paymasterAndData: "0x",
131
+ entryPoint: chunkS42QSWJY_cjs.ENTRY_POINT_V07
132
+ }
133
+ };
134
+ const payloadHash = chunkS42QSWJY_cjs.packedUserOperationHash(typedData);
135
+ return { typedData, payloadHash, sender };
136
+ }
137
+ function buildSelfCallCallData(sender) {
138
+ const TRANSFER_OWNERSHIP_ABI = [
139
+ { type: "function", name: "transferOwnership", inputs: [{ name: "newOwner", type: "address" }], outputs: [], stateMutability: "nonpayable" }
140
+ ];
141
+ const inner = viem.encodeFunctionData({
142
+ abi: TRANSFER_OWNERSHIP_ABI,
143
+ functionName: "transferOwnership",
144
+ args: ["0x000000000000000000000000000000000000dEaD"]
145
+ });
146
+ return buildExecuteCallData(sender, 0n, inner);
147
+ }
148
+ function rebuildDirectUserOpForSender(fixtureTypedData, newSender) {
149
+ const originalCallData = fixtureTypedData.message.callData;
150
+ const { args: executeArgs } = viem.decodeFunctionData({ abi: EXECUTE_ABI, data: originalCallData });
151
+ const execution = executeArgs[0];
152
+ const { args: redeemArgs } = viem.decodeFunctionData({ abi: chunkS42QSWJY_cjs.REDEEM_DELEGATIONS_ABI, data: execution.callData });
153
+ const [permissionContexts, modes, executionCallDatas] = redeemArgs;
154
+ const [delegations] = viem.decodeAbiParameters(DELEGATION_ARRAY_PARAM, permissionContexts[0]);
155
+ const adjustedDelegations = delegations.map(
156
+ (d, i) => i === 0 ? { ...d, delegate: newSender } : d
157
+ );
158
+ const adjustedPermissionContext = viem.encodeAbiParameters(DELEGATION_ARRAY_PARAM, [adjustedDelegations]);
159
+ const adjustedRedeemCallData = viem.encodeFunctionData({
160
+ abi: chunkS42QSWJY_cjs.REDEEM_DELEGATIONS_ABI,
161
+ functionName: "redeemDelegations",
162
+ args: [[adjustedPermissionContext], modes, executionCallDatas]
163
+ });
164
+ const adjustedCallData = viem.encodeFunctionData({
165
+ abi: EXECUTE_ABI,
166
+ functionName: "execute",
167
+ args: [{ target: execution.target, value: execution.value, callData: adjustedRedeemCallData }]
168
+ });
169
+ const typedData = {
170
+ ...fixtureTypedData,
171
+ domain: { ...fixtureTypedData.domain, verifyingContract: newSender },
172
+ message: { ...fixtureTypedData.message, sender: newSender, callData: adjustedCallData }
173
+ };
174
+ const payloadHash = chunkS42QSWJY_cjs.packedUserOperationHash(typedData);
175
+ return { typedData, payloadHash };
176
+ }
177
+ function buildFundingLegUserOp(options) {
178
+ const sender = chunkS42QSWJY_cjs.deriveDelegateAccountAddress(options.delegate);
179
+ const callData = buildExecuteCallData(
180
+ chunkS42QSWJY_cjs.DELEGATION_MANAGER,
181
+ 0n,
182
+ buildBoundRedeemDelegationsCallData({
183
+ delegate: sender,
184
+ caveats: options.caveats,
185
+ executionCallData: buildTransferExecutionCallData(
186
+ options.asset,
187
+ options.recipient ?? options.delegate,
188
+ BigInt(options.amount)
189
+ )
190
+ })
191
+ );
192
+ const { typedData, payloadHash } = buildBoundDirectUserOp({
193
+ delegate: options.delegate,
194
+ chainId: options.chainId ?? 84532,
195
+ callData
196
+ });
197
+ return { typedData, payloadHash, digest: viem.hashTypedData(typedData) };
198
+ }
199
+
200
+ exports.DEFAULT_DELEGATOR = DEFAULT_DELEGATOR;
201
+ exports.buildBoundDirectUserOp = buildBoundDirectUserOp;
202
+ exports.buildBoundRedeemDelegationsCallData = buildBoundRedeemDelegationsCallData;
203
+ exports.buildChainPermissionContext = buildChainPermissionContext;
204
+ exports.buildDelegation = buildDelegation;
205
+ exports.buildEmptyPermissionContext = buildEmptyPermissionContext;
206
+ exports.buildEmptyPermissionContextRedemption = buildEmptyPermissionContextRedemption;
207
+ exports.buildExecuteCallData = buildExecuteCallData;
208
+ exports.buildFundingLegUserOp = buildFundingLegUserOp;
209
+ exports.buildPermissionContext = buildPermissionContext;
210
+ exports.buildSelfCallCallData = buildSelfCallCallData;
211
+ exports.buildSingleExecutionCallData = buildSingleExecutionCallData;
212
+ exports.buildTransferExecutionCallData = buildTransferExecutionCallData;
213
+ exports.rebuildDirectUserOpForSender = rebuildDirectUserOpForSender;
214
+ //# sourceMappingURL=test-support.cjs.map
215
+ //# sourceMappingURL=test-support.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-support/direct-userop.ts"],"names":["DELEGATION_TUPLE_COMPONENTS","encodeAbiParameters","encodePacked","encodeFunctionData","REDEEM_DELEGATIONS_ABI","SINGLE_DEFAULT_MODE","deriveDelegateAccountAddress","DELEGATION_MANAGER","HYBRID_DELEGATOR_DOMAIN_NAME","HYBRID_DELEGATOR_DOMAIN_VERSION","PACKED_USER_OPERATION_FIELDS","ENTRY_POINT_V07","packedUserOperationHash","decodeFunctionData","decodeAbiParameters","hashTypedData"],"mappings":";;;;;AA0CA,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A,EAAW,WAAA,EAAY,GAAI,sBAAA,CAAuB;AAAA,IACxD,UAAU,OAAA,CAAQ,QAAA;AAAA,IAClB,OAAA,EAAS,QAAQ,OAAA,IAAW,KAAA;AAAA,IAC5B;AAAA,GACD,CAAA;AACD,EAAA,OAAO,EAAE,SAAA,EAAW,WAAA,EAAa,MAAA,EAAQQ,kBAAA,CAAc,SAAkB,CAAA,EAAE;AAC7E","file":"test-support.cjs","sourcesContent":["/**\n * #3272 — a real-shaped, BOUND direct-payment `PackedUserOperation` for\n * signer tests: `sender` is the counterfactual delegate account for a given\n * owner EOA, and `callData` is `execute(DelegationManager, 0,\n * redeemDelegations(...))` with a REAL redemption shape — one non-empty\n * `Delegation`, `delegate` = the signer's own account, `delegator` = a\n * distinct treasury address, `ExecutionMode.SingleDefault`, an\n * `encodePacked(target,value,callData)` execution — mirroring\n * `packages/backend/src/rails/delegation-rail.ts`'s `prepareRedemption`.\n * Replaces the toy 2-field / empty-callData / empty-arrays fixtures the\n * allowlist correctly refuses (including the B1 empty-permission-context\n * bypass, `buildEmptyPermissionContextRedemption` below, kept ONLY to\n * reproduce that exact refusal in a test).\n *\n * Moved here from `@haven_ai/signer` by #3283 so the SDK, the signer,\n * `@haven_ai/mcp` and `mcp-server` share ONE guard-valid builder. Published\n * as the `@haven_ai/sdk/test-support` subpath only because a sibling\n * package's tests cannot import this file by relative path (each package's\n * `tsc` `rootDir` is its own `src`). Test fixtures, not a signing API:\n * nothing here signs, and nothing the SDK or signer runs imports it.\n */\nimport {\n decodeAbiParameters,\n decodeFunctionData,\n encodeAbiParameters,\n encodeFunctionData,\n encodePacked,\n hashTypedData,\n type Address,\n type Hex,\n} from 'viem'\nimport {\n ENTRY_POINT_V07,\n HYBRID_DELEGATOR_DOMAIN_NAME,\n HYBRID_DELEGATOR_DOMAIN_VERSION,\n PACKED_USER_OPERATION_FIELDS,\n packedUserOperationHash,\n} from '../userop-binding.js'\nimport { DELEGATION_MANAGER } from '../settlement-child.js'\nimport { deriveDelegateAccountAddress } from '../delegate-account.js'\nimport { DELEGATION_TUPLE_COMPONENTS, REDEEM_DELEGATIONS_ABI, SINGLE_DEFAULT_MODE } from '../redemption-guard.js'\n\nconst ZERO_BYTES32 = `0x${'00'.repeat(32)}` as const\n\n/** `Delegation.authority` sentinel for a root (unchained) delegation — `@metamask/delegation-core`'s `ROOT_AUTHORITY`. */\nconst ROOT_AUTHORITY: Hex = `0x${'ff'.repeat(32)}`\n\n/** Stand-in treasury address — distinct from any derived signer account, matching the real fixture's `delegator`. */\nexport const DEFAULT_DELEGATOR: Address = '0x98989898989898989898989898989898989898De' as Address\n\nconst DELEGATION_ARRAY_PARAM = [\n { type: 'tuple[]', components: DELEGATION_TUPLE_COMPONENTS },\n] as const\n\nconst EXECUTE_ABI = [\n {\n type: 'function',\n name: 'execute',\n inputs: [\n {\n name: '_execution',\n type: 'tuple',\n components: [\n { name: 'target', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'callData', type: 'bytes' },\n ],\n },\n ],\n outputs: [],\n stateMutability: 'payable',\n },\n] as const\n\nconst TRANSFER_ABI = [\n {\n type: 'function',\n name: 'transfer',\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'amount', type: 'uint256' },\n ],\n outputs: [{ type: 'bool' }],\n stateMutability: 'nonpayable',\n },\n] as const\n\nexport interface DelegationOverrides {\n /** The redeemer this delegation authorises — normally the signer's own derived account. */\n delegate: Address\n /** Who granted it — must differ from `delegate` for a real (non-self) delegation. */\n delegator?: Address\n authority?: Hex\n caveats?: Array<{ enforcer: Address; terms: Hex; args: Hex }>\n salt?: bigint\n signature?: Hex\n}\n\n/** A single, well-formed `Delegation` tuple — the ONE-link chain Haven's backend redeems (`delegations: [[delegation]]`). */\nexport function buildDelegation(overrides: DelegationOverrides) {\n return {\n delegate: overrides.delegate,\n delegator: overrides.delegator ?? DEFAULT_DELEGATOR,\n authority: overrides.authority ?? ROOT_AUTHORITY,\n caveats: overrides.caveats ?? [\n // A real-shaped (if inert for test purposes) TimestampEnforcer term —\n // real budget delegations always carry at least one caveat.\n { enforcer: '0x1046bb45C8d673d4ea75321280DB34899413c069' as Address, terms: `0x${'00'.repeat(32)}` as Hex, args: '0x' as Hex },\n ],\n salt: overrides.salt ?? 1n,\n signature: overrides.signature ?? (`0x${'ab'.repeat(65)}` as Hex),\n }\n}\n\n/** `abi.encode(Delegation[])` for a ONE-delegation chain — a Haven-shaped permission context. */\nexport function buildPermissionContext(delegation: ReturnType<typeof buildDelegation>): Hex {\n return encodeAbiParameters(DELEGATION_ARRAY_PARAM, [[delegation]])\n}\n\n/** `abi.encode(Delegation[])` for a MULTI-link chain (leaf first) — never emitted by Haven. */\nexport function buildChainPermissionContext(chain: ReturnType<typeof buildDelegation>[]): Hex {\n return encodeAbiParameters(DELEGATION_ARRAY_PARAM, [chain])\n}\n\n/** `abi.encode(Delegation[])` for an EMPTY chain — the exact B1 bypass shape MetaMask's DelegationManager treats as self-authorised. */\nexport function buildEmptyPermissionContext(): Hex {\n return encodeAbiParameters(DELEGATION_ARRAY_PARAM, [[]])\n}\n\n/** `encodePacked(address,uint256,bytes)` — the single-execution calldata `ExecutionMode.SingleDefault` expects. */\nexport function buildSingleExecutionCallData(target: Address, value: bigint, innerCallData: Hex): Hex {\n return encodePacked(['address', 'uint256', 'bytes'], [target, value, innerCallData])\n}\n\n/** A real-shaped ERC-20 `transfer(to, amount)` execution — what a budget redemption actually spends. */\nexport function buildTransferExecutionCallData(token: Address, to: Address, amount: bigint): Hex {\n return buildSingleExecutionCallData(\n token,\n 0n,\n encodeFunctionData({ abi: TRANSFER_ABI, functionName: 'transfer', args: [to, amount] }),\n )\n}\n\nexport interface BoundRedeemDelegationsOptions {\n /** The redeemer — normally the signer's own derived account (matches the UserOp's `sender`). */\n delegate: Address\n delegator?: Address\n caveats?: DelegationOverrides['caveats']\n /** Override the single execution's calldata entirely (default: a real-shaped ERC-20 transfer). */\n executionCallData?: Hex\n}\n\n/** `redeemDelegations([permissionContext], [SingleDefault], [executionCallData])` — the REAL, bound shape. */\nexport function buildBoundRedeemDelegationsCallData(options: BoundRedeemDelegationsOptions): Hex {\n const delegation = buildDelegation({ delegate: options.delegate, delegator: options.delegator, caveats: options.caveats })\n const permissionContext = buildPermissionContext(delegation)\n const executionCallData =\n options.executionCallData ??\n buildTransferExecutionCallData(\n '0x036CbD53842c5426634e7929541eC2318f3dCF7e' as Address, // Base Sepolia USDC, matches the real captured fixture\n '0x98ffBf30459a98FD80fAce18f519967769641F76' as Address,\n 10000n,\n )\n return encodeFunctionData({\n abi: REDEEM_DELEGATIONS_ABI,\n functionName: 'redeemDelegations',\n args: [[permissionContext], [SINGLE_DEFAULT_MODE], [executionCallData]],\n })\n}\n\n/**\n * #3272 (B1 regression): `redeemDelegations([emptyPermissionContext],\n * [SingleDefault], [selfCallCallData])` — one permission context whose\n * `Delegation[]` decodes EMPTY, paired with a self-call execution. This is\n * the exact live bypass: MetaMask's DelegationManager treats an empty chain\n * as self-authorised and runs `selfCallCallData` AS the account. Exists only\n * so a test can assert this is refused, never to build a shape any code path\n * signs.\n */\nexport function buildEmptyPermissionContextRedemption(selfCallCallData: Hex): Hex {\n return encodeFunctionData({\n abi: REDEEM_DELEGATIONS_ABI,\n functionName: 'redeemDelegations',\n args: [[buildEmptyPermissionContext()], [SINGLE_DEFAULT_MODE], [selfCallCallData]],\n })\n}\n\n/** `execute((address,uint256,bytes))` — selector `0x5c1c6dcd`. */\nexport function buildExecuteCallData(target: Address, value: bigint, innerCallData: Hex): Hex {\n return encodeFunctionData({\n abi: EXECUTE_ABI,\n functionName: 'execute',\n args: [{ target, value, callData: innerCallData }],\n })\n}\n\nexport interface BoundDirectUserOpOptions {\n /** The delegate EOA (`signer.delegateAddress`) that owns the account `sender` derives from. */\n delegate: Address\n chainId?: number | bigint | string\n /** Override the execute() target — default DELEGATION_MANAGER (the bound shape). */\n target?: Address\n /** Override the execute() value — default 0n. */\n value?: bigint\n /** Override the full message.callData (bypasses target/value/redeemDelegations construction). */\n callData?: Hex\n /** Override sender/verifyingContract directly instead of deriving it from `delegate`. */\n sender?: Address\n /** Override the redemption's delegator (default: a distinct treasury address). */\n delegator?: Address\n}\n\nexport interface BoundDirectUserOp {\n typedData: {\n domain: { name: string; version: string; chainId: number | bigint | string; verifyingContract: Address }\n types: { PackedUserOperation: Array<{ name: string; type: string }> }\n primaryType: 'PackedUserOperation'\n message: Record<string, unknown>\n }\n payloadHash: Hex\n sender: Address\n}\n\n/**\n * A real-shaped, self-consistent (correct v0.7 hash) `PackedUserOperation`.\n * By default it is fully BOUND per #3272's allowlist: `sender` is the\n * counterfactual account for `delegate`, and `callData` redeems ONE real\n * delegation (delegate = `sender`, delegator = a distinct treasury address)\n * through the DelegationManager. Override `target` / `callData` / `sender` /\n * `delegator` to build the negative-test shapes the allowlist must refuse.\n */\nexport function buildBoundDirectUserOp(options: BoundDirectUserOpOptions): BoundDirectUserOp {\n const chainId = options.chainId ?? 84532\n const sender = options.sender ?? deriveDelegateAccountAddress(options.delegate)\n const callData =\n options.callData ??\n buildExecuteCallData(\n options.target ?? (DELEGATION_MANAGER as Address),\n options.value ?? 0n,\n buildBoundRedeemDelegationsCallData({ delegate: sender, delegator: options.delegator }),\n )\n const typedData = {\n domain: {\n name: HYBRID_DELEGATOR_DOMAIN_NAME,\n version: HYBRID_DELEGATOR_DOMAIN_VERSION,\n chainId,\n verifyingContract: sender,\n },\n types: { PackedUserOperation: PACKED_USER_OPERATION_FIELDS.map((field) => ({ ...field })) },\n primaryType: 'PackedUserOperation' as const,\n message: {\n sender,\n nonce: '0',\n initCode: '0x',\n callData,\n accountGasLimits: ZERO_BYTES32,\n preVerificationGas: '0',\n gasFees: ZERO_BYTES32,\n paymasterAndData: '0x',\n entryPoint: ENTRY_POINT_V07,\n },\n }\n const payloadHash = packedUserOperationHash(typedData)\n return { typedData, payloadHash, sender }\n}\n\n/** A well-formed `execute()` self-call — `target === sender` — for the (d)/self-call negative tests. */\nexport function buildSelfCallCallData(sender: Address): Hex {\n const TRANSFER_OWNERSHIP_ABI = [\n { type: 'function', name: 'transferOwnership', inputs: [{ name: 'newOwner', type: 'address' }], outputs: [], stateMutability: 'nonpayable' },\n ] as const\n const inner = encodeFunctionData({\n abi: TRANSFER_OWNERSHIP_ABI,\n functionName: 'transferOwnership',\n args: ['0x000000000000000000000000000000000000dEaD' as Address],\n })\n return buildExecuteCallData(sender, 0n, inner)\n}\n\n/**\n * Re-target a REAL captured direct-payment UserOp (for example\n * `__fixtures__/direct-payment-userop.json`) at `newSender`: the UserOp's\n * `sender` / `verifyingContract` and the redeemed delegation's `delegate`\n * become `newSender`; the delegator, caveats, mode and execution stay the\n * production bytes. The captured fixture is bound to a delegate whose key is\n * not in the repository, so a test signs this rebuilt copy with a test key\n * whose derived account is `newSender` — proving the guard accepts the actual\n * production shape, not only this file's synthetic one.\n */\nexport function rebuildDirectUserOpForSender(\n fixtureTypedData: {\n domain: Record<string, unknown>\n types: Record<string, unknown>\n primaryType: string\n message: Record<string, unknown>\n },\n newSender: Address,\n) {\n const originalCallData = fixtureTypedData.message.callData as Hex\n const { args: executeArgs } = decodeFunctionData({ abi: EXECUTE_ABI, data: originalCallData })\n const execution = executeArgs[0] as { target: Address; value: bigint; callData: Hex }\n const { args: redeemArgs } = decodeFunctionData({ abi: REDEEM_DELEGATIONS_ABI, data: execution.callData })\n const [permissionContexts, modes, executionCallDatas] = redeemArgs as unknown as [\n readonly Hex[],\n readonly Hex[],\n readonly Hex[],\n ]\n const [delegations] = decodeAbiParameters(DELEGATION_ARRAY_PARAM, permissionContexts[0])\n const adjustedDelegations = (delegations as unknown as Array<Record<string, unknown>>).map((d, i) =>\n i === 0 ? { ...d, delegate: newSender } : d,\n )\n const adjustedPermissionContext = encodeAbiParameters(DELEGATION_ARRAY_PARAM, [adjustedDelegations as never])\n const adjustedRedeemCallData = encodeFunctionData({\n abi: REDEEM_DELEGATIONS_ABI,\n functionName: 'redeemDelegations',\n args: [[adjustedPermissionContext], modes as Hex[], executionCallDatas as Hex[]],\n })\n const adjustedCallData = encodeFunctionData({\n abi: EXECUTE_ABI,\n functionName: 'execute',\n args: [{ target: execution.target, value: execution.value, callData: adjustedRedeemCallData }],\n })\n const typedData = {\n ...fixtureTypedData,\n domain: { ...fixtureTypedData.domain, verifyingContract: newSender },\n message: { ...fixtureTypedData.message, sender: newSender, callData: adjustedCallData },\n }\n const payloadHash = packedUserOperationHash(typedData as never) as Hex\n return { typedData, payloadHash }\n}\n\nexport interface FundingLegUserOpOptions {\n /** The delegate EOA (`signer.delegateAddress`): the account is derived from it AND it is the transfer's recipient. */\n delegate: Address\n /** The quoted token (the expected context's `asset`). */\n asset: Address\n /** The quoted atomic amount (the expected context's `amount`). */\n amount: bigint | string\n chainId?: number\n /** Override the transfer recipient (default: `delegate`) — for the recipient-pin negative test. */\n recipient?: Address\n /** Override the budget delegation's caveats (e.g. a multi-KB term, for relay-size tests). */\n caveats?: DelegationOverrides['caveats']\n}\n\n/**\n * #3281: an x402 EIP-3009 bridge FUNDING LEG exactly as the backend builds it\n * (`delegation-authorize.ts` → `prepareDelegationPayment(agent, token,\n * payTo = the delegate EOA, amountRaw)` → `prepareRedemption`): the\n * direct-payment shape, whose single execution is\n * `transfer(<delegate EOA>, <amount>)` on the quoted token. Returns the typed\n * data, its v0.7 UserOp hash (the expected context's `payloadHash`) and its\n * EIP-712 digest (the expected context's `typedDataHash`).\n */\nexport function buildFundingLegUserOp(options: FundingLegUserOpOptions) {\n const sender = deriveDelegateAccountAddress(options.delegate)\n const callData = buildExecuteCallData(\n DELEGATION_MANAGER as Address,\n 0n,\n buildBoundRedeemDelegationsCallData({\n delegate: sender,\n caveats: options.caveats,\n executionCallData: buildTransferExecutionCallData(\n options.asset,\n options.recipient ?? options.delegate,\n BigInt(options.amount),\n ),\n }),\n )\n const { typedData, payloadHash } = buildBoundDirectUserOp({\n delegate: options.delegate,\n chainId: options.chainId ?? 84532,\n callData,\n })\n return { typedData, payloadHash, digest: hashTypedData(typedData as never) }\n}\n"]}
@@ -0,0 +1,204 @@
1
+ import { Address, Hex } from 'viem';
2
+
3
+ /**
4
+ * #3272 — a real-shaped, BOUND direct-payment `PackedUserOperation` for
5
+ * signer tests: `sender` is the counterfactual delegate account for a given
6
+ * owner EOA, and `callData` is `execute(DelegationManager, 0,
7
+ * redeemDelegations(...))` with a REAL redemption shape — one non-empty
8
+ * `Delegation`, `delegate` = the signer's own account, `delegator` = a
9
+ * distinct treasury address, `ExecutionMode.SingleDefault`, an
10
+ * `encodePacked(target,value,callData)` execution — mirroring
11
+ * `packages/backend/src/rails/delegation-rail.ts`'s `prepareRedemption`.
12
+ * Replaces the toy 2-field / empty-callData / empty-arrays fixtures the
13
+ * allowlist correctly refuses (including the B1 empty-permission-context
14
+ * bypass, `buildEmptyPermissionContextRedemption` below, kept ONLY to
15
+ * reproduce that exact refusal in a test).
16
+ *
17
+ * Moved here from `@haven_ai/signer` by #3283 so the SDK, the signer,
18
+ * `@haven_ai/mcp` and `mcp-server` share ONE guard-valid builder. Published
19
+ * as the `@haven_ai/sdk/test-support` subpath only because a sibling
20
+ * package's tests cannot import this file by relative path (each package's
21
+ * `tsc` `rootDir` is its own `src`). Test fixtures, not a signing API:
22
+ * nothing here signs, and nothing the SDK or signer runs imports it.
23
+ */
24
+
25
+ /** Stand-in treasury address — distinct from any derived signer account, matching the real fixture's `delegator`. */
26
+ declare const DEFAULT_DELEGATOR: Address;
27
+ interface DelegationOverrides {
28
+ /** The redeemer this delegation authorises — normally the signer's own derived account. */
29
+ delegate: Address;
30
+ /** Who granted it — must differ from `delegate` for a real (non-self) delegation. */
31
+ delegator?: Address;
32
+ authority?: Hex;
33
+ caveats?: Array<{
34
+ enforcer: Address;
35
+ terms: Hex;
36
+ args: Hex;
37
+ }>;
38
+ salt?: bigint;
39
+ signature?: Hex;
40
+ }
41
+ /** A single, well-formed `Delegation` tuple — the ONE-link chain Haven's backend redeems (`delegations: [[delegation]]`). */
42
+ declare function buildDelegation(overrides: DelegationOverrides): {
43
+ delegate: `0x${string}`;
44
+ delegator: `0x${string}`;
45
+ authority: `0x${string}`;
46
+ caveats: {
47
+ enforcer: Address;
48
+ terms: Hex;
49
+ args: Hex;
50
+ }[];
51
+ salt: bigint;
52
+ signature: `0x${string}`;
53
+ };
54
+ /** `abi.encode(Delegation[])` for a ONE-delegation chain — a Haven-shaped permission context. */
55
+ declare function buildPermissionContext(delegation: ReturnType<typeof buildDelegation>): Hex;
56
+ /** `abi.encode(Delegation[])` for a MULTI-link chain (leaf first) — never emitted by Haven. */
57
+ declare function buildChainPermissionContext(chain: ReturnType<typeof buildDelegation>[]): Hex;
58
+ /** `abi.encode(Delegation[])` for an EMPTY chain — the exact B1 bypass shape MetaMask's DelegationManager treats as self-authorised. */
59
+ declare function buildEmptyPermissionContext(): Hex;
60
+ /** `encodePacked(address,uint256,bytes)` — the single-execution calldata `ExecutionMode.SingleDefault` expects. */
61
+ declare function buildSingleExecutionCallData(target: Address, value: bigint, innerCallData: Hex): Hex;
62
+ /** A real-shaped ERC-20 `transfer(to, amount)` execution — what a budget redemption actually spends. */
63
+ declare function buildTransferExecutionCallData(token: Address, to: Address, amount: bigint): Hex;
64
+ interface BoundRedeemDelegationsOptions {
65
+ /** The redeemer — normally the signer's own derived account (matches the UserOp's `sender`). */
66
+ delegate: Address;
67
+ delegator?: Address;
68
+ caveats?: DelegationOverrides['caveats'];
69
+ /** Override the single execution's calldata entirely (default: a real-shaped ERC-20 transfer). */
70
+ executionCallData?: Hex;
71
+ }
72
+ /** `redeemDelegations([permissionContext], [SingleDefault], [executionCallData])` — the REAL, bound shape. */
73
+ declare function buildBoundRedeemDelegationsCallData(options: BoundRedeemDelegationsOptions): Hex;
74
+ /**
75
+ * #3272 (B1 regression): `redeemDelegations([emptyPermissionContext],
76
+ * [SingleDefault], [selfCallCallData])` — one permission context whose
77
+ * `Delegation[]` decodes EMPTY, paired with a self-call execution. This is
78
+ * the exact live bypass: MetaMask's DelegationManager treats an empty chain
79
+ * as self-authorised and runs `selfCallCallData` AS the account. Exists only
80
+ * so a test can assert this is refused, never to build a shape any code path
81
+ * signs.
82
+ */
83
+ declare function buildEmptyPermissionContextRedemption(selfCallCallData: Hex): Hex;
84
+ /** `execute((address,uint256,bytes))` — selector `0x5c1c6dcd`. */
85
+ declare function buildExecuteCallData(target: Address, value: bigint, innerCallData: Hex): Hex;
86
+ interface BoundDirectUserOpOptions {
87
+ /** The delegate EOA (`signer.delegateAddress`) that owns the account `sender` derives from. */
88
+ delegate: Address;
89
+ chainId?: number | bigint | string;
90
+ /** Override the execute() target — default DELEGATION_MANAGER (the bound shape). */
91
+ target?: Address;
92
+ /** Override the execute() value — default 0n. */
93
+ value?: bigint;
94
+ /** Override the full message.callData (bypasses target/value/redeemDelegations construction). */
95
+ callData?: Hex;
96
+ /** Override sender/verifyingContract directly instead of deriving it from `delegate`. */
97
+ sender?: Address;
98
+ /** Override the redemption's delegator (default: a distinct treasury address). */
99
+ delegator?: Address;
100
+ }
101
+ interface BoundDirectUserOp {
102
+ typedData: {
103
+ domain: {
104
+ name: string;
105
+ version: string;
106
+ chainId: number | bigint | string;
107
+ verifyingContract: Address;
108
+ };
109
+ types: {
110
+ PackedUserOperation: Array<{
111
+ name: string;
112
+ type: string;
113
+ }>;
114
+ };
115
+ primaryType: 'PackedUserOperation';
116
+ message: Record<string, unknown>;
117
+ };
118
+ payloadHash: Hex;
119
+ sender: Address;
120
+ }
121
+ /**
122
+ * A real-shaped, self-consistent (correct v0.7 hash) `PackedUserOperation`.
123
+ * By default it is fully BOUND per #3272's allowlist: `sender` is the
124
+ * counterfactual account for `delegate`, and `callData` redeems ONE real
125
+ * delegation (delegate = `sender`, delegator = a distinct treasury address)
126
+ * through the DelegationManager. Override `target` / `callData` / `sender` /
127
+ * `delegator` to build the negative-test shapes the allowlist must refuse.
128
+ */
129
+ declare function buildBoundDirectUserOp(options: BoundDirectUserOpOptions): BoundDirectUserOp;
130
+ /** A well-formed `execute()` self-call — `target === sender` — for the (d)/self-call negative tests. */
131
+ declare function buildSelfCallCallData(sender: Address): Hex;
132
+ /**
133
+ * Re-target a REAL captured direct-payment UserOp (for example
134
+ * `__fixtures__/direct-payment-userop.json`) at `newSender`: the UserOp's
135
+ * `sender` / `verifyingContract` and the redeemed delegation's `delegate`
136
+ * become `newSender`; the delegator, caveats, mode and execution stay the
137
+ * production bytes. The captured fixture is bound to a delegate whose key is
138
+ * not in the repository, so a test signs this rebuilt copy with a test key
139
+ * whose derived account is `newSender` — proving the guard accepts the actual
140
+ * production shape, not only this file's synthetic one.
141
+ */
142
+ declare function rebuildDirectUserOpForSender(fixtureTypedData: {
143
+ domain: Record<string, unknown>;
144
+ types: Record<string, unknown>;
145
+ primaryType: string;
146
+ message: Record<string, unknown>;
147
+ }, newSender: Address): {
148
+ typedData: {
149
+ domain: {
150
+ verifyingContract: `0x${string}`;
151
+ };
152
+ message: {
153
+ sender: `0x${string}`;
154
+ callData: `0x${string}`;
155
+ };
156
+ types: Record<string, unknown>;
157
+ primaryType: string;
158
+ };
159
+ payloadHash: `0x${string}`;
160
+ };
161
+ interface FundingLegUserOpOptions {
162
+ /** The delegate EOA (`signer.delegateAddress`): the account is derived from it AND it is the transfer's recipient. */
163
+ delegate: Address;
164
+ /** The quoted token (the expected context's `asset`). */
165
+ asset: Address;
166
+ /** The quoted atomic amount (the expected context's `amount`). */
167
+ amount: bigint | string;
168
+ chainId?: number;
169
+ /** Override the transfer recipient (default: `delegate`) — for the recipient-pin negative test. */
170
+ recipient?: Address;
171
+ /** Override the budget delegation's caveats (e.g. a multi-KB term, for relay-size tests). */
172
+ caveats?: DelegationOverrides['caveats'];
173
+ }
174
+ /**
175
+ * #3281: an x402 EIP-3009 bridge FUNDING LEG exactly as the backend builds it
176
+ * (`delegation-authorize.ts` → `prepareDelegationPayment(agent, token,
177
+ * payTo = the delegate EOA, amountRaw)` → `prepareRedemption`): the
178
+ * direct-payment shape, whose single execution is
179
+ * `transfer(<delegate EOA>, <amount>)` on the quoted token. Returns the typed
180
+ * data, its v0.7 UserOp hash (the expected context's `payloadHash`) and its
181
+ * EIP-712 digest (the expected context's `typedDataHash`).
182
+ */
183
+ declare function buildFundingLegUserOp(options: FundingLegUserOpOptions): {
184
+ typedData: {
185
+ domain: {
186
+ name: string;
187
+ version: string;
188
+ chainId: number | bigint | string;
189
+ verifyingContract: Address;
190
+ };
191
+ types: {
192
+ PackedUserOperation: Array<{
193
+ name: string;
194
+ type: string;
195
+ }>;
196
+ };
197
+ primaryType: "PackedUserOperation";
198
+ message: Record<string, unknown>;
199
+ };
200
+ payloadHash: `0x${string}`;
201
+ digest: `0x${string}`;
202
+ };
203
+
204
+ export { type BoundDirectUserOp, type BoundDirectUserOpOptions, type BoundRedeemDelegationsOptions, DEFAULT_DELEGATOR, type DelegationOverrides, type FundingLegUserOpOptions, buildBoundDirectUserOp, buildBoundRedeemDelegationsCallData, buildChainPermissionContext, buildDelegation, buildEmptyPermissionContext, buildEmptyPermissionContextRedemption, buildExecuteCallData, buildFundingLegUserOp, buildPermissionContext, buildSelfCallCallData, buildSingleExecutionCallData, buildTransferExecutionCallData, rebuildDirectUserOpForSender };