@haven_ai/sdk 0.0.0-dev.202609291912.efd0772 → 0.0.0-dev.202609301629.325d86c
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/dist/{base64-DyOPH887.d.cts → base64-CFJN9y6o.d.cts} +14 -1
- package/dist/{base64-DyOPH887.d.ts → base64-CFJN9y6o.d.ts} +14 -1
- package/dist/{chunk-MJ2IMB5H.cjs → chunk-2OILYZQC.cjs} +215 -29
- package/dist/chunk-2OILYZQC.cjs.map +1 -0
- package/dist/{chunk-5I6LGPWZ.js → chunk-ANJUPDH2.js} +2 -2
- package/dist/{chunk-5I6LGPWZ.js.map → chunk-ANJUPDH2.js.map} +1 -1
- package/dist/{chunk-SZHKBOCZ.cjs → chunk-FZB5XARP.cjs} +2 -2
- package/dist/{chunk-SZHKBOCZ.cjs.map → chunk-FZB5XARP.cjs.map} +1 -1
- package/dist/{chunk-6JQT7HNR.js → chunk-X2SETPMZ.js} +179 -6
- package/dist/chunk-X2SETPMZ.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 +398 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +105 -10
- 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-6JQT7HNR.js.map +0 -1
- package/dist/chunk-MJ2IMB5H.cjs.map +0 -1
|
@@ -1531,6 +1531,19 @@ interface PaymentStatusResult {
|
|
|
1531
1531
|
* row records its response); absent = unknown. See the raw field's doc.
|
|
1532
1532
|
*/
|
|
1533
1533
|
delivered?: boolean;
|
|
1534
|
+
/**
|
|
1535
|
+
* #3475 follow-up: which settlement branch this x402 payment runs (#946).
|
|
1536
|
+
* `null` on the legacy rail, on any x402 intent whose scheme metadata
|
|
1537
|
+
* predates #946, or any stored value outside this enum.
|
|
1538
|
+
*/
|
|
1539
|
+
settlementScheme?: 'eip3009' | 'erc7710' | null;
|
|
1540
|
+
/**
|
|
1541
|
+
* #3475 follow-up: `true` only when an eip3009 payment's merchant
|
|
1542
|
+
* settlement transaction is already recorded and on-chain-verified.
|
|
1543
|
+
* Absent — never `false` — when unknown or on erc7710, matching
|
|
1544
|
+
* `delivered`'s own honesty rule.
|
|
1545
|
+
*/
|
|
1546
|
+
merchantSettlementRecorded?: boolean;
|
|
1534
1547
|
/** Platform fee surfaced so it's never silently collected (#386). */
|
|
1535
1548
|
fee?: PaymentFee | null;
|
|
1536
1549
|
amountAtomic?: string | null;
|
|
@@ -2077,7 +2090,7 @@ declare function buildSweepAuthorizationMessage(auth: SweepAuthorization): strin
|
|
|
2077
2090
|
* This SDK's own version. Owned by `scripts/release-bump.mjs`, which rewrites
|
|
2078
2091
|
* it with the package version on every release — never hand-edit it.
|
|
2079
2092
|
*/
|
|
2080
|
-
declare const SDK_VERSION = "0.0.0-dev.
|
|
2093
|
+
declare const SDK_VERSION = "0.0.0-dev.202609301629.325d86c";
|
|
2081
2094
|
/** The request header every published Haven client sends. */
|
|
2082
2095
|
declare const HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
2083
2096
|
/** `<package>/<version>` — the value of {@link HAVEN_CLIENT_HEADER}. */
|
|
@@ -1531,6 +1531,19 @@ interface PaymentStatusResult {
|
|
|
1531
1531
|
* row records its response); absent = unknown. See the raw field's doc.
|
|
1532
1532
|
*/
|
|
1533
1533
|
delivered?: boolean;
|
|
1534
|
+
/**
|
|
1535
|
+
* #3475 follow-up: which settlement branch this x402 payment runs (#946).
|
|
1536
|
+
* `null` on the legacy rail, on any x402 intent whose scheme metadata
|
|
1537
|
+
* predates #946, or any stored value outside this enum.
|
|
1538
|
+
*/
|
|
1539
|
+
settlementScheme?: 'eip3009' | 'erc7710' | null;
|
|
1540
|
+
/**
|
|
1541
|
+
* #3475 follow-up: `true` only when an eip3009 payment's merchant
|
|
1542
|
+
* settlement transaction is already recorded and on-chain-verified.
|
|
1543
|
+
* Absent — never `false` — when unknown or on erc7710, matching
|
|
1544
|
+
* `delivered`'s own honesty rule.
|
|
1545
|
+
*/
|
|
1546
|
+
merchantSettlementRecorded?: boolean;
|
|
1534
1547
|
/** Platform fee surfaced so it's never silently collected (#386). */
|
|
1535
1548
|
fee?: PaymentFee | null;
|
|
1536
1549
|
amountAtomic?: string | null;
|
|
@@ -2077,7 +2090,7 @@ declare function buildSweepAuthorizationMessage(auth: SweepAuthorization): strin
|
|
|
2077
2090
|
* This SDK's own version. Owned by `scripts/release-bump.mjs`, which rewrites
|
|
2078
2091
|
* it with the package version on every release — never hand-edit it.
|
|
2079
2092
|
*/
|
|
2080
|
-
declare const SDK_VERSION = "0.0.0-dev.
|
|
2093
|
+
declare const SDK_VERSION = "0.0.0-dev.202609301629.325d86c";
|
|
2081
2094
|
/** The request header every published Haven client sends. */
|
|
2082
2095
|
declare const HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
2083
2096
|
/** `<package>/<version>` — the value of {@link HAVEN_CLIENT_HEADER}. */
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFZB5XARP_cjs = require('./chunk-FZB5XARP.cjs');
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
|
+
var secp256k1 = require('@noble/curves/secp256k1');
|
|
7
|
+
var accounts = require('viem/accounts');
|
|
6
8
|
|
|
7
9
|
var TYPED_DATA_NOT_ALLOWED = "TYPED_DATA_NOT_ALLOWED";
|
|
8
|
-
var HavenTypedDataRefusedError = class extends
|
|
10
|
+
var HavenTypedDataRefusedError = class extends chunkFZB5XARP_cjs.HavenSigningError {
|
|
9
11
|
constructor(message) {
|
|
10
12
|
super(message);
|
|
11
13
|
this.code = TYPED_DATA_NOT_ALLOWED;
|
|
@@ -46,7 +48,7 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
46
48
|
`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
49
|
);
|
|
48
50
|
}
|
|
49
|
-
const ownAccount =
|
|
51
|
+
const ownAccount = chunkFZB5XARP_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
50
52
|
const sender = typeof message.sender === "string" ? message.sender : "";
|
|
51
53
|
if (sender.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
52
54
|
throw new HavenTypedDataRefusedError(
|
|
@@ -76,9 +78,9 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
76
78
|
"This UserOperation's execute() call does not re-encode to the exact callData bytes (trailing or non-canonical bytes). Refusing."
|
|
77
79
|
);
|
|
78
80
|
}
|
|
79
|
-
if (decoded.target.toLowerCase() !==
|
|
81
|
+
if (decoded.target.toLowerCase() !== chunkFZB5XARP_cjs.DELEGATION_MANAGER.toLowerCase()) {
|
|
80
82
|
throw new HavenTypedDataRefusedError(
|
|
81
|
-
`This UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${
|
|
83
|
+
`This UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${chunkFZB5XARP_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
84
|
);
|
|
83
85
|
}
|
|
84
86
|
if (decoded.value !== 0n) {
|
|
@@ -87,20 +89,20 @@ function assertBoundDirectPaymentUserOp(typedData, delegateAddress) {
|
|
|
87
89
|
);
|
|
88
90
|
}
|
|
89
91
|
try {
|
|
90
|
-
|
|
92
|
+
chunkFZB5XARP_cjs.assertRedeemsOwnBudgetDelegation(decoded.callData, ownAccount);
|
|
91
93
|
} catch (err) {
|
|
92
94
|
throw new HavenTypedDataRefusedError(err instanceof Error ? err.message : String(err));
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
function assertOwnSettlementChild(typedData, expectation, delegateAddress) {
|
|
96
98
|
try {
|
|
97
|
-
|
|
99
|
+
chunkFZB5XARP_cjs.verifySettlementChild(typedData, {
|
|
98
100
|
...expectation,
|
|
99
|
-
delegatorAccount:
|
|
101
|
+
delegatorAccount: chunkFZB5XARP_cjs.deriveDelegateAccountAddress(delegateAddress)
|
|
100
102
|
});
|
|
101
103
|
} catch (err) {
|
|
102
104
|
if (err instanceof HavenTypedDataRefusedError) throw err;
|
|
103
|
-
if (err instanceof
|
|
105
|
+
if (err instanceof chunkFZB5XARP_cjs.HavenSigningError) throw new HavenTypedDataRefusedError(err.message);
|
|
104
106
|
throw new HavenTypedDataRefusedError(
|
|
105
107
|
`Refusing to sign the x402 settlement child: it is malformed (${err instanceof Error ? err.message : String(err)}).`
|
|
106
108
|
);
|
|
@@ -129,7 +131,7 @@ function assertFundingLegPaysDelegate(typedData, expected) {
|
|
|
129
131
|
try {
|
|
130
132
|
const { args: executeArgs } = viem.decodeFunctionData({ abi: EXECUTE_ABI, data: message.callData });
|
|
131
133
|
const inner = executeArgs[0].callData;
|
|
132
|
-
const { args } = viem.decodeFunctionData({ abi:
|
|
134
|
+
const { args } = viem.decodeFunctionData({ abi: chunkFZB5XARP_cjs.REDEEM_DELEGATIONS_ABI, data: inner });
|
|
133
135
|
const executions = args[2];
|
|
134
136
|
executionCallData = executions[0];
|
|
135
137
|
} catch {
|
|
@@ -248,7 +250,7 @@ var TRANSFER_WITH_AUTHORIZATION_TYPES = {
|
|
|
248
250
|
function sweepUsdcAddress(chainId) {
|
|
249
251
|
const address = USDC_ADDRESS_BY_CHAIN[chainId];
|
|
250
252
|
if (!address) {
|
|
251
|
-
throw new
|
|
253
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
252
254
|
`Sweep is not supported on chain ${chainId}. Supported: ${SWEEPABLE_CHAIN_IDS.join(", ")}.`
|
|
253
255
|
);
|
|
254
256
|
}
|
|
@@ -257,7 +259,7 @@ function sweepUsdcAddress(chainId) {
|
|
|
257
259
|
function sweepUsdcDomain(chainId) {
|
|
258
260
|
const domain = USDC_EIP712_DOMAIN_BY_CHAIN[chainId];
|
|
259
261
|
if (!domain) {
|
|
260
|
-
throw new
|
|
262
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
261
263
|
`Sweep is not supported on chain ${chainId}. Supported: ${SWEEPABLE_CHAIN_IDS.join(", ")}.`
|
|
262
264
|
);
|
|
263
265
|
}
|
|
@@ -270,12 +272,12 @@ function buildSweepTypedData(auth) {
|
|
|
270
272
|
const domain = sweepUsdcDomain(auth.chainId);
|
|
271
273
|
const expectedToken = sweepUsdcAddress(auth.chainId);
|
|
272
274
|
if (!sameAddress(auth.token, expectedToken)) {
|
|
273
|
-
throw new
|
|
275
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
274
276
|
`Sweep token ${auth.token} is not the canonical USDC contract for chain ${auth.chainId}.`
|
|
275
277
|
);
|
|
276
278
|
}
|
|
277
279
|
if (!/^0x[0-9a-fA-F]{64}$/.test(auth.nonce)) {
|
|
278
|
-
throw new
|
|
280
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError("Sweep nonce must be a 0x-prefixed 32-byte hex string.");
|
|
279
281
|
}
|
|
280
282
|
return {
|
|
281
283
|
domain,
|
|
@@ -785,7 +787,7 @@ function stableStringify2(value) {
|
|
|
785
787
|
}
|
|
786
788
|
|
|
787
789
|
// src/client-identity.ts
|
|
788
|
-
var SDK_VERSION = "0.0.0-dev.
|
|
790
|
+
var SDK_VERSION = "0.0.0-dev.202609301629.325d86c";
|
|
789
791
|
var HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
790
792
|
function havenClientIdentity(pkg, version) {
|
|
791
793
|
return `${pkg}/${version}`;
|
|
@@ -807,6 +809,177 @@ function readClientUpdate(value) {
|
|
|
807
809
|
notes_url: typeof v.notes_url === "string" ? v.notes_url : null
|
|
808
810
|
};
|
|
809
811
|
}
|
|
812
|
+
var HALF_N = BigInt("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0");
|
|
813
|
+
function hexBytes(value, bytes, what) {
|
|
814
|
+
if (!/^0x[0-9a-fA-F]+$/.test(value) || value.length !== 2 + bytes * 2) {
|
|
815
|
+
throw new Error(`${what} must be a 0x-prefixed ${bytes}-byte hex string`);
|
|
816
|
+
}
|
|
817
|
+
return value.slice(2);
|
|
818
|
+
}
|
|
819
|
+
function addressFromKey(privateKey) {
|
|
820
|
+
try {
|
|
821
|
+
return accounts.privateKeyToAddress(`0x${hexBytes(privateKey, 32, "private key")}`);
|
|
822
|
+
} catch (err) {
|
|
823
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
824
|
+
`Invalid private key: ${err instanceof Error ? err.message : String(err)}`
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function signHash(privateKey, hash) {
|
|
829
|
+
try {
|
|
830
|
+
const { r, s, recovery } = secp256k1.secp256k1.sign(hexBytes(hash, 32, "hash"), hexBytes(privateKey, 32, "private key"), { lowS: true });
|
|
831
|
+
return viem.serializeSignature({
|
|
832
|
+
r: `0x${r.toString(16).padStart(64, "0")}`,
|
|
833
|
+
s: `0x${s.toString(16).padStart(64, "0")}`,
|
|
834
|
+
yParity: recovery
|
|
835
|
+
});
|
|
836
|
+
} catch (err) {
|
|
837
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
838
|
+
`Failed to sign hash: ${err instanceof Error ? err.message : String(err)}`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function verifySignature(hash, signature, expectedAddress) {
|
|
843
|
+
try {
|
|
844
|
+
const sig = hexBytes(signature, 65, "signature");
|
|
845
|
+
const hashHex = hexBytes(hash, 32, "hash");
|
|
846
|
+
if (BigInt(`0x${sig.slice(64, 128)}`) > HALF_N) return false;
|
|
847
|
+
const yParityOrV = Number.parseInt(sig.slice(128), 16);
|
|
848
|
+
const recoveryBit = yParityOrV === 0 || yParityOrV === 27 ? 0 : yParityOrV === 1 || yParityOrV === 28 ? 1 : -1;
|
|
849
|
+
if (recoveryBit < 0) return false;
|
|
850
|
+
const publicKey = secp256k1.secp256k1.Signature.fromCompact(sig.slice(0, 128)).addRecoveryBit(recoveryBit).recoverPublicKey(hashHex).toHex(false);
|
|
851
|
+
const recovered = accounts.publicKeyToAddress(`0x${publicKey}`);
|
|
852
|
+
return recovered.toLowerCase() === expectedAddress.toLowerCase();
|
|
853
|
+
} catch {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
var TAX_DECLARATION_DOMAIN = { name: "x402 Tax Declaration", version: "1" };
|
|
858
|
+
var TAX_DECLARATION_PRIMARY_TYPE = "TaxDeclaration";
|
|
859
|
+
var TAX_DECLARATION_TYPES = {
|
|
860
|
+
TaxDeclaration: [
|
|
861
|
+
{ name: "version", type: "string" },
|
|
862
|
+
{ name: "jurisdiction", type: "string" },
|
|
863
|
+
{ name: "taxableStatus", type: "string" },
|
|
864
|
+
{ name: "taxId", type: "string" },
|
|
865
|
+
{ name: "validUntil", type: "uint256" },
|
|
866
|
+
{ name: "principalId", type: "string" },
|
|
867
|
+
{ name: "principalAttributionHash", type: "string" }
|
|
868
|
+
]
|
|
869
|
+
};
|
|
870
|
+
var X_TAX_DECLARATION_HEADER = "X-Tax-Declaration";
|
|
871
|
+
function validateContent(content) {
|
|
872
|
+
if (typeof content !== "object" || content === null || Array.isArray(content)) {
|
|
873
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError("Tax declaration content must be an object.");
|
|
874
|
+
}
|
|
875
|
+
const record = content;
|
|
876
|
+
for (const field of ["principalId", "principalAttributionHash"]) {
|
|
877
|
+
if (record[field] !== void 0) {
|
|
878
|
+
throw new TaxDeclarationRefusedError(
|
|
879
|
+
`Tax declaration content arrives with ${field} already set; that field is computed locally from the delegate key and the accepted payment option, never accepted from Haven.`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const allowed = /* @__PURE__ */ new Set(["version", "jurisdiction", "taxableStatus", "taxId", "validUntil"]);
|
|
884
|
+
for (const key of Object.keys(record)) {
|
|
885
|
+
if (!allowed.has(key)) {
|
|
886
|
+
throw new TaxDeclarationRefusedError(
|
|
887
|
+
`Tax declaration content carries an unknown field '${key}'; the signed shape is built locally from the \xA72.1 fields only.`
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const strings = ["version", "jurisdiction", "taxableStatus", "taxId"];
|
|
892
|
+
for (const key of strings) {
|
|
893
|
+
if (typeof record[key] !== "string" || record[key].length === 0) {
|
|
894
|
+
throw new TaxDeclarationRefusedError(
|
|
895
|
+
`Tax declaration content field '${key}' must be a non-empty string.`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (typeof record.validUntil !== "number" || !Number.isInteger(record.validUntil) || record.validUntil <= 0) {
|
|
900
|
+
throw new TaxDeclarationRefusedError(
|
|
901
|
+
"Tax declaration content field 'validUntil' must be a positive integer (milliseconds)."
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
version: record.version,
|
|
906
|
+
jurisdiction: record.jurisdiction,
|
|
907
|
+
taxableStatus: record.taxableStatus,
|
|
908
|
+
taxId: record.taxId,
|
|
909
|
+
validUntil: record.validUntil
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
function jcsCanonicalBytes(value) {
|
|
913
|
+
const keys = Object.keys(value).sort();
|
|
914
|
+
const members = keys.map((key) => `${JSON.stringify(key)}:${JSON.stringify(value[key])}`);
|
|
915
|
+
return `{${members.join(",")}}`;
|
|
916
|
+
}
|
|
917
|
+
function principalAttributionHash(principalId) {
|
|
918
|
+
const canonical = jcsCanonicalBytes({ principalId });
|
|
919
|
+
const hex2 = crypto.createHash("sha256").update(canonical, "utf8").digest("hex");
|
|
920
|
+
return `sha-256:${hex2}`;
|
|
921
|
+
}
|
|
922
|
+
function taxPrincipalId(network, delegateAddress) {
|
|
923
|
+
if (network.startsWith("eip155:")) {
|
|
924
|
+
return `did:pkh:${network}:${delegateAddress}`;
|
|
925
|
+
}
|
|
926
|
+
const chainId = chunkFZB5XARP_cjs.chainIdForNetwork(network);
|
|
927
|
+
if (chainId === void 0) {
|
|
928
|
+
throw new TaxDeclarationRefusedError(
|
|
929
|
+
`The accepted payment option's network '${network}' is not a CAIP-2 eip155 chain this SDK can name; refusing to build a tax principal without the settlement network.`
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
return `did:pkh:eip155:${chainId}:${delegateAddress}`;
|
|
933
|
+
}
|
|
934
|
+
function buildSignedTaxDeclaration(input) {
|
|
935
|
+
const content = validateContent(input.content);
|
|
936
|
+
const principalId = taxPrincipalId(input.network, addressFromKeyForTax(input.delegateKey));
|
|
937
|
+
const attributionHash = principalAttributionHash(principalId);
|
|
938
|
+
const declaration = { ...content, principalId, principalAttributionHash: attributionHash };
|
|
939
|
+
const message = { ...declaration, validUntil: BigInt(declaration.validUntil) };
|
|
940
|
+
const digest = viem.hashTypedData({
|
|
941
|
+
domain: TAX_DECLARATION_DOMAIN,
|
|
942
|
+
types: TAX_DECLARATION_TYPES,
|
|
943
|
+
primaryType: TAX_DECLARATION_PRIMARY_TYPE,
|
|
944
|
+
message
|
|
945
|
+
});
|
|
946
|
+
const signature = signHash(input.delegateKey, digest);
|
|
947
|
+
return { declaration, signature };
|
|
948
|
+
}
|
|
949
|
+
function verifyTaxDeclarationSignature(declaration, signature, expectedAddress) {
|
|
950
|
+
const message = { ...declaration, validUntil: BigInt(declaration.validUntil) };
|
|
951
|
+
const digest = viem.hashTypedData({
|
|
952
|
+
domain: TAX_DECLARATION_DOMAIN,
|
|
953
|
+
types: TAX_DECLARATION_TYPES,
|
|
954
|
+
primaryType: TAX_DECLARATION_PRIMARY_TYPE,
|
|
955
|
+
message
|
|
956
|
+
});
|
|
957
|
+
return verifySignature(digest, signature, expectedAddress);
|
|
958
|
+
}
|
|
959
|
+
function encodeTaxDeclarationHeader(result) {
|
|
960
|
+
const json = JSON.stringify({ ...result.declaration, signature: result.signature });
|
|
961
|
+
return base64Url(json);
|
|
962
|
+
}
|
|
963
|
+
function base64Url(value) {
|
|
964
|
+
const standard = typeof Buffer !== "undefined" ? Buffer.from(value, "utf8").toString("base64") : btoa(String.fromCharCode(...new TextEncoder().encode(value)));
|
|
965
|
+
return standard.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
966
|
+
}
|
|
967
|
+
function addressFromKeyForTax(delegateKey) {
|
|
968
|
+
try {
|
|
969
|
+
return addressFromKey(delegateKey);
|
|
970
|
+
} catch (err) {
|
|
971
|
+
throw new chunkFZB5XARP_cjs.HavenSigningError(
|
|
972
|
+
`Invalid delegate key for tax declaration signing: ${err instanceof Error ? err.message : String(err)}`
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
var TaxDeclarationRefusedError = class extends chunkFZB5XARP_cjs.HavenSigningError {
|
|
977
|
+
code = "TAX_DECLARATION_REFUSED";
|
|
978
|
+
constructor(message) {
|
|
979
|
+
super(message);
|
|
980
|
+
this.name = "TaxDeclarationRefusedError";
|
|
981
|
+
}
|
|
982
|
+
};
|
|
810
983
|
|
|
811
984
|
// src/next-step.ts
|
|
812
985
|
var NEXT_TOOL_SERVER_NAMES = {
|
|
@@ -952,10 +1125,10 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
952
1125
|
if (td?.primaryType !== "Delegation") {
|
|
953
1126
|
refuseTaskChild("it is not a Delegation payload", `primaryType was '${String(td?.primaryType)}'.`);
|
|
954
1127
|
}
|
|
955
|
-
if (!same(td.domain?.verifyingContract,
|
|
1128
|
+
if (!same(td.domain?.verifyingContract, chunkFZB5XARP_cjs.DELEGATION_MANAGER)) {
|
|
956
1129
|
refuseTaskChild(
|
|
957
1130
|
"the EIP-712 domain names an unknown DelegationManager",
|
|
958
|
-
`Expected ${
|
|
1131
|
+
`Expected ${chunkFZB5XARP_cjs.DELEGATION_MANAGER}, got ${td.domain?.verifyingContract}.`
|
|
959
1132
|
);
|
|
960
1133
|
}
|
|
961
1134
|
if (td.domain?.name !== DELEGATION_DOMAIN_NAME || td.domain?.version !== DELEGATION_DOMAIN_VERSION) {
|
|
@@ -983,7 +1156,7 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
983
1156
|
`Expected chain ${expected.chainId}; the child says ${td.domain?.chainId}.`
|
|
984
1157
|
);
|
|
985
1158
|
}
|
|
986
|
-
const ownAccount =
|
|
1159
|
+
const ownAccount = chunkFZB5XARP_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
987
1160
|
const delegator = td.message?.delegator;
|
|
988
1161
|
if (typeof delegator !== "string" || !same(delegator, ownAccount)) {
|
|
989
1162
|
refuseTaskChild(
|
|
@@ -1002,7 +1175,7 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
1002
1175
|
if (typeof authority !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(authority)) {
|
|
1003
1176
|
refuseTaskChild("its authority is not a 32-byte delegation hash", `Got ${String(authority)}.`);
|
|
1004
1177
|
}
|
|
1005
|
-
if (authority.toLowerCase() ===
|
|
1178
|
+
if (authority.toLowerCase() === chunkFZB5XARP_cjs.ROOT_AUTHORITY) {
|
|
1006
1179
|
refuseTaskChild(
|
|
1007
1180
|
"it is a ROOT delegation, not a re-delegation of the agent budget",
|
|
1008
1181
|
"A task budget always chains under the agent budget delegation."
|
|
@@ -1015,7 +1188,7 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
1015
1188
|
);
|
|
1016
1189
|
}
|
|
1017
1190
|
const caveats = td.message?.caveats ?? [];
|
|
1018
|
-
const transfer = findCaveat(caveats,
|
|
1191
|
+
const transfer = findCaveat(caveats, chunkFZB5XARP_cjs.CAVEAT_ENFORCERS.erc20TransferAmount);
|
|
1019
1192
|
if (!transfer) {
|
|
1020
1193
|
refuseTaskChild(
|
|
1021
1194
|
"it has no ERC-20 transfer-amount caveat",
|
|
@@ -1033,7 +1206,7 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
1033
1206
|
`Expected ${expected.maxAmountAtomic}; the child allows ${amount.toString()}.`
|
|
1034
1207
|
);
|
|
1035
1208
|
}
|
|
1036
|
-
const timestamp = findCaveat(caveats,
|
|
1209
|
+
const timestamp = findCaveat(caveats, chunkFZB5XARP_cjs.CAVEAT_ENFORCERS.timestamp);
|
|
1037
1210
|
if (!timestamp) {
|
|
1038
1211
|
refuseTaskChild("it never expires", "A task-budget child without a timestamp caveat is open-ended.");
|
|
1039
1212
|
}
|
|
@@ -1054,7 +1227,7 @@ function assertOwnTaskChild(typedData, expected, delegateAddress, now = Date.now
|
|
|
1054
1227
|
`Expected ${expected.expiresAt}; the child says ${beforeThreshold}.`
|
|
1055
1228
|
);
|
|
1056
1229
|
}
|
|
1057
|
-
const calldata = findCaveat(caveats,
|
|
1230
|
+
const calldata = findCaveat(caveats, chunkFZB5XARP_cjs.CAVEAT_ENFORCERS.allowedCalldata);
|
|
1058
1231
|
if (expected.recipientAddress) {
|
|
1059
1232
|
if (!calldata) {
|
|
1060
1233
|
refuseTaskChild(
|
|
@@ -1091,7 +1264,7 @@ var DISABLE_DELEGATION_ABI = [
|
|
|
1091
1264
|
{
|
|
1092
1265
|
type: "function",
|
|
1093
1266
|
name: "disableDelegation",
|
|
1094
|
-
inputs: [{ name: "delegation", type: "tuple", components:
|
|
1267
|
+
inputs: [{ name: "delegation", type: "tuple", components: chunkFZB5XARP_cjs.DELEGATION_TUPLE_COMPONENTS }],
|
|
1095
1268
|
outputs: [],
|
|
1096
1269
|
stateMutability: "nonpayable"
|
|
1097
1270
|
}
|
|
@@ -1110,7 +1283,7 @@ function assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress) {
|
|
|
1110
1283
|
`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.`
|
|
1111
1284
|
);
|
|
1112
1285
|
}
|
|
1113
|
-
const ownAccount =
|
|
1286
|
+
const ownAccount = chunkFZB5XARP_cjs.deriveDelegateAccountAddress(delegateAddress);
|
|
1114
1287
|
const sender = typeof message.sender === "string" ? message.sender : "";
|
|
1115
1288
|
if (sender.toLowerCase() !== ownAccount.toLowerCase()) {
|
|
1116
1289
|
throw new HavenTypedDataRefusedError(
|
|
@@ -1133,9 +1306,9 @@ function assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress) {
|
|
|
1133
1306
|
"This close UserOperation's execute() call does not re-encode to the exact callData bytes (trailing or non-canonical bytes). Refusing."
|
|
1134
1307
|
);
|
|
1135
1308
|
}
|
|
1136
|
-
if (decoded.target.toLowerCase() !==
|
|
1309
|
+
if (decoded.target.toLowerCase() !== chunkFZB5XARP_cjs.DELEGATION_MANAGER.toLowerCase()) {
|
|
1137
1310
|
throw new HavenTypedDataRefusedError(
|
|
1138
|
-
`This close UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${
|
|
1311
|
+
`This close UserOperation's execute() calls ${decoded.target}, not the DelegationManager (${chunkFZB5XARP_cjs.DELEGATION_MANAGER}). Refusing what looks like a self-call or a call to an unrelated contract.`
|
|
1139
1312
|
);
|
|
1140
1313
|
}
|
|
1141
1314
|
if (decoded.value !== 0n) {
|
|
@@ -1172,7 +1345,7 @@ function assertOwnTaskBudgetCloseUserOp(typedData, expected, delegateAddress) {
|
|
|
1172
1345
|
`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.`
|
|
1173
1346
|
);
|
|
1174
1347
|
}
|
|
1175
|
-
if (delegation.authority.toLowerCase() ===
|
|
1348
|
+
if (delegation.authority.toLowerCase() === chunkFZB5XARP_cjs.ROOT_AUTHORITY) {
|
|
1176
1349
|
throw new HavenTypedDataRefusedError(
|
|
1177
1350
|
"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."
|
|
1178
1351
|
);
|
|
@@ -1232,8 +1405,12 @@ exports.SWEEP_BASE_CHAIN_ID = SWEEP_BASE_CHAIN_ID;
|
|
|
1232
1405
|
exports.SWEEP_BASE_SEPOLIA_CHAIN_ID = SWEEP_BASE_SEPOLIA_CHAIN_ID;
|
|
1233
1406
|
exports.SWEEP_BASE_SEPOLIA_USDC_ADDRESS = SWEEP_BASE_SEPOLIA_USDC_ADDRESS;
|
|
1234
1407
|
exports.SWEEP_BASE_USDC_ADDRESS = SWEEP_BASE_USDC_ADDRESS;
|
|
1408
|
+
exports.TAX_DECLARATION_DOMAIN = TAX_DECLARATION_DOMAIN;
|
|
1409
|
+
exports.TAX_DECLARATION_PRIMARY_TYPE = TAX_DECLARATION_PRIMARY_TYPE;
|
|
1410
|
+
exports.TAX_DECLARATION_TYPES = TAX_DECLARATION_TYPES;
|
|
1235
1411
|
exports.TRANSFER_WITH_AUTHORIZATION_TYPES = TRANSFER_WITH_AUTHORIZATION_TYPES;
|
|
1236
1412
|
exports.TYPED_DATA_NOT_ALLOWED = TYPED_DATA_NOT_ALLOWED;
|
|
1413
|
+
exports.TaxDeclarationRefusedError = TaxDeclarationRefusedError;
|
|
1237
1414
|
exports.X402PaymentHeaderValidationError = X402PaymentHeaderValidationError;
|
|
1238
1415
|
exports.X402_LEGACY_PAYMENT_HEADER_NAME = X402_LEGACY_PAYMENT_HEADER_NAME;
|
|
1239
1416
|
exports.X402_MAX_AUTHORIZATION_WINDOW_SECONDS = X402_MAX_AUTHORIZATION_WINDOW_SECONDS;
|
|
@@ -1243,11 +1420,14 @@ exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
|
1243
1420
|
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
1244
1421
|
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
1245
1422
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
1423
|
+
exports.X_TAX_DECLARATION_HEADER = X_TAX_DECLARATION_HEADER;
|
|
1424
|
+
exports.addressFromKey = addressFromKey;
|
|
1246
1425
|
exports.assertBoundDirectPaymentUserOp = assertBoundDirectPaymentUserOp;
|
|
1247
1426
|
exports.assertFundingLegPaysDelegate = assertFundingLegPaysDelegate;
|
|
1248
1427
|
exports.assertOwnSettlementChild = assertOwnSettlementChild;
|
|
1249
1428
|
exports.assertOwnTaskBudgetCloseUserOp = assertOwnTaskBudgetCloseUserOp;
|
|
1250
1429
|
exports.assertOwnTaskChild = assertOwnTaskChild;
|
|
1430
|
+
exports.buildSignedTaxDeclaration = buildSignedTaxDeclaration;
|
|
1251
1431
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
1252
1432
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
1253
1433
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
@@ -1260,6 +1440,7 @@ exports.defaultNextToolFor = defaultNextToolFor;
|
|
|
1260
1440
|
exports.encodeBase64Json = encodeBase64Json;
|
|
1261
1441
|
exports.encodeBase64Utf8 = encodeBase64Utf8;
|
|
1262
1442
|
exports.encodePaymentProof = encodePaymentProof;
|
|
1443
|
+
exports.encodeTaxDeclarationHeader = encodeTaxDeclarationHeader;
|
|
1263
1444
|
exports.hashDelegation = hashDelegation;
|
|
1264
1445
|
exports.havenClientIdentity = havenClientIdentity;
|
|
1265
1446
|
exports.isErc7710Option = isErc7710Option;
|
|
@@ -1270,6 +1451,7 @@ exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
|
1270
1451
|
exports.parseNextTool = parseNextTool;
|
|
1271
1452
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
1272
1453
|
exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;
|
|
1454
|
+
exports.principalAttributionHash = principalAttributionHash;
|
|
1273
1455
|
exports.readClientUpdate = readClientUpdate;
|
|
1274
1456
|
exports.renderNextTool = renderNextTool;
|
|
1275
1457
|
exports.resolveTokenBySymbol = resolveTokenBySymbol;
|
|
@@ -1278,16 +1460,20 @@ exports.selectErc7710PaymentOption = selectErc7710PaymentOption;
|
|
|
1278
1460
|
exports.selectPaymentOption = selectPaymentOption;
|
|
1279
1461
|
exports.selectStandardPaymentOption = selectStandardPaymentOption;
|
|
1280
1462
|
exports.selectX402SettlementScheme = selectX402SettlementScheme;
|
|
1463
|
+
exports.signHash = signHash;
|
|
1281
1464
|
exports.sweepUsdcAddress = sweepUsdcAddress;
|
|
1282
1465
|
exports.sweepUsdcDomain = sweepUsdcDomain;
|
|
1466
|
+
exports.taxPrincipalId = taxPrincipalId;
|
|
1283
1467
|
exports.toStandardPaymentRequirements = toStandardPaymentRequirements;
|
|
1284
1468
|
exports.unsupportedNodeVersionMessage = unsupportedNodeVersionMessage;
|
|
1285
1469
|
exports.validateStandardX402PaymentHeader = validateStandardX402PaymentHeader;
|
|
1470
|
+
exports.verifySignature = verifySignature;
|
|
1471
|
+
exports.verifyTaxDeclarationSignature = verifyTaxDeclarationSignature;
|
|
1286
1472
|
exports.x402AssetTransferMethod = x402AssetTransferMethod;
|
|
1287
1473
|
exports.x402AuthorizationAmount = x402AuthorizationAmount;
|
|
1288
1474
|
exports.x402FacilitatorAddresses = x402FacilitatorAddresses;
|
|
1289
1475
|
exports.x402PaymentHeaderNamesFor = x402PaymentHeaderNamesFor;
|
|
1290
1476
|
exports.x402PaymentHeaderNamesSent = x402PaymentHeaderNamesSent;
|
|
1291
1477
|
exports.x402V2PaymentEnvelope = x402V2PaymentEnvelope;
|
|
1292
|
-
//# sourceMappingURL=chunk-
|
|
1293
|
-
//# sourceMappingURL=chunk-
|
|
1478
|
+
//# sourceMappingURL=chunk-2OILYZQC.cjs.map
|
|
1479
|
+
//# sourceMappingURL=chunk-2OILYZQC.cjs.map
|