@haven_ai/sdk 0.7.0-alpha.0 → 0.8.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -9
- package/dist/{base64-_seD1uw8.d.cts → base64-BjxHPgtC.d.cts} +275 -16
- package/dist/{base64-_seD1uw8.d.ts → base64-BjxHPgtC.d.ts} +275 -16
- package/dist/{chunk-NNIT7WAI.js → chunk-H4APV67M.js} +2 -2
- package/dist/chunk-H4APV67M.js.map +1 -0
- package/dist/{chunk-J6DQEBK2.cjs → chunk-HFOAYTD4.cjs} +216 -40
- package/dist/chunk-HFOAYTD4.cjs.map +1 -0
- package/dist/{chunk-3SVPI4LS.cjs → chunk-HX34HOW4.cjs} +2 -2
- package/dist/chunk-HX34HOW4.cjs.map +1 -0
- package/dist/{chunk-R3RZJJWL.js → chunk-WDA3IGJP.js} +180 -17
- package/dist/chunk-WDA3IGJP.js.map +1 -0
- package/dist/edge.cjs +128 -128
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +172 -3
- package/dist/edge.d.ts +172 -3
- package/dist/edge.js +5 -54
- package/dist/edge.js.map +1 -1
- package/dist/index.cjs +685 -348
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -21
- package/dist/index.d.ts +76 -21
- package/dist/index.js +392 -55
- package/dist/index.js.map +1 -1
- package/dist/test-support.cjs +18 -18
- package/dist/test-support.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3SVPI4LS.cjs.map +0 -1
- package/dist/chunk-J6DQEBK2.cjs.map +0 -1
- package/dist/chunk-NNIT7WAI.js.map +0 -1
- package/dist/chunk-R3RZJJWL.js.map +0 -1
package/dist/edge.cjs
CHANGED
|
@@ -1,56 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var secp256k1 = require('@noble/curves/secp256k1');
|
|
6
|
-
var accounts = require('viem/accounts');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
|
|
9
|
-
var HALF_N = BigInt("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0");
|
|
10
|
-
function hexBytes(value, bytes, what) {
|
|
11
|
-
if (!/^0x[0-9a-fA-F]+$/.test(value) || value.length !== 2 + bytes * 2) {
|
|
12
|
-
throw new Error(`${what} must be a 0x-prefixed ${bytes}-byte hex string`);
|
|
13
|
-
}
|
|
14
|
-
return value.slice(2);
|
|
15
|
-
}
|
|
16
|
-
function addressFromKey(privateKey) {
|
|
17
|
-
try {
|
|
18
|
-
return accounts.privateKeyToAddress(`0x${hexBytes(privateKey, 32, "private key")}`);
|
|
19
|
-
} catch (err) {
|
|
20
|
-
throw new chunk3SVPI4LS_cjs.HavenSigningError(
|
|
21
|
-
`Invalid private key: ${err instanceof Error ? err.message : String(err)}`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function signHash(privateKey, hash) {
|
|
26
|
-
try {
|
|
27
|
-
const { r, s, recovery } = secp256k1.secp256k1.sign(hexBytes(hash, 32, "hash"), hexBytes(privateKey, 32, "private key"), { lowS: true });
|
|
28
|
-
return viem.serializeSignature({
|
|
29
|
-
r: `0x${r.toString(16).padStart(64, "0")}`,
|
|
30
|
-
s: `0x${s.toString(16).padStart(64, "0")}`,
|
|
31
|
-
yParity: recovery
|
|
32
|
-
});
|
|
33
|
-
} catch (err) {
|
|
34
|
-
throw new chunk3SVPI4LS_cjs.HavenSigningError(
|
|
35
|
-
`Failed to sign hash: ${err instanceof Error ? err.message : String(err)}`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function verifySignature(hash, signature, expectedAddress) {
|
|
40
|
-
try {
|
|
41
|
-
const sig = hexBytes(signature, 65, "signature");
|
|
42
|
-
const hashHex = hexBytes(hash, 32, "hash");
|
|
43
|
-
if (BigInt(`0x${sig.slice(64, 128)}`) > HALF_N) return false;
|
|
44
|
-
const yParityOrV = Number.parseInt(sig.slice(128), 16);
|
|
45
|
-
const recoveryBit = yParityOrV === 0 || yParityOrV === 27 ? 0 : yParityOrV === 1 || yParityOrV === 28 ? 1 : -1;
|
|
46
|
-
if (recoveryBit < 0) return false;
|
|
47
|
-
const publicKey = secp256k1.secp256k1.Signature.fromCompact(sig.slice(0, 128)).addRecoveryBit(recoveryBit).recoverPublicKey(hashHex).toHex(false);
|
|
48
|
-
const recovered = accounts.publicKeyToAddress(`0x${publicKey}`);
|
|
49
|
-
return recovered.toLowerCase() === expectedAddress.toLowerCase();
|
|
50
|
-
} catch {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
3
|
+
var chunkHFOAYTD4_cjs = require('./chunk-HFOAYTD4.cjs');
|
|
4
|
+
var chunkHX34HOW4_cjs = require('./chunk-HX34HOW4.cjs');
|
|
54
5
|
|
|
55
6
|
// src/sub-budget-guards.ts
|
|
56
7
|
var ERC20_PERIOD_TRANSFER_ENFORCER = "0x474e3Ae7E169e940607cC624Da8A15Eb120139aB";
|
|
@@ -80,10 +31,10 @@ function findCaveat(caveats, enforcer) {
|
|
|
80
31
|
return caveats.find((c) => same(c.enforcer, enforcer));
|
|
81
32
|
}
|
|
82
33
|
function hashSubBudgetDelegation(delegation) {
|
|
83
|
-
return
|
|
34
|
+
return chunkHFOAYTD4_cjs.hashDelegation(delegation);
|
|
84
35
|
}
|
|
85
36
|
function refuseSubBudgetChild(what, detail) {
|
|
86
|
-
throw new
|
|
37
|
+
throw new chunkHFOAYTD4_cjs.HavenTypedDataRefusedError(
|
|
87
38
|
`Refusing to sign the sub-budget child: ${what}. ${detail} This signature opens a slice of the delegating agent budget for another agent, so it is verified locally against the expectation Haven declared, rather than trusted.`
|
|
88
39
|
);
|
|
89
40
|
}
|
|
@@ -92,10 +43,10 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
92
43
|
if (td?.primaryType !== "Delegation") {
|
|
93
44
|
refuseSubBudgetChild("it is not a Delegation payload", `primaryType was '${String(td?.primaryType)}'.`);
|
|
94
45
|
}
|
|
95
|
-
if (!same(td.domain?.verifyingContract,
|
|
46
|
+
if (!same(td.domain?.verifyingContract, chunkHX34HOW4_cjs.DELEGATION_MANAGER)) {
|
|
96
47
|
refuseSubBudgetChild(
|
|
97
48
|
"the EIP-712 domain names an unknown DelegationManager",
|
|
98
|
-
`Expected ${
|
|
49
|
+
`Expected ${chunkHX34HOW4_cjs.DELEGATION_MANAGER}, got ${td.domain?.verifyingContract}.`
|
|
99
50
|
);
|
|
100
51
|
}
|
|
101
52
|
if (td.domain?.name !== DELEGATION_DOMAIN_NAME || td.domain?.version !== DELEGATION_DOMAIN_VERSION) {
|
|
@@ -111,10 +62,10 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
111
62
|
);
|
|
112
63
|
}
|
|
113
64
|
const domainChain = Number(td.domain?.chainId);
|
|
114
|
-
if (!Number.isFinite(domainChain) || !
|
|
65
|
+
if (!Number.isFinite(domainChain) || !chunkHFOAYTD4_cjs.DIRECT_PAYMENT_CHAIN_IDS.has(domainChain)) {
|
|
115
66
|
refuseSubBudgetChild(
|
|
116
67
|
"it is scoped to a chain the delegation rail has no pinned contracts for",
|
|
117
|
-
`Chains with pinned contracts: ${[...
|
|
68
|
+
`Chains with pinned contracts: ${[...chunkHFOAYTD4_cjs.DIRECT_PAYMENT_CHAIN_IDS].join(", ")}; the child says ${String(td.domain?.chainId)}.`
|
|
118
69
|
);
|
|
119
70
|
}
|
|
120
71
|
if (domainChain !== expected.chainId) {
|
|
@@ -123,7 +74,7 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
123
74
|
`Expected chain ${expected.chainId}; the child says ${td.domain?.chainId}.`
|
|
124
75
|
);
|
|
125
76
|
}
|
|
126
|
-
const ownAccount =
|
|
77
|
+
const ownAccount = chunkHX34HOW4_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
127
78
|
const delegator = td.message?.delegator;
|
|
128
79
|
if (typeof delegator !== "string" || !same(delegator, ownAccount)) {
|
|
129
80
|
refuseSubBudgetChild(
|
|
@@ -148,7 +99,7 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
148
99
|
if (typeof authority !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(authority)) {
|
|
149
100
|
refuseSubBudgetChild("its authority is not a 32-byte delegation hash", `Got ${String(authority)}.`);
|
|
150
101
|
}
|
|
151
|
-
if (authority.toLowerCase() ===
|
|
102
|
+
if (authority.toLowerCase() === chunkHX34HOW4_cjs.ROOT_AUTHORITY) {
|
|
152
103
|
refuseSubBudgetChild(
|
|
153
104
|
"it is a ROOT delegation, not a re-delegation of the delegating agent budget",
|
|
154
105
|
"A sub-budget always chains under the delegating agent budget delegation."
|
|
@@ -161,7 +112,7 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
161
112
|
);
|
|
162
113
|
}
|
|
163
114
|
const caveats = td.message?.caveats ?? [];
|
|
164
|
-
if (findCaveat(caveats,
|
|
115
|
+
if (findCaveat(caveats, chunkHX34HOW4_cjs.CAVEAT_ENFORCERS.erc20TransferAmount)) {
|
|
165
116
|
refuseSubBudgetChild(
|
|
166
117
|
"it carries a hard-cap transfer-amount caveat (the task-budget shape)",
|
|
167
118
|
"A sub-budget is period-scoped: its amount caveat must be an ERC20PeriodTransferEnforcer caveat slicing the parent period meter, never a lifetime cap."
|
|
@@ -199,7 +150,7 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
199
150
|
`Expected ${expected.startDate}; the child says ${startDate}.`
|
|
200
151
|
);
|
|
201
152
|
}
|
|
202
|
-
const timestamp = findCaveat(caveats,
|
|
153
|
+
const timestamp = findCaveat(caveats, chunkHX34HOW4_cjs.CAVEAT_ENFORCERS.timestamp);
|
|
203
154
|
if (!timestamp) {
|
|
204
155
|
refuseSubBudgetChild("it never expires", "A sub-budget child without a timestamp caveat is open-ended.");
|
|
205
156
|
}
|
|
@@ -214,7 +165,7 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
214
165
|
`Expected ${expected.expiresAt}; the child says ${beforeThreshold}.`
|
|
215
166
|
);
|
|
216
167
|
}
|
|
217
|
-
const calldata = findCaveat(caveats,
|
|
168
|
+
const calldata = findCaveat(caveats, chunkHX34HOW4_cjs.CAVEAT_ENFORCERS.allowedCalldata);
|
|
218
169
|
if (expected.recipientAddress) {
|
|
219
170
|
if (!calldata) {
|
|
220
171
|
refuseSubBudgetChild(
|
|
@@ -248,263 +199,312 @@ function assertOwnSubBudgetChild(typedData, expected, delegateAddress, now = Dat
|
|
|
248
199
|
}
|
|
249
200
|
}
|
|
250
201
|
function assertOwnSubBudgetCloseUserOp(typedData, expected, delegateAddress) {
|
|
251
|
-
|
|
202
|
+
chunkHFOAYTD4_cjs.assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress);
|
|
252
203
|
}
|
|
253
204
|
|
|
254
205
|
Object.defineProperty(exports, "CAVEAT_TYPEHASH", {
|
|
255
206
|
enumerable: true,
|
|
256
|
-
get: function () { return
|
|
207
|
+
get: function () { return chunkHFOAYTD4_cjs.CAVEAT_TYPEHASH; }
|
|
257
208
|
});
|
|
258
209
|
Object.defineProperty(exports, "DELEGATION_TYPEHASH", {
|
|
259
210
|
enumerable: true,
|
|
260
|
-
get: function () { return
|
|
211
|
+
get: function () { return chunkHFOAYTD4_cjs.DELEGATION_TYPEHASH; }
|
|
261
212
|
});
|
|
262
213
|
Object.defineProperty(exports, "DIRECT_PAYMENT_CHAIN_IDS", {
|
|
263
214
|
enumerable: true,
|
|
264
|
-
get: function () { return
|
|
215
|
+
get: function () { return chunkHFOAYTD4_cjs.DIRECT_PAYMENT_CHAIN_IDS; }
|
|
265
216
|
});
|
|
266
217
|
Object.defineProperty(exports, "EXECUTE_ABI", {
|
|
267
218
|
enumerable: true,
|
|
268
|
-
get: function () { return
|
|
219
|
+
get: function () { return chunkHFOAYTD4_cjs.EXECUTE_ABI; }
|
|
269
220
|
});
|
|
270
221
|
Object.defineProperty(exports, "HAVEN_CLIENT_HEADER", {
|
|
271
222
|
enumerable: true,
|
|
272
|
-
get: function () { return
|
|
223
|
+
get: function () { return chunkHFOAYTD4_cjs.HAVEN_CLIENT_HEADER; }
|
|
273
224
|
});
|
|
274
225
|
Object.defineProperty(exports, "HAVEN_MINIMUM_NODE_VERSION", {
|
|
275
226
|
enumerable: true,
|
|
276
|
-
get: function () { return
|
|
227
|
+
get: function () { return chunkHFOAYTD4_cjs.HAVEN_MINIMUM_NODE_VERSION; }
|
|
277
228
|
});
|
|
278
229
|
Object.defineProperty(exports, "HavenTypedDataRefusedError", {
|
|
279
230
|
enumerable: true,
|
|
280
|
-
get: function () { return
|
|
231
|
+
get: function () { return chunkHFOAYTD4_cjs.HavenTypedDataRefusedError; }
|
|
281
232
|
});
|
|
282
233
|
Object.defineProperty(exports, "MAX_TASK_BUDGET_TTL_SECONDS", {
|
|
283
234
|
enumerable: true,
|
|
284
|
-
get: function () { return
|
|
235
|
+
get: function () { return chunkHFOAYTD4_cjs.MAX_TASK_BUDGET_TTL_SECONDS; }
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, "TAX_DECLARATION_DOMAIN", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function () { return chunkHFOAYTD4_cjs.TAX_DECLARATION_DOMAIN; }
|
|
240
|
+
});
|
|
241
|
+
Object.defineProperty(exports, "TAX_DECLARATION_PRIMARY_TYPE", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
get: function () { return chunkHFOAYTD4_cjs.TAX_DECLARATION_PRIMARY_TYPE; }
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(exports, "TAX_DECLARATION_TYPES", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function () { return chunkHFOAYTD4_cjs.TAX_DECLARATION_TYPES; }
|
|
285
248
|
});
|
|
286
249
|
Object.defineProperty(exports, "TYPED_DATA_NOT_ALLOWED", {
|
|
287
250
|
enumerable: true,
|
|
288
|
-
get: function () { return
|
|
251
|
+
get: function () { return chunkHFOAYTD4_cjs.TYPED_DATA_NOT_ALLOWED; }
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(exports, "TaxDeclarationRefusedError", {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
get: function () { return chunkHFOAYTD4_cjs.TaxDeclarationRefusedError; }
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(exports, "X_TAX_DECLARATION_HEADER", {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () { return chunkHFOAYTD4_cjs.X_TAX_DECLARATION_HEADER; }
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(exports, "addressFromKey", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function () { return chunkHFOAYTD4_cjs.addressFromKey; }
|
|
289
264
|
});
|
|
290
265
|
Object.defineProperty(exports, "assertBoundDirectPaymentUserOp", {
|
|
291
266
|
enumerable: true,
|
|
292
|
-
get: function () { return
|
|
267
|
+
get: function () { return chunkHFOAYTD4_cjs.assertBoundDirectPaymentUserOp; }
|
|
293
268
|
});
|
|
294
269
|
Object.defineProperty(exports, "assertFundingLegPaysDelegate", {
|
|
295
270
|
enumerable: true,
|
|
296
|
-
get: function () { return
|
|
271
|
+
get: function () { return chunkHFOAYTD4_cjs.assertFundingLegPaysDelegate; }
|
|
297
272
|
});
|
|
298
273
|
Object.defineProperty(exports, "assertOwnSettlementChild", {
|
|
299
274
|
enumerable: true,
|
|
300
|
-
get: function () { return
|
|
275
|
+
get: function () { return chunkHFOAYTD4_cjs.assertOwnSettlementChild; }
|
|
301
276
|
});
|
|
302
277
|
Object.defineProperty(exports, "assertOwnTaskBudgetCloseUserOp", {
|
|
303
278
|
enumerable: true,
|
|
304
|
-
get: function () { return
|
|
279
|
+
get: function () { return chunkHFOAYTD4_cjs.assertOwnTaskBudgetCloseUserOp; }
|
|
305
280
|
});
|
|
306
281
|
Object.defineProperty(exports, "assertOwnTaskChild", {
|
|
307
282
|
enumerable: true,
|
|
308
|
-
get: function () { return
|
|
283
|
+
get: function () { return chunkHFOAYTD4_cjs.assertOwnTaskChild; }
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, "buildSignedTaxDeclaration", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function () { return chunkHFOAYTD4_cjs.buildSignedTaxDeclaration; }
|
|
309
288
|
});
|
|
310
289
|
Object.defineProperty(exports, "buildSweepAuthorizationMessage", {
|
|
311
290
|
enumerable: true,
|
|
312
|
-
get: function () { return
|
|
291
|
+
get: function () { return chunkHFOAYTD4_cjs.buildSweepAuthorizationMessage; }
|
|
313
292
|
});
|
|
314
293
|
Object.defineProperty(exports, "buildSweepTypedData", {
|
|
315
294
|
enumerable: true,
|
|
316
|
-
get: function () { return
|
|
295
|
+
get: function () { return chunkHFOAYTD4_cjs.buildSweepTypedData; }
|
|
317
296
|
});
|
|
318
297
|
Object.defineProperty(exports, "buildX402ExpectedMessage", {
|
|
319
298
|
enumerable: true,
|
|
320
|
-
get: function () { return
|
|
299
|
+
get: function () { return chunkHFOAYTD4_cjs.buildX402ExpectedMessage; }
|
|
321
300
|
});
|
|
322
301
|
Object.defineProperty(exports, "createNextStepBuilder", {
|
|
323
302
|
enumerable: true,
|
|
324
|
-
get: function () { return
|
|
303
|
+
get: function () { return chunkHFOAYTD4_cjs.createNextStepBuilder; }
|
|
325
304
|
});
|
|
326
305
|
Object.defineProperty(exports, "decodeBase64Json", {
|
|
327
306
|
enumerable: true,
|
|
328
|
-
get: function () { return
|
|
307
|
+
get: function () { return chunkHFOAYTD4_cjs.decodeBase64Json; }
|
|
329
308
|
});
|
|
330
309
|
Object.defineProperty(exports, "encodeBase64Json", {
|
|
331
310
|
enumerable: true,
|
|
332
|
-
get: function () { return
|
|
311
|
+
get: function () { return chunkHFOAYTD4_cjs.encodeBase64Json; }
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(exports, "encodeTaxDeclarationHeader", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
get: function () { return chunkHFOAYTD4_cjs.encodeTaxDeclarationHeader; }
|
|
333
316
|
});
|
|
334
317
|
Object.defineProperty(exports, "hashDelegation", {
|
|
335
318
|
enumerable: true,
|
|
336
|
-
get: function () { return
|
|
319
|
+
get: function () { return chunkHFOAYTD4_cjs.hashDelegation; }
|
|
337
320
|
});
|
|
338
321
|
Object.defineProperty(exports, "havenClientIdentity", {
|
|
339
322
|
enumerable: true,
|
|
340
|
-
get: function () { return
|
|
323
|
+
get: function () { return chunkHFOAYTD4_cjs.havenClientIdentity; }
|
|
341
324
|
});
|
|
342
325
|
Object.defineProperty(exports, "isSupportedNodeVersion", {
|
|
343
326
|
enumerable: true,
|
|
344
|
-
get: function () { return
|
|
327
|
+
get: function () { return chunkHFOAYTD4_cjs.isSupportedNodeVersion; }
|
|
345
328
|
});
|
|
346
329
|
Object.defineProperty(exports, "isTaskChildTypedData", {
|
|
347
330
|
enumerable: true,
|
|
348
|
-
get: function () { return
|
|
331
|
+
get: function () { return chunkHFOAYTD4_cjs.isTaskChildTypedData; }
|
|
332
|
+
});
|
|
333
|
+
Object.defineProperty(exports, "principalAttributionHash", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function () { return chunkHFOAYTD4_cjs.principalAttributionHash; }
|
|
349
336
|
});
|
|
350
337
|
Object.defineProperty(exports, "readClientUpdate", {
|
|
351
338
|
enumerable: true,
|
|
352
|
-
get: function () { return
|
|
339
|
+
get: function () { return chunkHFOAYTD4_cjs.readClientUpdate; }
|
|
353
340
|
});
|
|
354
341
|
Object.defineProperty(exports, "selectStandardPaymentOption", {
|
|
355
342
|
enumerable: true,
|
|
356
|
-
get: function () { return
|
|
343
|
+
get: function () { return chunkHFOAYTD4_cjs.selectStandardPaymentOption; }
|
|
344
|
+
});
|
|
345
|
+
Object.defineProperty(exports, "signHash", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
get: function () { return chunkHFOAYTD4_cjs.signHash; }
|
|
348
|
+
});
|
|
349
|
+
Object.defineProperty(exports, "taxPrincipalId", {
|
|
350
|
+
enumerable: true,
|
|
351
|
+
get: function () { return chunkHFOAYTD4_cjs.taxPrincipalId; }
|
|
357
352
|
});
|
|
358
353
|
Object.defineProperty(exports, "toStandardPaymentRequirements", {
|
|
359
354
|
enumerable: true,
|
|
360
|
-
get: function () { return
|
|
355
|
+
get: function () { return chunkHFOAYTD4_cjs.toStandardPaymentRequirements; }
|
|
361
356
|
});
|
|
362
357
|
Object.defineProperty(exports, "unsupportedNodeVersionMessage", {
|
|
363
358
|
enumerable: true,
|
|
364
|
-
get: function () { return
|
|
359
|
+
get: function () { return chunkHFOAYTD4_cjs.unsupportedNodeVersionMessage; }
|
|
360
|
+
});
|
|
361
|
+
Object.defineProperty(exports, "verifySignature", {
|
|
362
|
+
enumerable: true,
|
|
363
|
+
get: function () { return chunkHFOAYTD4_cjs.verifySignature; }
|
|
364
|
+
});
|
|
365
|
+
Object.defineProperty(exports, "verifyTaxDeclarationSignature", {
|
|
366
|
+
enumerable: true,
|
|
367
|
+
get: function () { return chunkHFOAYTD4_cjs.verifyTaxDeclarationSignature; }
|
|
365
368
|
});
|
|
366
369
|
Object.defineProperty(exports, "x402AuthorizationAmount", {
|
|
367
370
|
enumerable: true,
|
|
368
|
-
get: function () { return
|
|
371
|
+
get: function () { return chunkHFOAYTD4_cjs.x402AuthorizationAmount; }
|
|
369
372
|
});
|
|
370
373
|
Object.defineProperty(exports, "x402V2PaymentEnvelope", {
|
|
371
374
|
enumerable: true,
|
|
372
|
-
get: function () { return
|
|
375
|
+
get: function () { return chunkHFOAYTD4_cjs.x402V2PaymentEnvelope; }
|
|
373
376
|
});
|
|
374
377
|
Object.defineProperty(exports, "AgentPaymentFailureCode", {
|
|
375
378
|
enumerable: true,
|
|
376
|
-
get: function () { return
|
|
379
|
+
get: function () { return chunkHX34HOW4_cjs.AgentPaymentFailureCode; }
|
|
377
380
|
});
|
|
378
381
|
Object.defineProperty(exports, "AgentPaymentNextAction", {
|
|
379
382
|
enumerable: true,
|
|
380
|
-
get: function () { return
|
|
383
|
+
get: function () { return chunkHX34HOW4_cjs.AgentPaymentNextAction; }
|
|
381
384
|
});
|
|
382
385
|
Object.defineProperty(exports, "CAVEAT_ENFORCERS", {
|
|
383
386
|
enumerable: true,
|
|
384
|
-
get: function () { return
|
|
387
|
+
get: function () { return chunkHX34HOW4_cjs.CAVEAT_ENFORCERS; }
|
|
385
388
|
});
|
|
386
389
|
Object.defineProperty(exports, "DELEGATION_MANAGER", {
|
|
387
390
|
enumerable: true,
|
|
388
|
-
get: function () { return
|
|
391
|
+
get: function () { return chunkHX34HOW4_cjs.DELEGATION_MANAGER; }
|
|
389
392
|
});
|
|
390
393
|
Object.defineProperty(exports, "DELEGATION_TUPLE_COMPONENTS", {
|
|
391
394
|
enumerable: true,
|
|
392
|
-
get: function () { return
|
|
395
|
+
get: function () { return chunkHX34HOW4_cjs.DELEGATION_TUPLE_COMPONENTS; }
|
|
393
396
|
});
|
|
394
397
|
Object.defineProperty(exports, "DIRECT_SIGN_CONTEXT_VERSION", {
|
|
395
398
|
enumerable: true,
|
|
396
|
-
get: function () { return
|
|
399
|
+
get: function () { return chunkHX34HOW4_cjs.DIRECT_SIGN_CONTEXT_VERSION; }
|
|
397
400
|
});
|
|
398
401
|
Object.defineProperty(exports, "ENTRY_POINT_V07", {
|
|
399
402
|
enumerable: true,
|
|
400
|
-
get: function () { return
|
|
403
|
+
get: function () { return chunkHX34HOW4_cjs.ENTRY_POINT_V07; }
|
|
401
404
|
});
|
|
402
405
|
Object.defineProperty(exports, "HAVEN_CONNECTOR_CHANNEL", {
|
|
403
406
|
enumerable: true,
|
|
404
|
-
get: function () { return
|
|
407
|
+
get: function () { return chunkHX34HOW4_cjs.HAVEN_CONNECTOR_CHANNEL; }
|
|
405
408
|
});
|
|
406
409
|
Object.defineProperty(exports, "HYBRID_DELEGATOR_IMPLEMENTATION", {
|
|
407
410
|
enumerable: true,
|
|
408
|
-
get: function () { return
|
|
411
|
+
get: function () { return chunkHX34HOW4_cjs.HYBRID_DELEGATOR_IMPLEMENTATION; }
|
|
409
412
|
});
|
|
410
413
|
Object.defineProperty(exports, "HavenApiError", {
|
|
411
414
|
enumerable: true,
|
|
412
|
-
get: function () { return
|
|
415
|
+
get: function () { return chunkHX34HOW4_cjs.HavenApiError; }
|
|
413
416
|
});
|
|
414
417
|
Object.defineProperty(exports, "HavenError", {
|
|
415
418
|
enumerable: true,
|
|
416
|
-
get: function () { return
|
|
419
|
+
get: function () { return chunkHX34HOW4_cjs.HavenError; }
|
|
417
420
|
});
|
|
418
421
|
Object.defineProperty(exports, "HavenSigningError", {
|
|
419
422
|
enumerable: true,
|
|
420
|
-
get: function () { return
|
|
423
|
+
get: function () { return chunkHX34HOW4_cjs.HavenSigningError; }
|
|
421
424
|
});
|
|
422
425
|
Object.defineProperty(exports, "HavenUnsupportedSignerVersionError", {
|
|
423
426
|
enumerable: true,
|
|
424
|
-
get: function () { return
|
|
427
|
+
get: function () { return chunkHX34HOW4_cjs.HavenUnsupportedSignerVersionError; }
|
|
425
428
|
});
|
|
426
429
|
Object.defineProperty(exports, "HavenUserOpBindingError", {
|
|
427
430
|
enumerable: true,
|
|
428
|
-
get: function () { return
|
|
431
|
+
get: function () { return chunkHX34HOW4_cjs.HavenUserOpBindingError; }
|
|
429
432
|
});
|
|
430
433
|
Object.defineProperty(exports, "MAX_SETTLEMENT_WINDOW_SECONDS", {
|
|
431
434
|
enumerable: true,
|
|
432
|
-
get: function () { return
|
|
435
|
+
get: function () { return chunkHX34HOW4_cjs.MAX_SETTLEMENT_WINDOW_SECONDS; }
|
|
433
436
|
});
|
|
434
437
|
Object.defineProperty(exports, "REDEEM_DELEGATIONS_ABI", {
|
|
435
438
|
enumerable: true,
|
|
436
|
-
get: function () { return
|
|
439
|
+
get: function () { return chunkHX34HOW4_cjs.REDEEM_DELEGATIONS_ABI; }
|
|
437
440
|
});
|
|
438
441
|
Object.defineProperty(exports, "ROOT_AUTHORITY", {
|
|
439
442
|
enumerable: true,
|
|
440
|
-
get: function () { return
|
|
443
|
+
get: function () { return chunkHX34HOW4_cjs.ROOT_AUTHORITY; }
|
|
441
444
|
});
|
|
442
445
|
Object.defineProperty(exports, "SIGNER_UPDATE_FALLBACK", {
|
|
443
446
|
enumerable: true,
|
|
444
|
-
get: function () { return
|
|
447
|
+
get: function () { return chunkHX34HOW4_cjs.SIGNER_UPDATE_FALLBACK; }
|
|
445
448
|
});
|
|
446
449
|
Object.defineProperty(exports, "SIMPLE_FACTORY_ADDRESS", {
|
|
447
450
|
enumerable: true,
|
|
448
|
-
get: function () { return
|
|
451
|
+
get: function () { return chunkHX34HOW4_cjs.SIMPLE_FACTORY_ADDRESS; }
|
|
449
452
|
});
|
|
450
453
|
Object.defineProperty(exports, "SINGLE_DEFAULT_MODE", {
|
|
451
454
|
enumerable: true,
|
|
452
|
-
get: function () { return
|
|
455
|
+
get: function () { return chunkHX34HOW4_cjs.SINGLE_DEFAULT_MODE; }
|
|
453
456
|
});
|
|
454
457
|
Object.defineProperty(exports, "SignerRefusalCode", {
|
|
455
458
|
enumerable: true,
|
|
456
|
-
get: function () { return
|
|
459
|
+
get: function () { return chunkHX34HOW4_cjs.SignerRefusalCode; }
|
|
457
460
|
});
|
|
458
461
|
Object.defineProperty(exports, "TASK_SIGN_CONTEXT_VERSION", {
|
|
459
462
|
enumerable: true,
|
|
460
|
-
get: function () { return
|
|
463
|
+
get: function () { return chunkHX34HOW4_cjs.TASK_SIGN_CONTEXT_VERSION; }
|
|
461
464
|
});
|
|
462
465
|
Object.defineProperty(exports, "assertRedeemsOwnBudgetDelegation", {
|
|
463
466
|
enumerable: true,
|
|
464
|
-
get: function () { return
|
|
467
|
+
get: function () { return chunkHX34HOW4_cjs.assertRedeemsOwnBudgetDelegation; }
|
|
465
468
|
});
|
|
466
469
|
Object.defineProperty(exports, "assertUserOpTypedDataBinding", {
|
|
467
470
|
enumerable: true,
|
|
468
|
-
get: function () { return
|
|
471
|
+
get: function () { return chunkHX34HOW4_cjs.assertUserOpTypedDataBinding; }
|
|
469
472
|
});
|
|
470
473
|
Object.defineProperty(exports, "chainIdForNetwork", {
|
|
471
474
|
enumerable: true,
|
|
472
|
-
get: function () { return
|
|
475
|
+
get: function () { return chunkHX34HOW4_cjs.chainIdForNetwork; }
|
|
473
476
|
});
|
|
474
477
|
Object.defineProperty(exports, "connectorRerunCommand", {
|
|
475
478
|
enumerable: true,
|
|
476
|
-
get: function () { return
|
|
479
|
+
get: function () { return chunkHX34HOW4_cjs.connectorRerunCommand; }
|
|
477
480
|
});
|
|
478
481
|
Object.defineProperty(exports, "connectorUpgradeCommand", {
|
|
479
482
|
enumerable: true,
|
|
480
|
-
get: function () { return
|
|
483
|
+
get: function () { return chunkHX34HOW4_cjs.connectorUpgradeCommand; }
|
|
481
484
|
});
|
|
482
485
|
Object.defineProperty(exports, "deriveDelegateAccountAddress", {
|
|
483
486
|
enumerable: true,
|
|
484
|
-
get: function () { return
|
|
487
|
+
get: function () { return chunkHX34HOW4_cjs.deriveDelegateAccountAddress; }
|
|
485
488
|
});
|
|
486
489
|
Object.defineProperty(exports, "isPackedUserOperationTypedData", {
|
|
487
490
|
enumerable: true,
|
|
488
|
-
get: function () { return
|
|
491
|
+
get: function () { return chunkHX34HOW4_cjs.isPackedUserOperationTypedData; }
|
|
489
492
|
});
|
|
490
493
|
Object.defineProperty(exports, "isSettlementChildTypedData", {
|
|
491
494
|
enumerable: true,
|
|
492
|
-
get: function () { return
|
|
495
|
+
get: function () { return chunkHX34HOW4_cjs.isSettlementChildTypedData; }
|
|
493
496
|
});
|
|
494
497
|
Object.defineProperty(exports, "packedUserOperationHash", {
|
|
495
498
|
enumerable: true,
|
|
496
|
-
get: function () { return
|
|
499
|
+
get: function () { return chunkHX34HOW4_cjs.packedUserOperationHash; }
|
|
497
500
|
});
|
|
498
501
|
Object.defineProperty(exports, "verifySettlementChild", {
|
|
499
502
|
enumerable: true,
|
|
500
|
-
get: function () { return
|
|
503
|
+
get: function () { return chunkHX34HOW4_cjs.verifySettlementChild; }
|
|
501
504
|
});
|
|
502
505
|
exports.ERC20_PERIOD_TRANSFER_ENFORCER = ERC20_PERIOD_TRANSFER_ENFORCER;
|
|
503
|
-
exports.addressFromKey = addressFromKey;
|
|
504
506
|
exports.assertOwnSubBudgetChild = assertOwnSubBudgetChild;
|
|
505
507
|
exports.assertOwnSubBudgetCloseUserOp = assertOwnSubBudgetCloseUserOp;
|
|
506
508
|
exports.hashSubBudgetDelegation = hashSubBudgetDelegation;
|
|
507
|
-
exports.signHash = signHash;
|
|
508
|
-
exports.verifySignature = verifySignature;
|
|
509
509
|
//# sourceMappingURL=edge.cjs.map
|
|
510
510
|
//# sourceMappingURL=edge.cjs.map
|
package/dist/edge.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/edge-signing.ts","../src/sub-budget-guards.ts"],"names":["privateKeyToAddress","HavenSigningError","secp256k1","serializeSignature","publicKeyToAddress","hashDelegation","HavenTypedDataRefusedError","DELEGATION_MANAGER","DIRECT_PAYMENT_CHAIN_IDS","deriveDelegateAccountAddress","ROOT_AUTHORITY","CAVEAT_ENFORCERS","assertOwnTaskBudgetCloseUserOp"],"mappings":";;;;;;;;AAsBA,IAAM,MAAA,GAAS,OAAO,oEAAoE,CAAA;AAW1F,SAAS,QAAA,CAAS,KAAA,EAAe,KAAA,EAAe,IAAA,EAAsB;AACpE,EAAA,IAAI,CAAC,mBAAmB,IAAA,CAAK,KAAK,KAAK,KAAA,CAAM,MAAA,KAAW,CAAA,GAAI,KAAA,GAAQ,CAAA,EAAG;AACrE,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,IAAI,CAAA,uBAAA,EAA0B,KAAK,CAAA,gBAAA,CAAkB,CAAA;AAAA,EAC1E;AACA,EAAA,OAAO,KAA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{ secp256k1 } from '@noble/curves/secp256k1'\nimport { privateKeyToAddress, publicKeyToAddress } from 'viem/accounts'\nimport { serializeSignature, type Hex } from 'viem'\nimport { HavenSigningError } from './types.js'\n\n/**\n * #3173: the three key helpers the edge signer needs, without ethers.\n *\n * `./signer.ts` implements the same three on ethers, and the SDK barrel pulls\n * ethers in for them (and for `provider.ts` / `receipt.ts`). The edge signer\n * already ships viem, and viem signs with `@noble/curves` underneath — these\n * use the same curve library directly, synchronously (viem's own `sign` is\n * async), so `@haven_ai/sdk/edge` stays ethers-free and a signer session stops\n * paying for module init it never uses. Byte-equivalence with the ethers forms\n * is pinned in `edge-signing.test.ts`: same address, same 65-byte `r‖s‖v`\n * serialisation with low-s and v = 27/28, same recovery verdicts, and the same\n * refusals (high-s twin, wrong lengths) — with three stated strict-direction\n * exceptions, see `hexBytes`. Raw ECDSA over the hash — never the EIP-191\n * prefixed digest.\n */\n\n/** secp256k1 order / 2 — a signature with s above this is the malleable twin ethers rejects. */\nconst HALF_N = BigInt('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0')\n\n/**\n * Stricter than ethers, never looser: the lowercase `0x` prefix and the exact\n * byte length are required. Ethers accepts an uppercase `0X` prefix on a\n * signature and the 64-byte EIP-2098 compact form, and is inconsistent on a\n * private key (`Wallet` accepts unprefixed and refuses `0X`; `SigningKey` does\n * the reverse); every such form is refused here — the divergences are pinned\n * in `edge-signing.test.ts` with ethers control assertions, and every\n * well-formed input is byte-equivalent.\n */\nfunction hexBytes(value: string, bytes: number, what: string): string {\n if (!/^0x[0-9a-fA-F]+$/.test(value) || value.length !== 2 + bytes * 2) {\n throw new Error(`${what} must be a 0x-prefixed ${bytes}-byte hex string`)\n }\n return value.slice(2)\n}\n\nexport function addressFromKey(privateKey: string): string {\n try {\n // Same gate as signHash: a key that derives an address must also sign.\n return privateKeyToAddress(`0x${hexBytes(privateKey, 32, 'private key')}`)\n } catch (err) {\n throw new HavenSigningError(\n `Invalid private key: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n}\n\nexport function signHash(privateKey: string, hash: string): string {\n try {\n const { r, s, recovery } = secp256k1.sign(hexBytes(hash, 32, 'hash'), hexBytes(privateKey, 32, 'private key'), { lowS: true })\n // viem serialises the trailing byte from yParity (0/1 → 27/28), the same\n // `v` ethers' `Signature.serialized` writes.\n return serializeSignature({\n r: `0x${r.toString(16).padStart(64, '0')}`,\n s: `0x${s.toString(16).padStart(64, '0')}`,\n yParity: recovery,\n })\n } catch (err) {\n throw new HavenSigningError(\n `Failed to sign hash: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n}\n\nexport function verifySignature(hash: string, signature: string, expectedAddress: string): boolean {\n try {\n const sig = hexBytes(signature, 65, 'signature')\n const hashHex = hexBytes(hash, 32, 'hash')\n // Reject the high-s malleable twin, as ethers does — one signature per message.\n if (BigInt(`0x${sig.slice(64, 128)}`) > HALF_N) return false\n const yParityOrV = Number.parseInt(sig.slice(128), 16)\n const recoveryBit = yParityOrV === 0 || yParityOrV === 27 ? 0 : yParityOrV === 1 || yParityOrV === 28 ? 1 : -1\n if (recoveryBit < 0) return false\n const publicKey = secp256k1.Signature.fromCompact(sig.slice(0, 128))\n .addRecoveryBit(recoveryBit)\n .recoverPublicKey(hashHex)\n .toHex(false)\n const recovered = publicKeyToAddress(`0x${publicKey}`)\n return recovered.toLowerCase() === expectedAddress.toLowerCase()\n } catch {\n return false\n }\n}\n","/**\n * Sub-budget child guards (#3330) — the SDK-side local verification the\n * signer runs before its delegate key signs a sub-budget child, mirroring\n * `task-budget-guards.ts`'s `assertOwnTaskChild` for the two-row sub-budget\n * tree. ONE verifier covers BOTH rows, because the same signer (the\n * delegating agent A's own key) signs both:\n *\n * - A's PARENT-CHILD row: `delegate === delegator === A's own account`\n * (self-delegated, the task-child shape class).\n * - B's GRANT row: `delegator === A's own account`, `delegate === B's\n * delegate account` (a real grant to another account).\n *\n * What makes a sub-budget child a sub-budget child (vs a task budget's\n * hard-cap child) is the AMOUNT caveat: an `ERC20PeriodTransferEnforcer`\n * caveat whose terms are `abi.encode(address token, uint256 periodAmount,\n * uint256 periodDuration, uint256 startDate)` — the period-scoped slice of\n * the parent's own period meter, with the parent's periodDuration and\n * startDate reused verbatim. A hard-cap `ERC20TransferAmountEnforcer` caveat\n * is refused: that would be a task budget, which this channel must never\n * sign (two different products, two different sign-context endpoints).\n *\n * Authority, timestamp and recipient-pin checks are byte-for-byte the\n * task-child discipline: authority must equal the declared parent hash and\n * never be ROOT; expiry must be in the future and equal the declared one; a\n * pinned recipient must match exactly, and an unpinned budget must not grow\n * one. Enforcers are the pinned constants from `settlement-child.ts` (no kit\n * dependency) — same reasoning as that file's header documents.\n */\n\nimport { type Address, type Hex } from 'viem'\nimport { HavenTypedDataRefusedError, DIRECT_PAYMENT_CHAIN_IDS } from './direct-payment-guard.js'\nimport { DELEGATION_MANAGER, ROOT_AUTHORITY, CAVEAT_ENFORCERS } from './settlement-child.js'\nimport { deriveDelegateAccountAddress } from './delegate-account.js'\nimport {\n DELEGATION_TYPEHASH,\n CAVEAT_TYPEHASH,\n hashDelegation,\n type DelegationForHashing,\n} from './task-budget-guards.js'\n\n/** The pinned `ERC20PeriodTransferEnforcer` (bytecode-identical on Base + Base Sepolia). */\nexport const ERC20_PERIOD_TRANSFER_ENFORCER = '0x474e3Ae7E169e940607cC624Da8A15Eb120139aB'\n\n/** The pinned `Delegation` EIP-712 domain (cross-checked by task-budget-guards' pin test). */\nconst DELEGATION_DOMAIN_NAME = 'DelegationManager'\nconst DELEGATION_DOMAIN_VERSION = '1'\n\n/** The pinned `types` shape, byte-identical to `task-budget-guards.ts`'s. */\nconst EXPECTED_DELEGATION_TYPES = {\n Caveat: [\n { name: 'enforcer', type: 'address' },\n { name: 'terms', type: 'bytes' },\n ],\n Delegation: [\n { name: 'delegate', type: 'address' },\n { name: 'delegator', type: 'address' },\n { name: 'authority', type: 'bytes32' },\n { name: 'caveats', type: 'Caveat[]' },\n { name: 'salt', type: 'uint256' },\n ],\n} as const\n\nexport interface SubBudgetChildTypedData {\n domain: { name?: string; version?: string; chainId?: number | string; verifyingContract?: string }\n types: Record<string, unknown>\n primaryType: string\n message: Record<string, unknown>\n}\n\nfunction same(a: string | undefined, b: string | undefined): boolean {\n return !!a && !!b && a.toLowerCase() === b.toLowerCase()\n}\n\n/** Byte slice [start, end) of a `0x…` string, as lowercase hex without prefix. */\nfunction sliceTerms(terms: string, start: number, end?: number): string {\n const body = terms.startsWith('0x') ? terms.slice(2).toLowerCase() : terms.toLowerCase()\n return end === undefined ? body.slice(start * 2) : body.slice(start * 2, end * 2)\n}\n\nfunction findCaveat(caveats: Array<{ enforcer: string; terms: string }>, enforcer: string) {\n return caveats.find((c) => same(c.enforcer, enforcer))\n}\n\n/** The struct hash of a sub-budget child — the redemption chain's link value. */\nexport function hashSubBudgetDelegation(delegation: DelegationForHashing): Hex {\n return hashDelegation(delegation)\n}\n\n// The kit's own struct hashes, re-exported verbatim from task-budget-guards'\n// pinned literals so a caller can name them from this module too.\nexport { DELEGATION_TYPEHASH, CAVEAT_TYPEHASH }\n\nexport interface SubBudgetChildExpectation {\n chainId: number\n tokenAddress: string\n /** Per-period amount in atomic units — the child's periodAmount. */\n periodAmountAtomic: string\n /** The PARENT's period duration (seconds), reused verbatim in the caveat. */\n periodDurationSeconds: number\n /** The PARENT's period anchor, reused verbatim in the caveat. */\n startDate: number\n recipientAddress: string | null\n /** unix seconds — the `TimestampEnforcer`'s `beforeThreshold`. */\n expiresAt: number\n /** The hash of the row's parent delegation (`parent_delegation_hash`). */\n parentDelegationHash: string\n /**\n * A's own derived delegate account — the child's `delegator` on BOTH rows.\n */\n delegateAccount: string\n /**\n * The row's own `delegate`: A's account again for the parent-child row,\n * B's delegate account for the grant row. Served in the sign-context's\n * `expected` (read from the stored child JSON, not trusted caller input).\n */\n childDelegateAccount: string\n}\n\nfunction refuseSubBudgetChild(what: string, detail: string): never {\n throw new HavenTypedDataRefusedError(\n `Refusing to sign the sub-budget child: ${what}. ${detail} ` +\n 'This signature opens a slice of the delegating agent budget for another agent, so it is ' +\n 'verified locally against the expectation Haven declared, rather than trusted.',\n )\n}\n\n/**\n * Verify a sub-budget child delegation is EXACTLY what\n * `GET /sub-budgets/:id/sign-context` (purpose `open`) declared, that its\n * `delegator` is this signer's own account, and that its `delegate` is the\n * declared child delegate. Throws `HavenTypedDataRefusedError` (never\n * returns) on any disagreement.\n */\nexport function assertOwnSubBudgetChild(\n typedData: unknown,\n expected: SubBudgetChildExpectation,\n delegateAddress: string,\n now: number = Date.now(),\n): void {\n const td = typedData as SubBudgetChildTypedData\n if (td?.primaryType !== 'Delegation') {\n refuseSubBudgetChild('it is not a Delegation payload', `primaryType was '${String(td?.primaryType)}'.`)\n }\n if (!same(td.domain?.verifyingContract, DELEGATION_MANAGER)) {\n refuseSubBudgetChild(\n 'the EIP-712 domain names an unknown DelegationManager',\n `Expected ${DELEGATION_MANAGER}, got ${td.domain?.verifyingContract}.`,\n )\n }\n if (td.domain?.name !== DELEGATION_DOMAIN_NAME || td.domain?.version !== DELEGATION_DOMAIN_VERSION) {\n refuseSubBudgetChild(\n 'the EIP-712 domain name/version does not match the pinned DelegationManager domain',\n `Expected name '${DELEGATION_DOMAIN_NAME}' version '${DELEGATION_DOMAIN_VERSION}'; got name ` +\n `'${String(td.domain?.name)}' version '${String(td.domain?.version)}'.`,\n )\n }\n if (\n JSON.stringify(td.types?.Caveat) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Caveat) ||\n JSON.stringify(td.types?.Delegation) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Delegation)\n ) {\n refuseSubBudgetChild(\n 'its EIP-712 type definitions do not match the pinned Delegation/Caveat shape',\n 'A renamed, reordered, or additional field on Delegation or Caveat could change what the ' +\n 'caveats below mean without changing this check\\'s field-by-field comparisons.',\n )\n }\n const domainChain = Number(td.domain?.chainId)\n if (!Number.isFinite(domainChain) || !DIRECT_PAYMENT_CHAIN_IDS.has(domainChain)) {\n refuseSubBudgetChild(\n 'it is scoped to a chain the delegation rail has no pinned contracts for',\n `Chains with pinned contracts: ${[...DIRECT_PAYMENT_CHAIN_IDS].join(', ')}; the child says ${String(td.domain?.chainId)}.`,\n )\n }\n if (domainChain !== expected.chainId) {\n refuseSubBudgetChild(\n 'it is scoped to the wrong chain',\n `Expected chain ${expected.chainId}; the child says ${td.domain?.chainId}.`,\n )\n }\n\n const ownAccount = deriveDelegateAccountAddress(delegateAddress as Address)\n const delegator = td.message?.delegator\n if (typeof delegator !== 'string' || !same(delegator, ownAccount)) {\n refuseSubBudgetChild(\n \"it is not delegated by this agent's own account\",\n `Expected delegator ${ownAccount}; the child names ${String(delegator)}.`,\n )\n }\n if (!same(delegator, expected.delegateAccount)) {\n refuseSubBudgetChild(\n 'its delegator does not match the account Haven declared',\n `Expected ${expected.delegateAccount}; the child names ${String(delegator)}.`,\n )\n }\n const delegate = td.message?.delegate\n if (typeof delegate !== 'string' || !same(delegate, expected.childDelegateAccount)) {\n refuseSubBudgetChild(\n 'its delegate does not match the declared child delegate',\n `Expected ${expected.childDelegateAccount}; the child names ${String(delegate)}.`,\n )\n }\n\n const authority = td.message?.authority\n if (typeof authority !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(authority)) {\n refuseSubBudgetChild('its authority is not a 32-byte delegation hash', `Got ${String(authority)}.`)\n }\n if (authority.toLowerCase() === ROOT_AUTHORITY) {\n refuseSubBudgetChild(\n 'it is a ROOT delegation, not a re-delegation of the delegating agent budget',\n 'A sub-budget always chains under the delegating agent budget delegation.',\n )\n }\n if (!same(authority, expected.parentDelegationHash)) {\n refuseSubBudgetChild(\n 'it chains under a different parent delegation',\n `Expected authority ${expected.parentDelegationHash}; the child says ${authority}.`,\n )\n }\n\n const caveats = (td.message?.caveats as Array<{ enforcer: string; terms: string }> | undefined) ?? []\n\n // The PERIOD caveat is what makes this a sub-budget — a hard-cap\n // `ERC20TransferAmountEnforcer` caveat is the task-budget shape and is\n // refused on this channel.\n if (findCaveat(caveats, CAVEAT_ENFORCERS.erc20TransferAmount)) {\n refuseSubBudgetChild(\n 'it carries a hard-cap transfer-amount caveat (the task-budget shape)',\n 'A sub-budget is period-scoped: its amount caveat must be an ERC20PeriodTransferEnforcer ' +\n 'caveat slicing the parent period meter, never a lifetime cap.',\n )\n }\n const period = findCaveat(caveats, ERC20_PERIOD_TRANSFER_ENFORCER)\n if (!period) {\n refuseSubBudgetChild(\n 'it has no ERC-20 period-transfer caveat',\n 'Without it the child is not bounded to a per-period amount.',\n )\n }\n // terms = abi.encodePacked(address token, uint256 periodAmount,\n // uint256 periodDuration, uint256 startDate) — the kit's TIGHT packing\n // (20 + 32×3 = 116 bytes, verified against `createDelegation`'s own\n // output), the same layout `task-budget-guards.ts` decodes for the\n // ERC20TransferAmountEnforcer. NOT head/tail-padded words: the address\n // occupies bytes [0,20) and the amount starts at byte 20.\n const token = `0x${sliceTerms(period.terms, 0, 20)}`\n if (!same(token, expected.tokenAddress)) {\n refuseSubBudgetChild('it spends a different token', `Expected ${expected.tokenAddress}, child pins ${token}.`)\n }\n const periodAmount = BigInt(`0x${sliceTerms(period.terms, 20, 52)}`)\n if (periodAmount !== BigInt(expected.periodAmountAtomic)) {\n refuseSubBudgetChild(\n 'the period amount does not match',\n `Expected ${expected.periodAmountAtomic}; the child allows ${periodAmount.toString()}.`,\n )\n }\n const periodDuration = Number(BigInt(`0x${sliceTerms(period.terms, 52, 84)}`))\n if (periodDuration !== expected.periodDurationSeconds) {\n refuseSubBudgetChild(\n 'its period duration does not match the parent window Haven declared',\n `Expected ${expected.periodDurationSeconds}s; the child says ${periodDuration}s. A sub-budget is a ` +\n 'slice of the parent period meter — same window, smaller amount — never a different clock.',\n )\n }\n const startDate = Number(BigInt(`0x${sliceTerms(period.terms, 84, 116)}`))\n if (startDate !== expected.startDate) {\n refuseSubBudgetChild(\n 'its period start does not match the parent anchor Haven declared',\n `Expected ${expected.startDate}; the child says ${startDate}.`,\n )\n }\n\n const timestamp = findCaveat(caveats, CAVEAT_ENFORCERS.timestamp)\n if (!timestamp) {\n refuseSubBudgetChild('it never expires', 'A sub-budget child without a timestamp caveat is open-ended.')\n }\n const beforeThreshold = Number(BigInt(`0x${sliceTerms(timestamp.terms, 16, 32)}`))\n const nowSec = Math.floor(now / 1000)\n if (beforeThreshold <= nowSec) {\n refuseSubBudgetChild('it has already expired', `Expiry ${beforeThreshold} is not in the future.`)\n }\n if (beforeThreshold !== expected.expiresAt) {\n refuseSubBudgetChild(\n 'its expiry does not match what Haven declared',\n `Expected ${expected.expiresAt}; the child says ${beforeThreshold}.`,\n )\n }\n\n const calldata = findCaveat(caveats, CAVEAT_ENFORCERS.allowedCalldata)\n if (expected.recipientAddress) {\n if (!calldata) {\n refuseSubBudgetChild(\n 'it has no recipient pin',\n 'The sub-budget was issued with a pinned recipient, so the child must carry one.',\n )\n }\n const startIndex = BigInt(`0x${sliceTerms(calldata.terms, 0, 32)}`)\n if (startIndex !== 4n) {\n refuseSubBudgetChild(\n 'the recipient pin points at the wrong calldata offset',\n `Expected offset 4, got ${startIndex.toString()}.`,\n )\n }\n const paddedRecipient = sliceTerms(calldata.terms, 32, 64)\n if (paddedRecipient.slice(0, 24) !== '0'.repeat(24)) {\n refuseSubBudgetChild('the pinned recipient is not a plain address', 'Its 32-byte word is not a padded address.')\n }\n const recipient = `0x${paddedRecipient.slice(24)}`\n if (!same(recipient, expected.recipientAddress)) {\n refuseSubBudgetChild(\n 'it pins a different recipient than Haven declared',\n `Expected ${expected.recipientAddress}; the child pins ${recipient}.`,\n )\n }\n } else if (calldata) {\n refuseSubBudgetChild(\n 'it pins a recipient the sub-budget was not issued with',\n 'This sub-budget is open (no recipient pin); the child must not add one.',\n )\n }\n}\n\n/** Close UserOp verification — byte-for-byte the task-budget discipline. */\nexport function assertOwnSubBudgetCloseUserOp(\n typedData: Record<string, unknown>,\n expected: { delegationHash: string },\n delegateAddress: string,\n): void {\n // The close UserOp shape is identical to the task budget's: a\n // disableDelegation(child) call from the agent's own delegate account.\n // Reuse the task-budget verifier — the only expectation that differs is\n // the delegation hash, which is an input here either way. Static import,\n // not lazy: these modules share no init-time cycle.\n assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress)\n}\n\n// The close-UserOp verifier is imported for the re-export above.\nimport { assertOwnTaskBudgetCloseUserOp } from './task-budget-guards.js'\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/sub-budget-guards.ts"],"names":["hashDelegation","HavenTypedDataRefusedError","DELEGATION_MANAGER","DIRECT_PAYMENT_CHAIN_IDS","deriveDelegateAccountAddress","ROOT_AUTHORITY","CAVEAT_ENFORCERS","assertOwnTaskBudgetCloseUserOp"],"mappings":";;;;;;AAyCO,IAAM,8BAAA,GAAiC;AAG9C,IAAM,sBAAA,GAAyB,mBAAA;AAC/B,IAAM,yBAAA,GAA4B,GAAA;AAGlC,IAAM,yBAAA,GAA4B;AAAA,EAChC,MAAA,EAAQ;AAAA,IACN,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,SAAA,EAAU;AAAA,IACpC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,OAAA;AAAQ,GACjC;AAAA,EACA,UAAA,EAAY;AAAA,IACV,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,SAAA,EAAU;AAAA,IACpC,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,SAAA,EAAU;AAAA,IACrC,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,SAAA,EAAU;AAAA,IACrC,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,UAAA,EAAW;AAAA,IACpC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA;AAAU;AAEpC,CAAA;AASA,SAAS,IAAA,CAAK,GAAuB,CAAA,EAAgC;AACnE,EAAA,OAAO,CAAC,CAAC,CAAA,IAAK,CAAC,CAAC,KAAK,CAAA,CAAE,WAAA,EAAY,KAAM,CAAA,CAAE,WAA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AAO,EAAE,CAAA,EAAG;AACnD,MAAA,oBAAA,CAAqB,+CAA+C,2CAA2C,CAAA;AAAA,IACjH;AACA,IAAA,MAAM,SAAA,GAAY,CAAA,EAAA,EAAK,eAAA,CAAgB,KAAA,CAAM,EAAE,CAAC,CAAA,CAAA;AAChD,IAAA,IAAI,CAAC,IAAA,CAAK,SAAA,EAAW,QAAA,CAAS,gBAAgB,CAAA,EAAG;AAC/C,MAAA,oBAAA;AAAA,QACE,mDAAA;AAAA,QACA,CAAA,SAAA,EAAY,QAAA,CAAS,gBAAgB,CAAA,iBAAA,EAAoB,SAAS,CAAA,CAAA;AAAA,OACpE;AAAA,IACF;AAAA,EACF,WAAW,QAAA,EAAU;AACnB,IAAA,oBAAA;AAAA,MACE,wDAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF;AAGO,SAAS,6BAAA,CACd,SAAA,EACA,QAAA,EACA,eAAA,EACM;AAMN,EAAAC,gDAAA,CAA+B,SAAA,EAAW,UAAU,eAAe,CAAA;AACrE","file":"edge.cjs","sourcesContent":["/**\n * Sub-budget child guards (#3330) — the SDK-side local verification the\n * signer runs before its delegate key signs a sub-budget child, mirroring\n * `task-budget-guards.ts`'s `assertOwnTaskChild` for the two-row sub-budget\n * tree. ONE verifier covers BOTH rows, because the same signer (the\n * delegating agent A's own key) signs both:\n *\n * - A's PARENT-CHILD row: `delegate === delegator === A's own account`\n * (self-delegated, the task-child shape class).\n * - B's GRANT row: `delegator === A's own account`, `delegate === B's\n * delegate account` (a real grant to another account).\n *\n * What makes a sub-budget child a sub-budget child (vs a task budget's\n * hard-cap child) is the AMOUNT caveat: an `ERC20PeriodTransferEnforcer`\n * caveat whose terms are `abi.encode(address token, uint256 periodAmount,\n * uint256 periodDuration, uint256 startDate)` — the period-scoped slice of\n * the parent's own period meter, with the parent's periodDuration and\n * startDate reused verbatim. A hard-cap `ERC20TransferAmountEnforcer` caveat\n * is refused: that would be a task budget, which this channel must never\n * sign (two different products, two different sign-context endpoints).\n *\n * Authority, timestamp and recipient-pin checks are byte-for-byte the\n * task-child discipline: authority must equal the declared parent hash and\n * never be ROOT; expiry must be in the future and equal the declared one; a\n * pinned recipient must match exactly, and an unpinned budget must not grow\n * one. Enforcers are the pinned constants from `settlement-child.ts` (no kit\n * dependency) — same reasoning as that file's header documents.\n */\n\nimport { type Address, type Hex } from 'viem'\nimport { HavenTypedDataRefusedError, DIRECT_PAYMENT_CHAIN_IDS } from './direct-payment-guard.js'\nimport { DELEGATION_MANAGER, ROOT_AUTHORITY, CAVEAT_ENFORCERS } from './settlement-child.js'\nimport { deriveDelegateAccountAddress } from './delegate-account.js'\nimport {\n DELEGATION_TYPEHASH,\n CAVEAT_TYPEHASH,\n hashDelegation,\n type DelegationForHashing,\n} from './task-budget-guards.js'\n\n/** The pinned `ERC20PeriodTransferEnforcer` (bytecode-identical on Base + Base Sepolia). */\nexport const ERC20_PERIOD_TRANSFER_ENFORCER = '0x474e3Ae7E169e940607cC624Da8A15Eb120139aB'\n\n/** The pinned `Delegation` EIP-712 domain (cross-checked by task-budget-guards' pin test). */\nconst DELEGATION_DOMAIN_NAME = 'DelegationManager'\nconst DELEGATION_DOMAIN_VERSION = '1'\n\n/** The pinned `types` shape, byte-identical to `task-budget-guards.ts`'s. */\nconst EXPECTED_DELEGATION_TYPES = {\n Caveat: [\n { name: 'enforcer', type: 'address' },\n { name: 'terms', type: 'bytes' },\n ],\n Delegation: [\n { name: 'delegate', type: 'address' },\n { name: 'delegator', type: 'address' },\n { name: 'authority', type: 'bytes32' },\n { name: 'caveats', type: 'Caveat[]' },\n { name: 'salt', type: 'uint256' },\n ],\n} as const\n\nexport interface SubBudgetChildTypedData {\n domain: { name?: string; version?: string; chainId?: number | string; verifyingContract?: string }\n types: Record<string, unknown>\n primaryType: string\n message: Record<string, unknown>\n}\n\nfunction same(a: string | undefined, b: string | undefined): boolean {\n return !!a && !!b && a.toLowerCase() === b.toLowerCase()\n}\n\n/** Byte slice [start, end) of a `0x…` string, as lowercase hex without prefix. */\nfunction sliceTerms(terms: string, start: number, end?: number): string {\n const body = terms.startsWith('0x') ? terms.slice(2).toLowerCase() : terms.toLowerCase()\n return end === undefined ? body.slice(start * 2) : body.slice(start * 2, end * 2)\n}\n\nfunction findCaveat(caveats: Array<{ enforcer: string; terms: string }>, enforcer: string) {\n return caveats.find((c) => same(c.enforcer, enforcer))\n}\n\n/** The struct hash of a sub-budget child — the redemption chain's link value. */\nexport function hashSubBudgetDelegation(delegation: DelegationForHashing): Hex {\n return hashDelegation(delegation)\n}\n\n// The kit's own struct hashes, re-exported verbatim from task-budget-guards'\n// pinned literals so a caller can name them from this module too.\nexport { DELEGATION_TYPEHASH, CAVEAT_TYPEHASH }\n\nexport interface SubBudgetChildExpectation {\n chainId: number\n tokenAddress: string\n /** Per-period amount in atomic units — the child's periodAmount. */\n periodAmountAtomic: string\n /** The PARENT's period duration (seconds), reused verbatim in the caveat. */\n periodDurationSeconds: number\n /** The PARENT's period anchor, reused verbatim in the caveat. */\n startDate: number\n recipientAddress: string | null\n /** unix seconds — the `TimestampEnforcer`'s `beforeThreshold`. */\n expiresAt: number\n /** The hash of the row's parent delegation (`parent_delegation_hash`). */\n parentDelegationHash: string\n /**\n * A's own derived delegate account — the child's `delegator` on BOTH rows.\n */\n delegateAccount: string\n /**\n * The row's own `delegate`: A's account again for the parent-child row,\n * B's delegate account for the grant row. Served in the sign-context's\n * `expected` (read from the stored child JSON, not trusted caller input).\n */\n childDelegateAccount: string\n}\n\nfunction refuseSubBudgetChild(what: string, detail: string): never {\n throw new HavenTypedDataRefusedError(\n `Refusing to sign the sub-budget child: ${what}. ${detail} ` +\n 'This signature opens a slice of the delegating agent budget for another agent, so it is ' +\n 'verified locally against the expectation Haven declared, rather than trusted.',\n )\n}\n\n/**\n * Verify a sub-budget child delegation is EXACTLY what\n * `GET /sub-budgets/:id/sign-context` (purpose `open`) declared, that its\n * `delegator` is this signer's own account, and that its `delegate` is the\n * declared child delegate. Throws `HavenTypedDataRefusedError` (never\n * returns) on any disagreement.\n */\nexport function assertOwnSubBudgetChild(\n typedData: unknown,\n expected: SubBudgetChildExpectation,\n delegateAddress: string,\n now: number = Date.now(),\n): void {\n const td = typedData as SubBudgetChildTypedData\n if (td?.primaryType !== 'Delegation') {\n refuseSubBudgetChild('it is not a Delegation payload', `primaryType was '${String(td?.primaryType)}'.`)\n }\n if (!same(td.domain?.verifyingContract, DELEGATION_MANAGER)) {\n refuseSubBudgetChild(\n 'the EIP-712 domain names an unknown DelegationManager',\n `Expected ${DELEGATION_MANAGER}, got ${td.domain?.verifyingContract}.`,\n )\n }\n if (td.domain?.name !== DELEGATION_DOMAIN_NAME || td.domain?.version !== DELEGATION_DOMAIN_VERSION) {\n refuseSubBudgetChild(\n 'the EIP-712 domain name/version does not match the pinned DelegationManager domain',\n `Expected name '${DELEGATION_DOMAIN_NAME}' version '${DELEGATION_DOMAIN_VERSION}'; got name ` +\n `'${String(td.domain?.name)}' version '${String(td.domain?.version)}'.`,\n )\n }\n if (\n JSON.stringify(td.types?.Caveat) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Caveat) ||\n JSON.stringify(td.types?.Delegation) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Delegation)\n ) {\n refuseSubBudgetChild(\n 'its EIP-712 type definitions do not match the pinned Delegation/Caveat shape',\n 'A renamed, reordered, or additional field on Delegation or Caveat could change what the ' +\n 'caveats below mean without changing this check\\'s field-by-field comparisons.',\n )\n }\n const domainChain = Number(td.domain?.chainId)\n if (!Number.isFinite(domainChain) || !DIRECT_PAYMENT_CHAIN_IDS.has(domainChain)) {\n refuseSubBudgetChild(\n 'it is scoped to a chain the delegation rail has no pinned contracts for',\n `Chains with pinned contracts: ${[...DIRECT_PAYMENT_CHAIN_IDS].join(', ')}; the child says ${String(td.domain?.chainId)}.`,\n )\n }\n if (domainChain !== expected.chainId) {\n refuseSubBudgetChild(\n 'it is scoped to the wrong chain',\n `Expected chain ${expected.chainId}; the child says ${td.domain?.chainId}.`,\n )\n }\n\n const ownAccount = deriveDelegateAccountAddress(delegateAddress as Address)\n const delegator = td.message?.delegator\n if (typeof delegator !== 'string' || !same(delegator, ownAccount)) {\n refuseSubBudgetChild(\n \"it is not delegated by this agent's own account\",\n `Expected delegator ${ownAccount}; the child names ${String(delegator)}.`,\n )\n }\n if (!same(delegator, expected.delegateAccount)) {\n refuseSubBudgetChild(\n 'its delegator does not match the account Haven declared',\n `Expected ${expected.delegateAccount}; the child names ${String(delegator)}.`,\n )\n }\n const delegate = td.message?.delegate\n if (typeof delegate !== 'string' || !same(delegate, expected.childDelegateAccount)) {\n refuseSubBudgetChild(\n 'its delegate does not match the declared child delegate',\n `Expected ${expected.childDelegateAccount}; the child names ${String(delegate)}.`,\n )\n }\n\n const authority = td.message?.authority\n if (typeof authority !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(authority)) {\n refuseSubBudgetChild('its authority is not a 32-byte delegation hash', `Got ${String(authority)}.`)\n }\n if (authority.toLowerCase() === ROOT_AUTHORITY) {\n refuseSubBudgetChild(\n 'it is a ROOT delegation, not a re-delegation of the delegating agent budget',\n 'A sub-budget always chains under the delegating agent budget delegation.',\n )\n }\n if (!same(authority, expected.parentDelegationHash)) {\n refuseSubBudgetChild(\n 'it chains under a different parent delegation',\n `Expected authority ${expected.parentDelegationHash}; the child says ${authority}.`,\n )\n }\n\n const caveats = (td.message?.caveats as Array<{ enforcer: string; terms: string }> | undefined) ?? []\n\n // The PERIOD caveat is what makes this a sub-budget — a hard-cap\n // `ERC20TransferAmountEnforcer` caveat is the task-budget shape and is\n // refused on this channel.\n if (findCaveat(caveats, CAVEAT_ENFORCERS.erc20TransferAmount)) {\n refuseSubBudgetChild(\n 'it carries a hard-cap transfer-amount caveat (the task-budget shape)',\n 'A sub-budget is period-scoped: its amount caveat must be an ERC20PeriodTransferEnforcer ' +\n 'caveat slicing the parent period meter, never a lifetime cap.',\n )\n }\n const period = findCaveat(caveats, ERC20_PERIOD_TRANSFER_ENFORCER)\n if (!period) {\n refuseSubBudgetChild(\n 'it has no ERC-20 period-transfer caveat',\n 'Without it the child is not bounded to a per-period amount.',\n )\n }\n // terms = abi.encodePacked(address token, uint256 periodAmount,\n // uint256 periodDuration, uint256 startDate) — the kit's TIGHT packing\n // (20 + 32×3 = 116 bytes, verified against `createDelegation`'s own\n // output), the same layout `task-budget-guards.ts` decodes for the\n // ERC20TransferAmountEnforcer. NOT head/tail-padded words: the address\n // occupies bytes [0,20) and the amount starts at byte 20.\n const token = `0x${sliceTerms(period.terms, 0, 20)}`\n if (!same(token, expected.tokenAddress)) {\n refuseSubBudgetChild('it spends a different token', `Expected ${expected.tokenAddress}, child pins ${token}.`)\n }\n const periodAmount = BigInt(`0x${sliceTerms(period.terms, 20, 52)}`)\n if (periodAmount !== BigInt(expected.periodAmountAtomic)) {\n refuseSubBudgetChild(\n 'the period amount does not match',\n `Expected ${expected.periodAmountAtomic}; the child allows ${periodAmount.toString()}.`,\n )\n }\n const periodDuration = Number(BigInt(`0x${sliceTerms(period.terms, 52, 84)}`))\n if (periodDuration !== expected.periodDurationSeconds) {\n refuseSubBudgetChild(\n 'its period duration does not match the parent window Haven declared',\n `Expected ${expected.periodDurationSeconds}s; the child says ${periodDuration}s. A sub-budget is a ` +\n 'slice of the parent period meter — same window, smaller amount — never a different clock.',\n )\n }\n const startDate = Number(BigInt(`0x${sliceTerms(period.terms, 84, 116)}`))\n if (startDate !== expected.startDate) {\n refuseSubBudgetChild(\n 'its period start does not match the parent anchor Haven declared',\n `Expected ${expected.startDate}; the child says ${startDate}.`,\n )\n }\n\n const timestamp = findCaveat(caveats, CAVEAT_ENFORCERS.timestamp)\n if (!timestamp) {\n refuseSubBudgetChild('it never expires', 'A sub-budget child without a timestamp caveat is open-ended.')\n }\n const beforeThreshold = Number(BigInt(`0x${sliceTerms(timestamp.terms, 16, 32)}`))\n const nowSec = Math.floor(now / 1000)\n if (beforeThreshold <= nowSec) {\n refuseSubBudgetChild('it has already expired', `Expiry ${beforeThreshold} is not in the future.`)\n }\n if (beforeThreshold !== expected.expiresAt) {\n refuseSubBudgetChild(\n 'its expiry does not match what Haven declared',\n `Expected ${expected.expiresAt}; the child says ${beforeThreshold}.`,\n )\n }\n\n const calldata = findCaveat(caveats, CAVEAT_ENFORCERS.allowedCalldata)\n if (expected.recipientAddress) {\n if (!calldata) {\n refuseSubBudgetChild(\n 'it has no recipient pin',\n 'The sub-budget was issued with a pinned recipient, so the child must carry one.',\n )\n }\n const startIndex = BigInt(`0x${sliceTerms(calldata.terms, 0, 32)}`)\n if (startIndex !== 4n) {\n refuseSubBudgetChild(\n 'the recipient pin points at the wrong calldata offset',\n `Expected offset 4, got ${startIndex.toString()}.`,\n )\n }\n const paddedRecipient = sliceTerms(calldata.terms, 32, 64)\n if (paddedRecipient.slice(0, 24) !== '0'.repeat(24)) {\n refuseSubBudgetChild('the pinned recipient is not a plain address', 'Its 32-byte word is not a padded address.')\n }\n const recipient = `0x${paddedRecipient.slice(24)}`\n if (!same(recipient, expected.recipientAddress)) {\n refuseSubBudgetChild(\n 'it pins a different recipient than Haven declared',\n `Expected ${expected.recipientAddress}; the child pins ${recipient}.`,\n )\n }\n } else if (calldata) {\n refuseSubBudgetChild(\n 'it pins a recipient the sub-budget was not issued with',\n 'This sub-budget is open (no recipient pin); the child must not add one.',\n )\n }\n}\n\n/** Close UserOp verification — byte-for-byte the task-budget discipline. */\nexport function assertOwnSubBudgetCloseUserOp(\n typedData: Record<string, unknown>,\n expected: { delegationHash: string },\n delegateAddress: string,\n): void {\n // The close UserOp shape is identical to the task budget's: a\n // disableDelegation(child) call from the agent's own delegate account.\n // Reuse the task-budget verifier — the only expectation that differs is\n // the delegation hash, which is an input here either way. Static import,\n // not lazy: these modules share no init-time cycle.\n assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress)\n}\n\n// The close-UserOp verifier is imported for the re-export above.\nimport { assertOwnTaskBudgetCloseUserOp } from './task-budget-guards.js'\n"]}
|