presign-guard-wallet 0.18.0 → 0.19.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
@@ -109,7 +109,7 @@ const wallet = guardWallet(walletClient, {
109
109
  // "8453:0x4200…0006": { perDay: "0.01", decimals: 18 },
110
110
  },
111
111
  unknownTokens: "ask", // a token without a limit: "ask" (default), "stop" or "allow"
112
- allow: ["0xShop…", "0xRouter…"], // optional: only these recipients, spenders and contracts
112
+ allow: ["0xShop…", "0xRouter…"], // optional: only these recipients, spenders and contracts (0x, XRPL r… or Algorand addresses)
113
113
  window: "24h", // the rolling window perDay applies to
114
114
  },
115
115
  // over a limit: a human decides (true = sign anyway); without it the wallet stops
@@ -255,7 +255,7 @@ client.register("xrpl:*", new ExactXrplScheme(xrpl)); // x402 payments in RLUSD,
255
255
 
256
256
  ## Algorand (USDC)
257
257
 
258
- `algorandSigner` guards an Algorand signer for x402's AVM client (`@x402/avm`). In an x402 payment group the agent signs one transaction: its USDC transfer to the seller (the seller's facilitator signs and pays the fee transaction). The guarded signer signs only that: an asset transfer of USDC (ASA 31566704 on mainnet, 10458941 on testnet) from the agent's own address, with no close-out, rekey or clawback. It counts toward your `USDC` limit, and pause stops it. Anything else is refused with `unsupported_chain`.
258
+ `algorandSigner` guards an Algorand signer for x402's AVM client (`@x402/avm`). In an x402 payment group the agent signs one transaction: its USDC transfer to the seller (the seller's facilitator signs and pays the fee transaction). The guarded signer signs only that: an asset transfer of USDC (ASA 31566704 on mainnet, 10458941 on testnet) from the agent's own address, with no close-out, rekey or clawback. It counts toward your `USDC` limit, and pause stops it. Anything else is refused with `unsupported_chain`. With an allow list (`limits.allow`), the seller must be on it: Algorand addresses are accepted there (with their checksum), and a receiver that isn't listed goes to `onOverLimit` (`not_allowed`), for x402 payments and for groups signed with `any`.
259
259
 
