presign-guard-wallet 0.6.0 → 0.7.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 -0
- package/index.d.ts +4 -0
- package/index.js +41 -5
- package/limits.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,8 @@ try {
|
|
|
71
71
|
|
|
72
72
|
Chains: Ethereum (1), Optimism (10), BNB Chain (56), Polygon (137), Base (8453), Arbitrum (42161).
|
|
73
73
|
|
|
74
|
+
**Tempo** (4217, and the Moderato testnet 42431) is not covered by presign-guard. There the wallet signs exactly one thing, checked locally: a TIP-20 `transfer` or `transferWithMemo` of USDC.e (pathUSD on the testnet), with no value attached, counted toward your `USDC` limits. Anything else on Tempo is refused (`unsupported_chain`). Guard a Tempo wallet client next to your main one with `guarded.wrap(tempoWalletClient)`: both share the same limits, pause and purchase records.
|
|
75
|
+
|
|
74
76
|
## Prepaid credits
|
|
75
77
|
|
|
76
78
|
Agents that sign a lot can prepay: one x402 payment of **$0.80 for 100 checks** or **$7.00 for 1000** (20% / 30% off), valid for a year.
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { WalletClient } from "viem";
|
|
|
3
3
|
export declare const PRESIGN_URL: string;
|
|
4
4
|
export declare const PRESIGN_SIGNERS: string[];
|
|
5
5
|
export declare const SUPPORTED_CHAINS: number[];
|
|
6
|
+
/** Tempo chain id -> the stablecoins (lowercase) the wallet may transfer there, checked locally instead of by presign-guard. */
|
|
7
|
+
export declare const TEMPO_TOKENS: Record<number, string[]>;
|
|
6
8
|
export declare const VERSION: string;
|
|
7
9
|
export declare const CREDIT_HEADER: string;
|
|
8
10
|
|
|
@@ -129,6 +131,8 @@ export interface GuardControls {
|
|
|
129
131
|
* wallet server's receipts, approval messages). Call report() with what happened afterwards.
|
|
130
132
|
*/
|
|
131
133
|
withPurchase<T>(info: Purchase, fn: (report: (outcome: PurchaseOutcome) => void) => Promise<T> | T): Promise<T>;
|
|
134
|
+
/** The same guard (checks, limits, pause, purchases) on another WalletClient, e.g. one for Tempo: both spend from one budget. */
|
|
135
|
+
wrap<W extends object>(wallet: W): W & GuardControls;
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
export interface GuardOptions {
|
package/index.js
CHANGED
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
// function, e.g. ask the user on their phone); without it, it stops. These
|
|
26
26
|
// limits live in the agent's software: an agent with the raw key can go around
|
|
27
27
|
// them. See limits.js for what counts as spending.
|
|
28
|
+
//
|
|
29
|
+
// Tempo (chain 4217, testnet 42431) is not covered by presign-guard. There the
|
|
30
|
+
// wallet signs only one thing, checked here: a TIP-20 transfer or
|
|
31
|
+
// transferWithMemo of USDC.e (pathUSD on the testnet), with no value attached,
|
|
32
|
+
// which counts toward the USDC limits like any other USDC transfer. Anything
|
|
33
|
+
// else on Tempo is refused (code "unsupported_chain").
|
|
28
34
|
|
|
29
35
|
import { encodeFunctionData } from "viem";
|
|
30
36
|
import { verifyReceipt, AUTHORITY } from "x402-safe-fetch";
|
|
@@ -37,7 +43,13 @@ export { memoryStore };
|
|
|
37
43
|
export const PRESIGN_URL = "https://presign-guard.fizzl.eu";
|
|
38
44
|
export const PRESIGN_SIGNERS = ["0xf084Ea47Ca4D99BB4De3ECB0332b316bE6521EaE"];
|
|
39
45
|
export const SUPPORTED_CHAINS = [1, 10, 56, 137, 8453, 42161];
|
|
40
|
-
|
|
46
|
+
// Tempo: the stablecoins the wallet may send there (the ones the USDC limit covers).
|
|
47
|
+
export const TEMPO_TOKENS = {
|
|
48
|
+
4217: ["0x20c000000000000000000000b9537d11c60e8b50"],
|
|
49
|
+
42431: ["0x20c0000000000000000000000000000000000000"],
|
|
50
|
+
};
|
|
51
|
+
const TEMPO_TRANSFERS = new Set(["transfer", "transferWithMemo"]);
|
|
52
|
+
export const VERSION = "0.7.0";
|
|
41
53
|
export const CREDIT_HEADER = "x-credit-key";
|
|
42
54
|
const ROUTE = "POST /v1/check";
|
|
43
55
|
|
|
@@ -228,10 +240,25 @@ export function guardWallet(wallet, {
|
|
|
228
240
|
return result;
|
|
229
241
|
}
|
|
230
242
|
|
|
231
|
-
|
|
243
|
+
// Tempo: only a plain stablecoin transfer, checked here instead of by presign-guard.
|
|
244
|
+
function tempoRequest(method, args, chainId) {
|
|
245
|
+
const tokens = TEMPO_TOKENS[chainId];
|
|
246
|
+
const ok = method === "writeContract" && tokens.includes(String(args?.address ?? "").toLowerCase())
|
|
247
|
+
&& TEMPO_TRANSFERS.has(args?.functionName) && !(BigInt(args?.value ?? 0n) > 0n);
|
|
248
|
+
let request = null;
|
|
249
|
+
try { request = ok ? checkRequestFor(method, args, { chainId, origin }) : null; } catch { request = null; }
|
|
250
|
+
if (!request) throw new PresignBlockedError(`on Tempo (chain ${chainId}) this wallet only sends USDC.e transfers; nothing was signed`, { code: "unsupported_chain" });
|
|
251
|
+
return request;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function guarded(target, method, original, args, rest) {
|
|
232
255
|
if (paused) throw new PresignBlockedError(`wallet is paused; nothing was signed`, { code: "paused" });
|
|
233
|
-
const chainId = args?.chain?.id ??
|
|
256
|
+
const chainId = args?.chain?.id ?? target.chain?.id;
|
|
234
257
|
const run = () => original(args, ...rest);
|
|
258
|
+
if (TEMPO_TOKENS[chainId]) {
|
|
259
|
+
const request = tempoRequest(method, args, chainId);
|
|
260
|
+
return limiter ? withinLimits(method, request, null, run) : run();
|
|
261
|
+
}
|
|
235
262
|
const request = checkRequestFor(method, args, { chainId, origin });
|
|
236
263
|
if (!request) {
|
|
237
264
|
// A contract deployment is not checked, but the value it sends still counts.
|
|
@@ -249,6 +276,14 @@ export function guardWallet(wallet, {
|
|
|
249
276
|
pause: () => { paused = true; },
|
|
250
277
|
resume: () => { paused = false; },
|
|
251
278
|
paused: () => paused,
|
|
279
|
+
/**
|
|
280
|
+
* The same guard (checks, limits, pause, purchases) on another viem WalletClient, e.g. one
|
|
281
|
+
* for Tempo next to the one for Base: both spend from one budget.
|
|
282
|
+
*/
|
|
283
|
+
wrap: (other) => {
|
|
284
|
+
if (!other || typeof other !== "object") throw new TypeError("wrap(wallet): wallet must be a viem WalletClient");
|
|
285
|
+
return proxyFor(other);
|
|
286
|
+
},
|
|
252
287
|
/** Per token: the limits, what was spent in the current window and what is left (null without limits). */
|
|
253
288
|
spending: async () => (limiter ? limiter.spending() : null),
|
|
254
289
|
/**
|
|
@@ -276,12 +311,13 @@ export function guardWallet(wallet, {
|
|
|
276
311
|
},
|
|
277
312
|
};
|
|
278
313
|
|
|
279
|
-
|
|
314
|
+
const proxyFor = (w) => new Proxy(w, {
|
|
280
315
|
get(target, prop, receiver) {
|
|
281
316
|
if (Object.hasOwn(extras, prop) && !(prop in target)) return extras[prop];
|
|
282
317
|
const value = Reflect.get(target, prop, receiver);
|
|
283
318
|
if (typeof prop !== "string" || !GUARDED.has(prop) || typeof value !== "function") return value;
|
|
284
|
-
return (args, ...rest) => guarded(prop, value.bind(target), args, rest);
|
|
319
|
+
return (args, ...rest) => guarded(target, prop, value.bind(target), args, rest);
|
|
285
320
|
},
|
|
286
321
|
});
|
|
322
|
+
return proxyFor(wallet);
|
|
287
323
|
}
|
package/limits.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
// What counts as spending:
|
|
7
7
|
// - the native value sent with a transaction (ETH, BNB, POL);
|
|
8
|
-
// - an ERC-20 transfer or transferFrom;
|
|
8
|
+
// - an ERC-20 transfer or transferFrom (and a TIP-20 transferWithMemo on Tempo);
|
|
9
9
|
// - an allowance (approve, increaseAllowance, Permit, Permit2): whoever gets
|
|
10
10
|
// it can spend that amount, so it counts when it is given; an unlimited
|
|
11
11
|
// one or setApprovalForAll is over any limit;
|
|
@@ -29,6 +29,9 @@ const USDC = {
|
|
|
29
29
|
137: [["0x3c499c542cef5e3811e1192ce70d8cc03d5c3359", 6], ["0x2791bca1f2de4661ed88a30c99a7a9449aa84174", 6]],
|
|
30
30
|
8453: [["0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", 6]],
|
|
31
31
|
42161: [["0xaf88d065e77c8cc2239327c5edb3a432268e5831", 6], ["0xff970a61a04b1ca14834a43f5de4533ebddb5cc8", 6]],
|
|
32
|
+
// Tempo: USDC.e (bridged USDC, what MPP charges in), and pathUSD on the Moderato testnet.
|
|
33
|
+
4217: [["0x20c000000000000000000000b9537d11c60e8b50", 6]],
|
|
34
|
+
42431: [["0x20c0000000000000000000000000000000000000", 6]],
|
|
32
35
|
};
|
|
33
36
|
const NATIVE_SYMBOL = { 1: "ETH", 10: "ETH", 8453: "ETH", 42161: "ETH", 56: "BNB", 137: "POL" };
|
|
34
37
|
export const KNOWN_TOKENS = ["USDC", "ETH", "BNB", "POL"];
|
|
@@ -38,6 +41,7 @@ const ERC20_ABI = parseAbi([
|
|
|
38
41
|
"function increaseAllowance(address spender, uint256 addedValue)",
|
|
39
42
|
"function transfer(address to, uint256 amount)",
|
|
40
43
|
"function transferFrom(address from, address to, uint256 amount)",
|
|
44
|
+
"function transferWithMemo(address to, uint256 amount, bytes32 memo)",
|
|
41
45
|
"function setApprovalForAll(address operator, bool approved)",
|
|
42
46
|
]);
|
|
43
47
|
|
|
@@ -110,7 +114,7 @@ export function spendFor(request, verdict) {
|
|
|
110
114
|
if (call.functionName === "approve" || call.functionName === "increaseAllowance") {
|
|
111
115
|
if (a[1] > 0n) out.items.push({ chainId, token: to, amount: capped(a[1]), to: lower(a[0]) });
|
|
112
116
|
out.counterparties.push(lower(a[0]));
|
|
113
|
-
} else if (call.functionName === "transfer") {
|
|
117
|
+
} else if (call.functionName === "transfer" || call.functionName === "transferWithMemo") {
|
|
114
118
|
out.items.push({ chainId, token: to, amount: capped(a[1]), to: lower(a[0]) });
|
|
115
119
|
out.counterparties.push(lower(a[0]));
|
|
116
120
|
} else if (call.functionName === "transferFrom") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "presign-guard-wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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": {
|