presign-guard-wallet 0.14.0 → 0.15.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 +3 -2
- package/index.d.ts +4 -1
- package/index.js +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ try {
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
`wallet` is the same client:
|
|
55
|
+
`wallet` is the same client. `signMessage` is checked too, as a plain message: a sign-in message (Sign-In with Ethereum) for another site than `origin` is red, unreadable bytes are orange; it counts toward no limit (`checkMessages: false` turns this off). Every other method (`getAddresses`, `extend`, …) works as before, unchecked.
|
|
56
56
|
|
|
57
57
|
## Options
|
|
58
58
|
|
|
@@ -66,6 +66,7 @@ try {
|
|
|
66
66
|
| `origin` | | The site asking for the signature: its domain age and phishing lists are checked too |
|
|
67
67
|
| `onVerdict` | | `(verdict, { method, request, paidWith, creditsLeft }) => void`, e.g. for logging; `paidWith` is `"credits"` or `"x402"` |
|
|
68
68
|
| `verifyReceipts` | `"require"` | Check presign-guard's signed receipt on every verdict; `"off"` skips it |
|
|
69
|
+
| `checkMessages` | `true` | Check `signMessage` too ($0.01 per message, like any check); `false` signs messages unchecked |
|
|
69
70
|
| `signers` | presign-guard's published signer | Accepted signer addresses |
|
|
70
71
|
| `authority` | the Fizzl payout wallet | Wallet whose certificates also make a signer trusted (key rotation); `null` accepts only `signers` |
|
|
71
72
|
| `limits` | | Spending limits per token, see [Spending limits](#spending-limits) |
|
|
@@ -292,7 +293,7 @@ presign-guard signs every paid verdict (EIP-191 over canonical JSON, with a hash
|
|
|
292
293
|
|
|
293
294
|
## Costs and coverage
|
|
294
295
|
|
|
295
|
-
- $0.01 per checked signature, paid with your `pay` fetch, or $0.008 / $0.007 with [prepaid credits](#prepaid-credits). Calls presign-guard does not cover (
|
|
296
|
+
- $0.01 per checked signature, paid with your `pay` fetch, or $0.008 / $0.007 with [prepaid credits](#prepaid-credits). Calls presign-guard does not cover (contract deployments) are not checked and cost nothing; `signMessage` is checked unless `checkMessages: false`.
|
|
296
297
|
- presign-guard reads public data (GoPlus, RugCheck, DexScreener, OFAC via PG1, phishing lists). A green verdict means no known problem was found, not a guarantee.
|
|
297
298
|
- The requests carry `user-agent: presign-guard-wallet/<version>` so the service can count how often the package is used.
|
|
298
299
|
|
package/index.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export interface PresignVerdict {
|
|
|
26
26
|
/** What is sent to presign-guard's POST /v1/check. */
|
|
27
27
|
export type CheckRequest =
|
|
28
28
|
| { type: "transaction"; chainId: number; to: string; data: string; value: string; origin?: string; from?: string }
|
|
29
|
-
| { type: "signature"; chainId: number; typedData: unknown; origin?: string }
|
|
29
|
+
| { type: "signature"; chainId: number; typedData: unknown; origin?: string }
|
|
30
|
+
| { type: "message"; method: "personal_sign"; message: string; chainId?: number; origin?: string; from?: string };
|
|
30
31
|
|
|
31
32
|
export declare class PresignBlockedError extends Error {
|
|
32
33
|
code: "red" | "orange" | "check_failed" | "bad_receipt" | "unsupported_chain" | "over_limit" | "paused" | "limit_unavailable";
|
|
@@ -174,6 +175,8 @@ export interface GuardOptions {
|
|
|
174
175
|
presignUrl?: string;
|
|
175
176
|
/** Check presign-guard's signed receipt on every verdict. Default "require". */
|
|
176
177
|
verifyReceipts?: "require" | "off";
|
|
178
|
+
/** Check signMessage with presign-guard too (default true): eth_sign-style hashes are orange, a sign-in message for another site than origin is red. */
|
|
179
|
+
checkMessages?: boolean;
|
|
177
180
|
/** Accepted signer addresses. Default: the published signer (PRESIGN_SIGNERS). */
|
|
178
181
|
signers?: string[];
|
|
179
182
|
/** Wallet whose certificates also make a signer trusted (key rotation). Default: the Fizzl payout wallet; null accepts only `signers`. */
|
package/index.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
// toward the limits (XRP toward an XRP limit, RLUSD toward USDC). Use it with
|
|
49
49
|
// @x402/xrpl's ExactXrplScheme to pay x402 services in RLUSD.
|
|
50
50
|
|
|
51
|
-
import { decodeFunctionData, encodeFunctionData, parseAbi } from "viem";
|
|
51
|
+
import { bytesToHex, decodeFunctionData, encodeFunctionData, parseAbi } from "viem";
|
|
52
52
|
import { verifyReceipt, AUTHORITY } from "x402-safe-fetch";
|
|
53
53
|
import { createLimiter, memoryStore } from "./limits.js";
|
|
54
54
|
import { createRemoteLimiter } from "./remote.js";
|
|
@@ -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.
|
|
81
|
+
export const VERSION = "0.15.0";
|
|
82
82
|
export const CREDIT_HEADER = "x-credit-key";
|
|
83
83
|
const ROUTE = "POST /v1/check";
|
|
84
84
|
|
|
@@ -141,6 +141,13 @@ export function checkRequestFor(method, args, { chainId, origin, x402, from } =
|
|
|
141
141
|
const data = encodeFunctionData({ abi: args.abi, functionName: args.functionName, args: args.args });
|
|
142
142
|
return { type: "transaction", ...base, ...sender, to: args.address, data, value: String(args.value ?? 0n) };
|
|
143
143
|
}
|
|
144
|
+
if (method === "signMessage") {
|
|
145
|
+
// viem: a string is signed as text, { raw } as bytes (hex or a byte array).
|
|
146
|
+
const m = args?.message;
|
|
147
|
+
const message = typeof m === "string" ? m : typeof m?.raw === "string" ? m.raw : m?.raw instanceof Uint8Array ? bytesToHex(m.raw) : null;
|
|
148
|
+
if (message === null) return null;
|
|
149
|
+
return { type: "message", method: "personal_sign", message, ...(chainId ? { chainId } : {}), ...(origin ? { origin } : {}), ...sender };
|
|
150
|
+
}
|
|
144
151
|
if (method === "signTypedData") {
|
|
145
152
|
const { domain, types, primaryType, message } = args;
|
|
146
153
|
// A payment made by mandatePayer() (mandate.js) is checked against its mandate too.
|
|
@@ -213,6 +220,7 @@ function cleanPurchase(info) {
|
|
|
213
220
|
* @param {(entry: object) => void} [options.onSpend] after each signed spend
|
|
214
221
|
* @param {{url: string, key: string}} [options.server] a wallet server (fizzl wallet-server) keeps the limits, budget and approvals for all your agents
|
|
215
222
|
* @param {object} [options.store] where spending is kept (default in memory; fileStore from presign-guard-wallet/file-store)
|
|
223
|
+
* @param {boolean} [options.checkMessages] check signMessage too (default true): a sign-in message for another site is red
|
|
216
224
|
*/
|
|
217
225
|
export function guardWallet(wallet, {
|
|
218
226
|
pay,
|
|
@@ -225,6 +233,7 @@ export function guardWallet(wallet, {
|
|
|
225
233
|
signers = PRESIGN_SIGNERS,
|
|
226
234
|
authority = AUTHORITY,
|
|
227
235
|
creditKey,
|
|
236
|
+
checkMessages = true,
|
|
228
237
|
fetch: plainFetch = globalThis.fetch,
|
|
229
238
|
limits,
|
|
230
239
|
onOverLimit,
|
|
@@ -238,6 +247,7 @@ export function guardWallet(wallet, {
|
|
|
238
247
|
if (!["stop", "allow"].includes(onOrange) && typeof onOrange !== "function") throw new TypeError('onOrange must be "stop", "allow" or a function');
|
|
239
248
|
if (!["stop", "allow"].includes(onError)) throw new TypeError('onError must be "stop" or "allow"');
|
|
240
249
|
if (!["require", "off"].includes(verifyReceipts)) throw new TypeError('verifyReceipts must be "require" or "off"');
|
|
250
|
+
if (typeof checkMessages !== "boolean") throw new TypeError("checkMessages must be true or false");
|
|
241
251
|
|
|
242
252
|
if (server !== undefined && (limits !== undefined || onOverLimit || store)) throw new TypeError("with server, the limits and approvals live on the wallet server: leave out limits, onOverLimit and store");
|
|
243
253
|
if (server === undefined && limits === undefined && (onOverLimit || onSpend || store)) throw new TypeError("onOverLimit, onSpend and store need limits");
|
|
@@ -281,7 +291,7 @@ export function guardWallet(wallet, {
|
|
|
281
291
|
|
|
282
292
|
// The verdict for a request, or null when the check could not be done and onError is "allow".
|
|
283
293
|
async function verdictFor(method, request, chainId) {
|
|
284
|
-
if (!SUPPORTED_CHAINS.includes(chainId) && !XRPL_NETWORKS.includes(chainId)) {
|
|
294
|
+
if (request.type !== "message" && !SUPPORTED_CHAINS.includes(chainId) && !XRPL_NETWORKS.includes(chainId)) {
|
|
285
295
|
if (onError === "allow") return null;
|
|
286
296
|
throw new PresignBlockedError(`chain ${chainId} is not covered by presign-guard; nothing was signed`, { code: "unsupported_chain", request });
|
|
287
297
|
}
|
|
@@ -348,6 +358,12 @@ export function guardWallet(wallet, {
|
|
|
348
358
|
if (paused) throw new PresignBlockedError(`wallet is paused; nothing was signed`, { code: "paused" });
|
|
349
359
|
const chainId = args?.chain?.id ?? target.chain?.id;
|
|
350
360
|
const run = () => original(args, ...rest);
|
|
361
|
+
// A plain message moves nothing by itself, so it is checked but not counted toward the limits.
|
|
362
|
+
if (method === "signMessage") {
|
|
363
|
+
const request = checkRequestFor(method, args, { chainId, origin, from: senderOf(args, target) });
|
|
364
|
+
if (request) await verdictFor(method, request, chainId);
|
|
365
|
+
return run();
|
|
366
|
+
}
|
|
351
367
|
if (TEMPO_TOKENS[chainId]) {
|
|
352
368
|
const request = tempoRequest(method, args, chainId);
|
|
353
369
|
return limiter ? withinLimits(method, request, null, run) : run();
|
|
@@ -506,7 +522,7 @@ export function guardWallet(wallet, {
|
|
|
506
522
|
get(target, prop, receiver) {
|
|
507
523
|
if (Object.hasOwn(extras, prop) && !(prop in target)) return extras[prop];
|
|
508
524
|
const value = Reflect.get(target, prop, receiver);
|
|
509
|
-
if (typeof prop !== "string" || !GUARDED.has(prop) || typeof value !== "function") return value;
|
|
525
|
+
if (typeof prop !== "string" || !(GUARDED.has(prop) || (checkMessages && prop === "signMessage")) || typeof value !== "function") return value;
|
|
510
526
|
return (args, ...rest) => guarded(target, prop, value.bind(target), args, rest);
|
|
511
527
|
},
|
|
512
528
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "presign-guard-wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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": {
|