260
260
  ```js
261
261
  import { toClientAvmSigner } from "@x402/avm";
package/algorand.js CHANGED
@@ -66,6 +66,15 @@ export function algorandAddress(pub) {
66
66
  return out;
67
67
  }
68
68
 
69
+ // A well-formed Algorand address: 58 base32 characters whose last 4 bytes are the checksum of the public key.
70
+ export function isAlgorandAddress(a) {
71
+ if (typeof a !== "string" || !/^[A-Z2-7]{58}$/.test(a)) return false;
72
+ let bits = 0, v = 0;
73
+ const bytes = [];
74
+ for (const ch of a) { v = (v << 5) | B32.indexOf(ch); bits += 5; if (bits >= 8) { bytes.push((v >>> (bits - 8)) & 255); bits -= 8; } }
75
+ return bytes.length === 36 && algorandAddress(Uint8Array.from(bytes.slice(0, 32))) === a;
76
+ }
77
+
69
78
  // An unsigned transaction's fields that matter for spending, as plain values (addresses as strings).
70
79
  export function readAlgorandTxn(bytes) {
71
80
  const t = msgpackDecode(bytes);
package/index.d.ts CHANGED
@@ -49,7 +49,7 @@ export interface SpendingLimits {
49
49
  tokens?: Record<string, { perTx?: TokenAmount; perDay?: TokenAmount; decimals?: number }>;
50
50
  /** Spending of a token without a limit, or a signature whose spending cannot be read. Default "ask" (onOverLimit, else stop). */
51
51
  unknownTokens?: "stop" | "ask" | "allow";
52
- /** Only these recipients, spenders and contracts; anything else goes to onOverLimit. */
52
+ /** Only these recipients, spenders and contracts (0x, XRPL r… or Algorand addresses); anything else goes to onOverLimit. */
53
53
  allow?: string[];
54
54
  /** The rolling window perDay applies to. Default "24h". */
55
55
  window?: string | number;
package/limits.js CHANGED
@@ -26,7 +26,7 @@
26
26
  // Amounts are kept at 18 decimals so one budget can cover the same token with
27
27
  // different decimals on different chains (USDC is 18 on BNB Chain, 6 elsewhere).
28
28
  import { decodeFunctionData, formatUnits, parseAbi, parseUnits } from "viem";
29
- import { ALGORAND_USDC } from "./algorand.js";
29
+ import { ALGORAND_USDC, isAlgorandAddress } from "./algorand.js";
30
30
  import { SOLANA_USDC } from "./solana.js";
31
31
 
32
32
  const SCALE = 18;
@@ -62,6 +62,7 @@ const ERC20_ABI = parseAbi([
62
62
  ]);
63
63
 
64
64
  const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$|^r[1-9A-HJ-NP-Za-km-z]{24,34}$/;
65
+ const allowable = (a) => ADDRESS_RE.test(a) || isAlgorandAddress(a); // EVM, XRPL or Algorand (with its checksum)
65
66
  const lower = (a) => (typeof a === "string" ? a.toLowerCase() : a);
66
67
 
67
68
  export function parseWindow(window) {
@@ -83,7 +84,7 @@ export function normalizeLimits(limits) {
83
84
  if (!limits || typeof limits !== "object") throw new TypeError("limits must be an object");
84
85
  const { tokens = {}, unknownTokens = "ask", allow, window } = limits;
85
86
  if (!["stop", "ask", "allow"].includes(unknownTokens)) throw new TypeError('limits.unknownTokens must be "stop", "ask" or "allow"');
86
- if (allow !== undefined && (!Array.isArray(allow) || allow.some((a) => !ADDRESS_RE.test(a)))) throw new TypeError("limits.allow must be a list of 0x (or XRPL r…) addresses");
87
+ if (allow !== undefined && (!Array.isArray(allow) || allow.some((a) => !allowable(a)))) throw new TypeError("limits.allow must be a list of 0x, XRPL r… or Algorand addresses");
87
88
  const budgets = new Map();
88
89
  const index = new Map(); // "chainId:token" or "*:token" -> { budget, decimals }
89
90
  const put = (k, v) => { if (index.has(k)) throw new TypeError(`limits.tokens: ${k} is covered twice`); index.set(k, v); };
@@ -200,13 +201,14 @@ function algorandSpend(request, out) {
200
201
  const digits = (v) => /^\d+$/.test(String(v ?? ""));
201
202
  for (const t of request.group) {
202
203
  const to = typeof t.receiver === "string" ? t.receiver : null;
203
- if (t.rekeyTo || t.closeTo || t.clawbackFrom) { out.unknown = true; out.counterparties.push(t.rekeyTo ?? t.closeTo ?? t.clawbackFrom); continue; }
204
+ // Counterparties lowercased like the allow list; the receiver as written stays in the items.
205
+ if (t.rekeyTo || t.closeTo || t.clawbackFrom) { out.unknown = true; out.counterparties.push(lower(t.rekeyTo ?? t.closeTo ?? t.clawbackFrom)); continue; }
204
206
  if (t.type === "pay") {
205
207
  if (!digits(t.amount)) { out.unknown = true; continue; }
206
- if (BigInt(t.amount) > 0n && to !== t.sender) { out.items.push({ chainId: net, token: NATIVE, amount: BigInt(t.amount), to }); out.counterparties.push(to); }
208
+ if (BigInt(t.amount) > 0n && to !== t.sender) { out.items.push({ chainId: net, token: NATIVE, amount: BigInt(t.amount), to }); out.counterparties.push(lower(to)); }
207
209
  } else if (t.type === "axfer") {
208
210
  if (!digits(t.amount) || !digits(t.assetId)) { out.unknown = true; continue; }
209
- if (BigInt(t.amount) > 0n && to !== t.sender) { out.items.push({ chainId: net, token: String(t.assetId), amount: BigInt(t.amount), to }); out.counterparties.push(to); }
211
+ if (BigInt(t.amount) > 0n && to !== t.sender) { out.items.push({ chainId: net, token: String(t.assetId), amount: BigInt(t.amount), to }); out.counterparties.push(lower(to)); }
210
212
  }
211
213
  // App calls, asset config and freeze, key registration: they move nothing out of this account by themselves.
212
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presign-guard-wallet",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "A wallet for AI agents (viem on EVM chains, Solana and Algorand) that asks presign-guard ($0.01 over x402) before every transaction, contract write and 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": {