@haven_ai/sdk 0.5.0-alpha.1 → 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.
- package/README.md +2 -1
- package/dist/{base64-BUMXmruY.d.cts → base64-cD9kR4JL.d.cts} +243 -16
- package/dist/{base64-BUMXmruY.d.ts → base64-cD9kR4JL.d.ts} +243 -16
- package/dist/{chunk-KQ7JXKTV.js → chunk-3WSEX3GW.js} +315 -6
- package/dist/chunk-3WSEX3GW.js.map +1 -0
- package/dist/{chunk-GLNG2GF7.js → chunk-63GPTEEY.js} +42 -6
- package/dist/chunk-63GPTEEY.js.map +1 -0
- package/dist/{chunk-QSSVOPWA.cjs → chunk-CK4NLLMO.cjs} +333 -17
- package/dist/chunk-CK4NLLMO.cjs.map +1 -0
- package/dist/{chunk-JKUIE45B.cjs → chunk-S42QSWJY.cjs} +42 -6
- package/dist/chunk-S42QSWJY.cjs.map +1 -0
- package/dist/edge.cjs +85 -57
- package/dist/edge.d.cts +24 -4
- package/dist/edge.d.ts +24 -4
- package/dist/edge.js +3 -3
- package/dist/index.cjs +485 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -3
- package/dist/index.d.ts +47 -3
- package/dist/index.js +192 -21
- 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-GLNG2GF7.js.map +0 -1
- package/dist/chunk-JKUIE45B.cjs.map +0 -1
- package/dist/chunk-KQ7JXKTV.js.map +0 -1
- package/dist/chunk-QSSVOPWA.cjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkS42QSWJY_cjs = require('./chunk-S42QSWJY.cjs');
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
|
|
7
7
|
var TYPED_DATA_NOT_ALLOWED = "TYPED_DATA_NOT_ALLOWED";
|
|
8
|
-
var HavenTypedDataRefusedError = class extends
|
|
8
|
+
var HavenTypedDataRefusedError = class extends chunkS42QSWJY_cjs.HavenSigningError {
|
|
9
9
|
constructor(message) {
|
|
10
10
|
super(message);
|
|
11
11
|
this.code = TYPED_DATA_NOT_ALLOWED;
|
|
@@ -46,7 +46,7 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
46
46
|
`This signer only signs direct payments on chains the delegation rail has pinned contracts for (${[...DIRECT_PAYMENT_CHAIN_IDS].join(", ")}); this typed data names chain ${String(domain.chainId)}. Refusing.`
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
-
const ownAccount =
|
|
49
|
+
const ownAccount = chunkS42QSWJY_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
50
50
|
const sender = typeof message.sender === "string" ? message.sender : "";
|
|
51
51
|
if (sender.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
52
52
|
throw new HavenTypedDataRefusedError(
|
|
@@ -76,9 +76,9 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
76
76
|
"This UserOperation's execute() call does not re-encode to the exact callData bytes (trailing or non-canonical bytes). Refusing."
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
|
-
if (decoded.target.toLowerCase() !==
|
|
79
|
+
if (decoded.target.toLowerCase() !== chunkS42QSWJY_cjs.DELEGATION_MANAGER.toLowerCase()) {
|
|
80
80
|
throw new HavenTypedDataRefusedError(
|
|
81
|
-
`This UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${
|
|
81
|
+
`This UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${chunkS42QSWJY_cjs.DELEGATION_MANAGER}). A direct payment only ever redeems the agent's own budget delegation \u2014 refusing what looks like a self-call (e.g. transferOwnership, updateSigners, upgradeToAndCall) or a call to an unrelated contract.`
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
if (decoded.value !== 0n) {
|
|
@@ -87,20 +87,20 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
try {
|
|
90
|
-
|
|
90
|
+
chunkS42QSWJY_cjs.assertRedeemsOwnBudgetDelegation(decoded.callData, ownAccount);
|
|
91
91
|
} catch (err) {
|
|
92
92
|
throw new HavenTypedDataRefusedError(err instanceof Error ? err.message : String(err));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
function assertOwnSettlementChild(typedData, expectation, delegateAddress) {
|
|
96
96
|
try {
|
|
97
|
-
|
|
97
|
+
chunkS42QSWJY_cjs.verifySettlementChild(typedData, {
|
|
98
98
|
...expectation,
|
|
99
|
-
delegatorAccount:
|
|
99
|
+
delegatorAccount: chunkS42QSWJY_cjs.deriveDelegateAccountAddress(delegateAddress)
|
|
100
100
|
});
|
|
101
101
|
} catch (err) {
|
|
102
102
|
if (err instanceof HavenTypedDataRefusedError) throw err;
|
|
103
|
-
if (err instanceof
|
|
103
|
+
if (err instanceof chunkS42QSWJY_cjs.HavenSigningError) throw new HavenTypedDataRefusedError(err.message);
|
|
104
104
|
throw new HavenTypedDataRefusedError(
|
|
105
105
|
`Refusing to sign the x402 settlement child: it is malformed (${err instanceof Error ? err.message : String(err)}).`
|
|
106
106
|
);
|
|
@@ -129,7 +129,7 @@ function assertFundingLegPaysDelegate(typedData, expected) {
|
|
|
129
129
|
try {
|
|
130
130
|
const { args: executeArgs } = viem.decodeFunctionData({ abi: EXECUTE_ABI, data: message.callData });
|
|
131
131
|
const inner = executeArgs[0].callData;
|
|
132
|
-
const { args } = viem.decodeFunctionData({ abi:
|
|
132
|
+
const { args } = viem.decodeFunctionData({ abi: chunkS42QSWJY_cjs.REDEEM_DELEGATIONS_ABI, data: inner });
|
|
133
133
|
const executions = args[2];
|
|
134
134
|
executionCallData = executions[0];
|
|
135
135
|
} catch {
|
|
@@ -248,7 +248,7 @@ var TRANSFER_WITH_AUTHORIZATION_TYPES = {
|
|
|
248
248
|
function sweepUsdcAddress(chainId) {
|
|
249
249
|
const address = USDC_ADDRESS_BY_CHAIN[chainId];
|
|
250
250
|
if (!address) {
|
|
251
|
-
throw new
|
|
251
|
+
throw new chunkS42QSWJY_cjs.HavenSigningError(
|
|
252
252
|
`Sweep is not supported on chain ${chainId}. Supported: ${SWEEPABLE_CHAIN_IDS.join(", ")}.`
|
|
253
253
|
);
|
|
254
254
|
}
|
|
@@ -257,7 +257,7 @@ function sweepUsdcAddress(chainId) {
|
|
|
257
257
|
function sweepUsdcDomain(chainId) {
|
|
258
258
|
const domain = USDC_EIP712_DOMAIN_BY_CHAIN[chainId];
|
|
259
259
|
if (!domain) {
|
|
260
|
-
throw new
|
|
260
|
+
throw new chunkS42QSWJY_cjs.HavenSigningError(
|
|
261
261
|
`Sweep is not supported on chain ${chainId}. Supported: ${SWEEPABLE_CHAIN_IDS.join(", ")}.`
|
|
262
262
|
);
|
|
263
263
|
}
|
|
@@ -270,12 +270,12 @@ function buildSweepTypedData(auth) {
|
|
|
270
270
|
const domain = sweepUsdcDomain(auth.chainId);
|
|
271
271
|
const expectedToken = sweepUsdcAddress(auth.chainId);
|
|
272
272
|
if (!sameAddress(auth.token, expectedToken)) {
|
|
273
|
-
throw new
|
|
273
|
+
throw new chunkS42QSWJY_cjs.HavenSigningError(
|
|
274
274
|
`Sweep token ${auth.token} is not the canonical USDC contract for chain ${auth.chainId}.`
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
277
|
if (!/^0x[0-9a-fA-F]{64}$/.test(auth.nonce)) {
|
|
278
|
-
throw new
|
|
278
|
+
throw new chunkS42QSWJY_cjs.HavenSigningError("Sweep nonce must be a 0x-prefixed 32-byte hex string.");
|
|
279
279
|
}
|
|
280
280
|
return {
|
|
281
281
|
domain,
|
|
@@ -779,7 +779,7 @@ function stableStringify2(value) {
|
|
|
779
779
|
}
|
|
780
780
|
|
|
781
781
|
// src/client-identity.ts
|
|
782
|
-
var SDK_VERSION = "0.
|
|
782
|
+
var SDK_VERSION = "0.6.0-alpha.0";
|
|
783
783
|
var HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
784
784
|
function havenClientIdentity(pkg, version) {
|
|
785
785
|
return `${pkg}/${version}`;
|
|
@@ -898,14 +898,326 @@ function unsupportedNodeVersionMessage(options) {
|
|
|
898
898
|
function major(version) {
|
|
899
899
|
return String(parseNodeVersion(version)[0]);
|
|
900
900
|
}
|
|
901
|
+
var MAX_TASK_BUDGET_TTL_SECONDS = 86400;
|
|
902
|
+
var EXPECTED_DELEGATION_TYPES = {
|
|
903
|
+
Caveat: [
|
|
904
|
+
{ name: "enforcer", type: "address" },
|
|
905
|
+
{ name: "terms", type: "bytes" }
|
|
906
|
+
],
|
|
907
|
+
Delegation: [
|
|
908
|
+
{ name: "delegate", type: "address" },
|
|
909
|
+
{ name: "delegator", type: "address" },
|
|
910
|
+
{ name: "authority", type: "bytes32" },
|
|
911
|
+
{ name: "caveats", type: "Caveat[]" },
|
|
912
|
+
{ name: "salt", type: "uint256" }
|
|
913
|
+
]
|
|
914
|
+
};
|
|
915
|
+
var DELEGATION_DOMAIN_NAME = "DelegationManager";
|
|
916
|
+
var DELEGATION_DOMAIN_VERSION = "1";
|
|
917
|
+
function same(a, b) {
|
|
918
|
+
return !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
919
|
+
}
|
|
920
|
+
function hex(value) {
|
|
921
|
+
return value.startsWith("0x") ? value.slice(2).toLowerCase() : value.toLowerCase();
|
|
922
|
+
}
|
|
923
|
+
function slice(terms, start, end) {
|
|
924
|
+
const body = hex(terms);
|
|
925
|
+
return end === void 0 ? body.slice(start * 2) : body.slice(start * 2, end * 2);
|
|
926
|
+
}
|
|
927
|
+
function findCaveat(caveats, enforcer) {
|
|
928
|
+
return caveats.find((c) => same(c.enforcer, enforcer));
|
|
929
|
+
}
|
|
930
|
+
function isTaskChildTypedData(value) {
|
|
931
|
+
const td = value;
|
|
932
|
+
if (!td || td.primaryType !== "Delegation" || typeof td.domain?.verifyingContract !== "string" || !Array.isArray(td.message?.caveats)) {
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
const delegate = td.message?.delegate;
|
|
936
|
+
const delegator = td.message?.delegator;
|
|
937
|
+
return typeof delegate === "string" && typeof delegator === "string" && same(delegate, delegator);
|
|
938
|
+
}
|
|
939
|
+
function refuseTaskChild(what, detail) {
|
|
940
|
+
throw new HavenTypedDataRefusedError(
|
|
941
|
+
`Refusing to sign the task-budget child: ${what}. ${detail} This signature opens a self-delegated slice of the agent budget, so it is verified locally against the expectation Haven declared, rather than trusted.`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now()) {
|
|
945
|
+
const td = typedData;
|
|
946
|
+
if (td?.primaryType !== "Delegation") {
|
|
947
|
+
refuseTaskChild("it is not a Delegation payload", `primaryType was '${String(td?.primaryType)}'.`);
|
|
948
|
+
}
|
|
949
|
+
if (!same(td.domain?.verifyingContract, chunkS42QSWJY_cjs.DELEGATION_MANAGER)) {
|
|
950
|
+
refuseTaskChild(
|
|
951
|
+
"the EIP-712 domain names an unknown DelegationManager",
|
|
952
|
+
`Expected ${chunkS42QSWJY_cjs.DELEGATION_MANAGER}, got ${td.domain?.verifyingContract}.`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
if (td.domain?.name !== DELEGATION_DOMAIN_NAME || td.domain?.version !== DELEGATION_DOMAIN_VERSION) {
|
|
956
|
+
refuseTaskChild(
|
|
957
|
+
"the EIP-712 domain name/version does not match the pinned DelegationManager domain",
|
|
958
|
+
`Expected name '${DELEGATION_DOMAIN_NAME}' version '${DELEGATION_DOMAIN_VERSION}'; got name '${String(td.domain?.name)}' version '${String(td.domain?.version)}'.`
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
if (JSON.stringify(td.types?.Caveat) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Caveat) || JSON.stringify(td.types?.Delegation) !== JSON.stringify(EXPECTED_DELEGATION_TYPES.Delegation)) {
|
|
962
|
+
refuseTaskChild(
|
|
963
|
+
"its EIP-712 type definitions do not match the pinned Delegation/Caveat shape",
|
|
964
|
+
"A renamed, reordered, or additional field on Delegation or Caveat could change what the caveats below mean without changing this check's field-by-field comparisons."
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
const domainChain = Number(td.domain?.chainId);
|
|
968
|
+
if (!Number.isFinite(domainChain) || !DIRECT_PAYMENT_CHAIN_IDS.has(domainChain)) {
|
|
969
|
+
refuseTaskChild(
|
|
970
|
+
"it is scoped to a chain the delegation rail has no pinned contracts for",
|
|
971
|
+
`Chains with pinned contracts: ${[...DIRECT_PAYMENT_CHAIN_IDS].join(", ")}; the child says ${String(td.domain?.chainId)}.`
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
if (domainChain !== expected.chainId) {
|
|
975
|
+
refuseTaskChild(
|
|
976
|
+
"it is scoped to the wrong chain",
|
|
977
|
+
`Expected chain ${expected.chainId}; the child says ${td.domain?.chainId}.`
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
const ownAccount = chunkS42QSWJY_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
981
|
+
const delegator = td.message?.delegator;
|
|
982
|
+
if (typeof delegator !== "string" || !same(delegator, ownAccount)) {
|
|
983
|
+
refuseTaskChild(
|
|
984
|
+
"it is not delegated by this agent's own account",
|
|
985
|
+
`Expected delegator ${ownAccount}; the child names ${String(delegator)}.`
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
const delegate = td.message?.delegate;
|
|
989
|
+
if (typeof delegate !== "string" || !same(delegate, ownAccount)) {
|
|
990
|
+
refuseTaskChild(
|
|
991
|
+
"it is not self-delegated to this agent's own account",
|
|
992
|
+
`Expected delegate ${ownAccount}; the child names ${String(delegate)}.`
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
const authority = td.message?.authority;
|
|
996
|
+
if (typeof authority !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(authority)) {
|
|
997
|
+
refuseTaskChild("its authority is not a 32-byte delegation hash", `Got ${String(authority)}.`);
|
|
998
|
+
}
|
|
999
|
+
if (authority.toLowerCase() === chunkS42QSWJY_cjs.ROOT_AUTHORITY) {
|
|
1000
|
+
refuseTaskChild(
|
|
1001
|
+
"it is a ROOT delegation, not a re-delegation of the agent budget",
|
|
1002
|
+
"A task budget always chains under the agent budget delegation."
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
if (!same(authority, expected.parentDelegationHash)) {
|
|
1006
|
+
refuseTaskChild(
|
|
1007
|
+
"it chains under a different parent delegation",
|
|
1008
|
+
`Expected authority ${expected.parentDelegationHash}; the child says ${authority}.`
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
const caveats = td.message?.caveats ?? [];
|
|
1012
|
+
const transfer = findCaveat(caveats, chunkS42QSWJY_cjs.CAVEAT_ENFORCERS.erc20TransferAmount);
|
|
1013
|
+
if (!transfer) {
|
|
1014
|
+
refuseTaskChild(
|
|
1015
|
+
"it has no ERC-20 transfer-amount caveat",
|
|
1016
|
+
"Without it the child is not bounded to an amount."
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
const token = `0x${slice(transfer.terms, 0, 20)}`;
|
|
1020
|
+
if (!same(token, expected.tokenAddress)) {
|
|
1021
|
+
refuseTaskChild("it spends a different token", `Expected ${expected.tokenAddress}, child pins ${token}.`);
|
|
1022
|
+
}
|
|
1023
|
+
const amount = BigInt(`0x${slice(transfer.terms, 20, 52)}`);
|
|
1024
|
+
if (amount !== BigInt(expected.maxAmountAtomic)) {
|
|
1025
|
+
refuseTaskChild(
|
|
1026
|
+
"the amount does not match",
|
|
1027
|
+
`Expected ${expected.maxAmountAtomic}; the child allows ${amount.toString()}.`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
const timestamp = findCaveat(caveats, chunkS42QSWJY_cjs.CAVEAT_ENFORCERS.timestamp);
|
|
1031
|
+
if (!timestamp) {
|
|
1032
|
+
refuseTaskChild("it never expires", "A task-budget child without a timestamp caveat is open-ended.");
|
|
1033
|
+
}
|
|
1034
|
+
const beforeThreshold = Number(BigInt(`0x${slice(timestamp.terms, 16, 32)}`));
|
|
1035
|
+
const nowSec = Math.floor(now / 1e3);
|
|
1036
|
+
if (beforeThreshold <= nowSec) {
|
|
1037
|
+
refuseTaskChild("it has already expired", `Expiry ${beforeThreshold} is not in the future.`);
|
|
1038
|
+
}
|
|
1039
|
+
if (beforeThreshold > nowSec + MAX_TASK_BUDGET_TTL_SECONDS) {
|
|
1040
|
+
refuseTaskChild(
|
|
1041
|
+
"its window is longer than a task budget may live",
|
|
1042
|
+
`Expiry is ${beforeThreshold - nowSec}s out; the ceiling is ${MAX_TASK_BUDGET_TTL_SECONDS}s.`
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
if (beforeThreshold !== expected.expiresAt) {
|
|
1046
|
+
refuseTaskChild(
|
|
1047
|
+
"its expiry does not match what Haven declared",
|
|
1048
|
+
`Expected ${expected.expiresAt}; the child says ${beforeThreshold}.`
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
const calldata = findCaveat(caveats, chunkS42QSWJY_cjs.CAVEAT_ENFORCERS.allowedCalldata);
|
|
1052
|
+
if (expected.recipientAddress) {
|
|
1053
|
+
if (!calldata) {
|
|
1054
|
+
refuseTaskChild(
|
|
1055
|
+
"it has no recipient pin",
|
|
1056
|
+
"The task budget was opened with a pinned recipient, so the child must carry one."
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
const startIndex = BigInt(`0x${slice(calldata.terms, 0, 32)}`);
|
|
1060
|
+
if (startIndex !== 4n) {
|
|
1061
|
+
refuseTaskChild(
|
|
1062
|
+
"the recipient pin points at the wrong calldata offset",
|
|
1063
|
+
`Expected offset 4, got ${startIndex.toString()}.`
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
const paddedRecipient = slice(calldata.terms, 32, 64);
|
|
1067
|
+
if (paddedRecipient.slice(0, 24) !== "0".repeat(24)) {
|
|
1068
|
+
refuseTaskChild("the pinned recipient is not a plain address", "Its 32-byte word is not a padded address.");
|
|
1069
|
+
}
|
|
1070
|
+
const recipient = `0x${paddedRecipient.slice(24)}`;
|
|
1071
|
+
if (!same(recipient, expected.recipientAddress)) {
|
|
1072
|
+
refuseTaskChild(
|
|
1073
|
+
"it pins a different recipient than Haven declared",
|
|
1074
|
+
`Expected ${expected.recipientAddress}; the child pins ${recipient}.`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
} else if (calldata) {
|
|
1078
|
+
refuseTaskChild(
|
|
1079
|
+
"it pins a recipient the task budget was not opened with",
|
|
1080
|
+
"This task budget is open (no recipient pin); the child must not add one."
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
var DISABLE_DELEGATION_ABI = [
|
|
1085
|
+
{
|
|
1086
|
+
type: "function",
|
|
1087
|
+
name: "disableDelegation",
|
|
1088
|
+
inputs: [{ name: "delegation", type: "tuple", components: chunkS42QSWJY_cjs.DELEGATION_TUPLE_COMPONENTS }],
|
|
1089
|
+
outputs: [],
|
|
1090
|
+
stateMutability: "nonpayable"
|
|
1091
|
+
}
|
|
1092
|
+
];
|
|
1093
|
+
function assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress) {
|
|
1094
|
+
const domain = typedData.domain ?? {};
|
|
1095
|
+
const message = typedData.message ?? {};
|
|
1096
|
+
if (typeof domain.chainId !== "number" && typeof domain.chainId !== "bigint") {
|
|
1097
|
+
throw new HavenTypedDataRefusedError(
|
|
1098
|
+
`This close UserOperation's domain.chainId is ${typeof domain.chainId} (${String(domain.chainId)}), not a number \u2014 refusing rather than risk signing a different EIP-712 domain than this check evaluated.`
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
const chainId = Number(domain.chainId);
|
|
1102
|
+
if (!DIRECT_PAYMENT_CHAIN_IDS.has(chainId)) {
|
|
1103
|
+
throw new HavenTypedDataRefusedError(
|
|
1104
|
+
`This signer only signs a task-budget close on chains the delegation rail has pinned contracts for (${[...DIRECT_PAYMENT_CHAIN_IDS].join(", ")}); this typed data names chain ${String(domain.chainId)}. Refusing.`
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
const ownAccount = chunkS42QSWJY_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
1108
|
+
const sender = typeof message.sender === "string" ? message.sender : "";
|
|
1109
|
+
if (sender.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
1110
|
+
throw new HavenTypedDataRefusedError(
|
|
1111
|
+
`This close UserOperation's account (${sender || "unknown"}) is not this signer's own delegate account (${ownAccount}). Sign only your own agent's Haven-prepared payloads.`
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
const callData = message.callData;
|
|
1115
|
+
let decoded;
|
|
1116
|
+
try {
|
|
1117
|
+
const { args } = viem.decodeFunctionData({ abi: EXECUTE_ABI, data: callData });
|
|
1118
|
+
decoded = args[0];
|
|
1119
|
+
} catch {
|
|
1120
|
+
throw new HavenTypedDataRefusedError(
|
|
1121
|
+
"This close UserOperation's callData is not a single execute((address,uint256,bytes)) call. This signer only signs a task-budget close of that exact shape."
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
const reEncodedExecute = viem.encodeFunctionData({ abi: EXECUTE_ABI, functionName: "execute", args: [decoded] });
|
|
1125
|
+
if (reEncodedExecute.toLowerCase() !== callData.toLowerCase()) {
|
|
1126
|
+
throw new HavenTypedDataRefusedError(
|
|
1127
|
+
"This close UserOperation's execute() call does not re-encode to the exact callData bytes (trailing or non-canonical bytes). Refusing."
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
if (decoded.target.toLowerCase() !== chunkS42QSWJY_cjs.DELEGATION_MANAGER.toLowerCase()) {
|
|
1131
|
+
throw new HavenTypedDataRefusedError(
|
|
1132
|
+
`This close UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${chunkS42QSWJY_cjs.DELEGATION_MANAGER}). Refusing what looks like a self-call or a call to an unrelated contract.`
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
if (decoded.value !== 0n) {
|
|
1136
|
+
throw new HavenTypedDataRefusedError(
|
|
1137
|
+
`This close UserOperation's execute() sends ${decoded.value} wei of native value alongside the DelegationManager call \u2014 a task-budget close never does. Refusing.`
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
let delegation;
|
|
1141
|
+
try {
|
|
1142
|
+
const { args } = viem.decodeFunctionData({ abi: DISABLE_DELEGATION_ABI, data: decoded.callData });
|
|
1143
|
+
delegation = args[0];
|
|
1144
|
+
} catch {
|
|
1145
|
+
throw new HavenTypedDataRefusedError(
|
|
1146
|
+
"This close UserOperation's execute() does not call disableDelegation(Delegation) \u2014 this signer only signs a task-budget close of that exact shape."
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
const reEncodedDisable = viem.encodeFunctionData({
|
|
1150
|
+
abi: DISABLE_DELEGATION_ABI,
|
|
1151
|
+
functionName: "disableDelegation",
|
|
1152
|
+
args: [delegation]
|
|
1153
|
+
});
|
|
1154
|
+
if (reEncodedDisable.toLowerCase() !== decoded.callData.toLowerCase()) {
|
|
1155
|
+
throw new HavenTypedDataRefusedError(
|
|
1156
|
+
"This close UserOperation's disableDelegation call does not re-encode to the exact bytes signed (trailing or non-canonical bytes). Refusing."
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
if (delegation.delegator.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
1160
|
+
throw new HavenTypedDataRefusedError(
|
|
1161
|
+
`This close UserOperation disables a delegation granted by ${delegation.delegator}, not this signer's own account (${ownAccount}). Refusing.`
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
if (delegation.delegate.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
1165
|
+
throw new HavenTypedDataRefusedError(
|
|
1166
|
+
`This close UserOperation disables a delegation granted to ${delegation.delegate}, not this signer's own account (${ownAccount}) \u2014 a task-budget child is always self-delegated. Refusing.`
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
if (delegation.authority.toLowerCase() === chunkS42QSWJY_cjs.ROOT_AUTHORITY) {
|
|
1170
|
+
throw new HavenTypedDataRefusedError(
|
|
1171
|
+
"This close UserOperation disables a ROOT delegation, not a re-delegation of the agent budget. A task-budget child always chains under the agent budget delegation. Refusing."
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const actualHash = hashDelegation(delegation);
|
|
1175
|
+
if (actualHash.toLowerCase() !== expected.delegationHash.toLowerCase()) {
|
|
1176
|
+
throw new HavenTypedDataRefusedError(
|
|
1177
|
+
`This close UserOperation disables delegation ${actualHash}, not the task budget's own child (${expected.delegationHash}). Refusing.`
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
var DELEGATION_TYPEHASH = "0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e";
|
|
1182
|
+
var CAVEAT_TYPEHASH = "0x80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d";
|
|
1183
|
+
function hashCaveat(caveat) {
|
|
1184
|
+
const termsHash = viem.keccak256(caveat.terms);
|
|
1185
|
+
const encoded = viem.encodeAbiParameters(
|
|
1186
|
+
[{ type: "bytes32" }, { type: "address" }, { type: "bytes32" }],
|
|
1187
|
+
[CAVEAT_TYPEHASH, caveat.enforcer, termsHash]
|
|
1188
|
+
);
|
|
1189
|
+
return viem.keccak256(encoded);
|
|
1190
|
+
}
|
|
1191
|
+
function hashCaveatsArray(caveats) {
|
|
1192
|
+
const concatenated = `0x${caveats.map((c) => hashCaveat(c).slice(2)).join("")}`;
|
|
1193
|
+
return viem.keccak256(concatenated);
|
|
1194
|
+
}
|
|
1195
|
+
function hashDelegation(delegation) {
|
|
1196
|
+
const caveatsHash = hashCaveatsArray(delegation.caveats);
|
|
1197
|
+
const encoded = viem.encodeAbiParameters(
|
|
1198
|
+
[
|
|
1199
|
+
{ type: "bytes32" },
|
|
1200
|
+
{ type: "address" },
|
|
1201
|
+
{ type: "address" },
|
|
1202
|
+
{ type: "bytes32" },
|
|
1203
|
+
{ type: "bytes32" },
|
|
1204
|
+
{ type: "uint256" }
|
|
1205
|
+
],
|
|
1206
|
+
[DELEGATION_TYPEHASH, delegation.delegate, delegation.delegator, delegation.authority, caveatsHash, delegation.salt]
|
|
1207
|
+
);
|
|
1208
|
+
return viem.keccak256(encoded);
|
|
1209
|
+
}
|
|
901
1210
|
|
|
1211
|
+
exports.CAVEAT_TYPEHASH = CAVEAT_TYPEHASH;
|
|
902
1212
|
exports.DEFAULT_NEXT_TOOL_BY_ACTION = DEFAULT_NEXT_TOOL_BY_ACTION;
|
|
1213
|
+
exports.DELEGATION_TYPEHASH = DELEGATION_TYPEHASH;
|
|
903
1214
|
exports.DIRECT_PAYMENT_CHAIN_IDS = DIRECT_PAYMENT_CHAIN_IDS;
|
|
904
1215
|
exports.ERC7710_ASSET_TRANSFER_METHOD = ERC7710_ASSET_TRANSFER_METHOD;
|
|
905
1216
|
exports.EXECUTE_ABI = EXECUTE_ABI;
|
|
906
1217
|
exports.HAVEN_CLIENT_HEADER = HAVEN_CLIENT_HEADER;
|
|
907
1218
|
exports.HAVEN_MINIMUM_NODE_VERSION = HAVEN_MINIMUM_NODE_VERSION;
|
|
908
1219
|
exports.HavenTypedDataRefusedError = HavenTypedDataRefusedError;
|
|
1220
|
+
exports.MAX_TASK_BUDGET_TTL_SECONDS = MAX_TASK_BUDGET_TTL_SECONDS;
|
|
909
1221
|
exports.NEXT_TOOL_SERVER_NAMES = NEXT_TOOL_SERVER_NAMES;
|
|
910
1222
|
exports.NEXT_TOOL_SERVER_ROLES = NEXT_TOOL_SERVER_ROLES;
|
|
911
1223
|
exports.SDK_CLIENT_IDENTITY = SDK_CLIENT_IDENTITY;
|
|
@@ -928,6 +1240,8 @@ exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_
|
|
|
928
1240
|
exports.assertBoundDirectPaymentUserOp = assertBoundDirectPaymentUserOp;
|
|
929
1241
|
exports.assertFundingLegPaysDelegate = assertFundingLegPaysDelegate;
|
|
930
1242
|
exports.assertOwnSettlementChild = assertOwnSettlementChild;
|
|
1243
|
+
exports.assertOwnTaskBudgetCloseUserOp = assertOwnTaskBudgetCloseUserOp;
|
|
1244
|
+
exports.assertOwnTaskChild = assertOwnTaskChild;
|
|
931
1245
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
932
1246
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
933
1247
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
@@ -940,10 +1254,12 @@ exports.defaultNextToolFor = defaultNextToolFor;
|
|
|
940
1254
|
exports.encodeBase64Json = encodeBase64Json;
|
|
941
1255
|
exports.encodeBase64Utf8 = encodeBase64Utf8;
|
|
942
1256
|
exports.encodePaymentProof = encodePaymentProof;
|
|
1257
|
+
exports.hashDelegation = hashDelegation;
|
|
943
1258
|
exports.havenClientIdentity = havenClientIdentity;
|
|
944
1259
|
exports.isErc7710Option = isErc7710Option;
|
|
945
1260
|
exports.isSupportedNodeVersion = isSupportedNodeVersion;
|
|
946
1261
|
exports.isSweepableChain = isSweepableChain;
|
|
1262
|
+
exports.isTaskChildTypedData = isTaskChildTypedData;
|
|
947
1263
|
exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
948
1264
|
exports.parseNextTool = parseNextTool;
|
|
949
1265
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
@@ -966,5 +1282,5 @@ exports.x402FacilitatorAddresses = x402FacilitatorAddresses;
|
|
|
966
1282
|
exports.x402PaymentHeaderNamesFor = x402PaymentHeaderNamesFor;
|
|
967
1283
|
exports.x402PaymentHeaderNamesSent = x402PaymentHeaderNamesSent;
|
|
968
1284
|
exports.x402V2PaymentEnvelope = x402V2PaymentEnvelope;
|
|
969
|
-
//# sourceMappingURL=chunk-
|
|
970
|
-
//# sourceMappingURL=chunk-
|
|
1285
|
+
//# sourceMappingURL=chunk-CK4NLLMO.cjs.map
|
|
1286
|
+
//# sourceMappingURL=chunk-CK4NLLMO.cjs.map
|