presign-guard-wallet 0.13.0 → 0.14.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 CHANGED
@@ -14,6 +14,8 @@ On top of that it can keep to **spending limits** you set per token (per transac
14
14
 
15
15
  presign-guard decodes approvals, `increaseAllowance`, `setApprovalForAll`, EIP-2612 and Permit2 permits, EIP-3009 transfer authorizations (what an x402 payment signs) and Seaport orders, and screens every spender, recipient and token: known drainers and phishing addresses, sanctions, unlimited approvals to a plain wallet, honeypot tokens, unverified or brand-new contracts, and, with `origin`, new or lookalike domains and phishing sites. See the [reason codes](https://github.com/Fizzl13/presign-guard#reason-codes).
16
16
 
17
+ Transactions are also **simulated**: the wallet sends its own address along (`from`), and presign-guard runs the transaction against the latest block to see what really leaves the wallet, also inside routers, multicalls and batches. An approval the call doesn't show (`HIDDEN_APPROVAL`), an NFT leaving the wallet (`SIMULATION_NFT_OUT`) or a transaction that would fail (`SIMULATION_FAILS`) is orange, so with the default `onOrange: "stop"` nothing is signed.
18
+
17
19
  > **Just want an agent that pays within limits, with approvals on your phone?** The hosted [Fizzl Agent Wallet](https://wallet.fizzl.eu/?ref=readme) wraps this library in an MCP server for Claude, Cursor and other MCP clients: sign in, add an agent, copy its setup. No code needed.
18
20
 
19
21
  ## Install
package/index.d.ts CHANGED
@@ -25,7 +25,7 @@ export interface PresignVerdict {
25
25
 
26
26
  /** What is sent to presign-guard's POST /v1/check. */
27
27
  export type CheckRequest =
28
- | { type: "transaction"; chainId: number; to: string; data: string; value: string; origin?: string }
28
+ | { type: "transaction"; chainId: number; to: string; data: string; value: string; origin?: string; from?: string }
29
29
  | { type: "signature"; chainId: number; typedData: unknown; origin?: string };
30
30
 
31
31
  export declare class PresignBlockedError extends Error {
@@ -192,7 +192,7 @@ export interface GuardOptions {
192
192
 
193
193
  /** The same wallet client; sendTransaction, writeContract and signTypedData are checked first. */
194
194
  export declare function guardWallet<W extends WalletClient>(wallet: W, options: GuardOptions): W & GuardControls;
195
- export declare function checkRequestFor(method: string, args: unknown, options?: { chainId?: number; origin?: string; x402?: Record<string, unknown> }): CheckRequest | null;
195
+ export declare function checkRequestFor(method: string, args: unknown, options?: { chainId?: number; origin?: string; x402?: Record<string, unknown>; from?: string }): CheckRequest | null;
196
196
  /**
197
197
  * Wrap an x402 client scheme so the payment requirements it pays go along with the presign-guard check of its
198
198
  * EIP-3009 signature (red when the signature pays more, someone else, another token or chain than asked).
package/index.js CHANGED
@@ -78,7 +78,7 @@ const ESCROW_ABI = parseAbi([
78
78
  const TRANSFER_ABI = parseAbi(["function transfer(address to, uint256 amount)"]);
79
79
  const VOUCHER_DOMAIN = "TIP20 Channel Reserve";
80
80
  export const XRPL_NETWORKS = ["xrpl:0", "xrpl:1"];
81
- export const VERSION = "0.13.0";
81
+ export const VERSION = "0.14.0";
82
82
  export const CREDIT_HEADER = "x-credit-key";
83
83
  const ROUTE = "POST /v1/check";
84
84
 
@@ -121,16 +121,25 @@ export function x402Checked(scheme) {
121
121
  });
122
122
  }
123
123
 
124
- // What presign-guard should check for a wallet call, or null for calls it does not cover.
125
- export function checkRequestFor(method, args, { chainId, origin, x402 } = {}) {
124
+ // The wallet a transaction is sent from: the call's account, else the client's.
125
+ function senderOf(args, client) {
126
+ const a = args?.account ?? client?.account;
127
+ const address = typeof a === "string" ? a : a?.address;
128
+ return typeof address === "string" && /^0x[0-9a-fA-F]{40}$/.test(address) ? address : null;
129
+ }
130
+
131
+ // What presign-guard should check for a wallet call, or null for calls it does not cover. With `from` (the
132
+ // sending wallet) presign-guard simulates a transaction and reports what really leaves the wallet.
133
+ export function checkRequestFor(method, args, { chainId, origin, x402, from } = {}) {
126
134
  const base = { chainId, ...(origin ? { origin } : {}) };
135
+ const sender = from ? { from } : {};
127
136
  if (method === "sendTransaction") {
128
137
  if (!args?.to) return null; // contract deployment: nothing to screen
129
- return { type: "transaction", ...base, to: args.to, data: args.data ?? "0x", value: String(args.value ?? 0n) };
138
+ return { type: "transaction", ...base, ...sender, to: args.to, data: args.data ?? "0x", value: String(args.value ?? 0n) };
130
139
  }
131
140
  if (method === "writeContract") {
132
141
  const data = encodeFunctionData({ abi: args.abi, functionName: args.functionName, args: args.args });
133
- return { type: "transaction", ...base, to: args.address, data, value: String(args.value ?? 0n) };
142
+ return { type: "transaction", ...base, ...sender, to: args.address, data, value: String(args.value ?? 0n) };
134
143
  }
135
144
  if (method === "signTypedData") {
136
145
  const { domain, types, primaryType, message } = args;
@@ -343,7 +352,7 @@ export function guardWallet(wallet, {
343
352
  const request = tempoRequest(method, args, chainId);
344
353
  return limiter ? withinLimits(method, request, null, run) : run();
345
354
  }
346
- const request = checkRequestFor(method, args, { chainId, origin, x402: x402Paying.getStore() });
355
+ const request = checkRequestFor(method, args, { chainId, origin, x402: x402Paying.getStore(), from: senderOf(args, target) });
347
356
  if (!request) {
348
357
  // A contract deployment is not checked, but the value it sends still counts.
349
358
  if (limiter && method === "sendTransaction") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presign-guard-wallet",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A viem wallet for AI agents that asks presign-guard ($0.01 over x402) before every transaction, contract write and typed-data signature, refuses to sign red, and keeps to per-token spending limits, with approval from your phone over the limit.",
5
5
  "type": "module",
6
6
  "exports": {