From 8e7af7ff36f964bcbda1bc21eac5d545462acc2d Mon Sep 17 00:00:00 2001 From: HarmMalik <60510357+HaramMalik@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:14:07 +0500 Subject: [PATCH] =?UTF-8?q?feat(thirdweb):=20add=20DACS-Standard=20(=C2=A7?= =?UTF-8?q?9.5.7)=20pre-flight=20spend=20mandate=20guardrail=20to=20sendTr?= =?UTF-8?q?ansaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Summary Implements `DacsMandateMeta` and `assertDacsSpendMandate` inside `sendTransaction` (`packages/thirdweb/src/transaction/actions/send-transaction.ts`) to enforce deterministic, fail-closed pre-flight spend mandate ceilings prior to RPC serialization, gasless relayer submission, zkSync EIP-712 execution, or `account.sendTransaction` dispatch in compliance with **DACS-Standard** (§9.5.7 `X402-1..X402-4` & §14.4 `DACS-4 Settle`). ### Motivation Autonomous AI agents executing transactions via `sendTransaction` / `sendAndConfirmTransaction` (including Engine server wallets and gasless relayers) often operate under delegated session or task mandates (`dacsMandate` / `dacsSessionId` + `dacsMaxAmount`). Enforcing `assertDacsSpendMandate()` before serialization and signer execution ensures over-ceiling transactions fail deterministically before signature generation or relayer dispatch. ### Changes - **`packages/thirdweb/src/transaction/actions/send-transaction.ts`**: - Added `DacsMandateMeta` interface and `assertDacsSpendMandate()` atomic wei spend validator. - Extended `SendTransactionOptions` with `DacsMandateMeta`. - Enforced `assertDacsSpendMandate()` across standard `account.sendTransaction`, `sendGaslessTransaction`, and `sendEip712Transaction` execution branches. Signed-off-by: HarmMalik <60510357+HaramMalik@users.noreply.github.com> --- .../transaction/actions/send-transaction.ts | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/packages/thirdweb/src/transaction/actions/send-transaction.ts b/packages/thirdweb/src/transaction/actions/send-transaction.ts index bab98d3832f..c7f3360f6e5 100644 --- a/packages/thirdweb/src/transaction/actions/send-transaction.ts +++ b/packages/thirdweb/src/transaction/actions/send-transaction.ts @@ -6,8 +6,53 @@ import type { GaslessOptions } from "./gasless/types.js"; import { toSerializableTransaction } from "./to-serializable-transaction.js"; import type { WaitForReceiptOptions } from "./wait-for-tx-receipt.js"; +// ─── DACS-Standard Guardrail (§9.5.7 & §14.4) ───────────────────────────── + +export interface DacsMandateMeta { + /** Signed DACS mandate identifier or URI. */ + dacsMandate?: string; + /** Active DACS session identifier. */ + dacsSessionId?: string; + /** Hard authorized spend ceiling in atomic units (wei). */ + dacsMaxAmount?: bigint | string | number; +} + +export function assertDacsSpendMandate( + requestedAmount: bigint | string | number, + meta?: DacsMandateMeta, +): void { + if (!meta || (!meta.dacsMandate && !meta.dacsSessionId)) { + return; + } + + if (meta.dacsMaxAmount !== undefined) { + let ceiling: bigint; + let requested: bigint; + try { + ceiling = BigInt(meta.dacsMaxAmount); + requested = BigInt(requestedAmount); + } catch { + throw new Error( + `[DACS-Standard §9.5.7] Invalid numeric amount or dacsMaxAmount ceiling.`, + ); + } + + if (ceiling < 0n) { + throw new Error( + `[DACS-Standard §9.5.7] Invalid negative dacsMaxAmount ceiling: "${meta.dacsMaxAmount}".`, + ); + } + + if (requested > ceiling) { + throw new Error( + `[DACS-Standard §9.5.7] sendTransaction execution aborted: requested value (${requested}) exceeds authorized mandate ceiling (${ceiling}).`, + ); + } + } +} + /** Send transaction options */ -export interface SendTransactionOptions { +export interface SendTransactionOptions extends DacsMandateMeta { /** * The account to send the transaction with */ @@ -76,7 +121,7 @@ export interface SendTransactionOptions { * nft: { * name: "NFT Name", * description: "NFT Description", - * image: "https://example.com/image.png", + * image: "[https://example.com/image.png](https://example.com/image.png)", * }, * }); * @@ -148,7 +193,7 @@ export interface SendTransactionOptions { * transaction, * gasless: { * provider: "engine", - * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***", + * relayerUrl: "[https://thirdweb.engine-](https://thirdweb.engine-)***[.thirdweb.com/relayer/](https://.thirdweb.com/relayer/)***", * relayerForwarderAddress: "0x...", * } * }); @@ -171,6 +216,18 @@ export async function sendTransaction( options: SendTransactionOptions, ): Promise { let { account, transaction, gasless } = options; + const dacsMeta: DacsMandateMeta | undefined = + options.dacsMandate || options.dacsSessionId + ? { + dacsMandate: options.dacsMandate, + dacsSessionId: options.dacsSessionId, + dacsMaxAmount: options.dacsMaxAmount, + } + : undefined; + + if (typeof transaction.value === "bigint") { + assertDacsSpendMandate(transaction.value, dacsMeta); + } const decorator = getTransactionDecorator(); if (decorator) { @@ -186,6 +243,10 @@ export async function sendTransaction( // if zksync transaction params are set, send with eip712 if (transaction.eip712) { + assertDacsSpendMandate( + typeof transaction.value === "bigint" ? transaction.value : 0n, + dacsMeta, + ); const { sendEip712Transaction } = await import( "./zksync/send-eip712-transaction.js" ); @@ -199,6 +260,10 @@ export async function sendTransaction( from: account, transaction: transaction, }); + + // DACS-Standard (§9.5.7 & §14.4) pre-flight spend mandate ceiling check + assertDacsSpendMandate(serializableTransaction.value ?? 0n, dacsMeta); + // branch for gasless transactions if (gasless) { // lazy load the gasless tx function because it's only needed for gasless transactions