agentwallet-mcp 1.12.3 → 1.12.4

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
@@ -259,6 +259,8 @@ pay_x402(
259
259
 
260
260
  **Token domains.** The EIP-712 domain comes from the endpoint's `extra.name` / `extra.version`, then a short registry of USDC deployments, then the token contract's own `name()` / `version()`. If none of those answer, the payment is refused rather than signed with a guessed domain.
261
261
 
262
+ **Delegated payers.** If the paying address is an EIP-7702 delegated account, `pay_x402` reports it in `payer_delegation` (the delegate and whether it answers ERC-1271). A delegate without ERC-1271 is declined by facilitators that check account code before recovering the signer, and the reason they return reads like a signature fault; the warning names the real cause. Pay from a plain EOA for reliable settlement.
263
+
262
264
  ## x402 Acceptance
263
265
 
264
266
  AgentWallet also lets you **accept** x402 payments. Create a paywall, point it at any resource, and get a public URL that charges agents automatically:
package/build/index.js CHANGED
@@ -15,10 +15,10 @@ import { z } from 'zod';
15
15
  import { assertPublicUrl, safeFetch } from './ssrf-guard.js';
16
16
  import { deriveX402Payment, isWithinCap, lookupTrustedDecimals, assertDeclaredDecimals, nativeDecimals, SOLANA_CHAIN_IDS, } from './x402-payment.js';
17
17
  import { isLocalMode, getLocalAddress, localWalletRecord, localSend, localNativeBalance, localTokenBalance, localSignMessage, resolveRpcUrl, } from './local-wallet.js';
18
- import { localSignAuthorization, localEthCall, localSignPermit2Upto } from './local-wallet.js';
18
+ import { localSignAuthorization, localEthCall, localGetCode, localSignPermit2Upto } from './local-wallet.js';
19
19
  import { buildUptoAuthorization, uptoPayload, permit2AllowanceCalldata, permit2ApproveCalldata, decodeUint, PERMIT2_ADDRESS, } from './x402-permit2.js';
20
20
  import { assessTokenRisk } from './token-risk.js';
21
- import { isLegacyAgentWalletAccept, requiredAmount, buildAuthorization, buildPaymentPayload, buildPaymentPayloadRaw, paymentHeaderFor, parsePaymentRequired, parseSettlement, pickOption, knownTokenDomain, } from './x402-eip3009.js';
21
+ import { isLegacyAgentWalletAccept, requiredAmount, buildAuthorization, buildPaymentPayload, buildPaymentPayloadRaw, paymentHeaderFor, parsePaymentRequired, parseSettlement, pickOption, knownTokenDomain, parseEip7702Delegation, erc1271ProbeCalldata, classifyErc1271Probe, } from './x402-eip3009.js';
22
22
  import { isSolanaLocalMode, getSolanaAddress, solanaWalletRecord, localSolBalance, localSplBalance, localSolTransfer, localSplTransfer, resolveSolanaRpc, } from './local-solana.js';
23
23
  /** True when either chain family is running non-custodially. */
24
24
  function anyLocalMode() {
@@ -128,6 +128,12 @@ async function routeLocally(path, method, body) {
128
128
  return NOT_HANDLED;
129
129
  return localEthCall(localChainId(body, qs), String(body?.to || ''), String(body?.data || '0x'));
130
130
  }
131
+ // POST /eth-get-code (read-only; the payer's account code, checked for an EIP-7702 delegation before an x402 authorization)
132
+ if (method === 'POST' && rawPath === '/eth-get-code') {
133
+ if (!isLocalMode())
134
+ return NOT_HANDLED;
135
+ return localGetCode(localChainId(body, qs), String(body?.address || ''));
136
+ }
131
137
  // GET /wallets/{id}/balance
132
138
  if (method === 'GET' && /^\/wallets\/[^/]*\/balance$/.test(rawPath)) {
133
139
  const chainId = localChainId(body, qs);
@@ -461,7 +467,7 @@ function resolveChainId(network) {
461
467
  const AddressSchema = z.string().regex(/^(0x[a-fA-F0-9]{40}|[1-9A-HJ-NP-Za-km-z]{32,44})$/, 'Must be a 0x-prefixed 40-hex EVM address or a base58 Solana address');
462
468
  const server = new McpServer({
463
469
  name: 'agentwallet',
464
- version: '1.12.3',
470
+ version: '1.12.4',
465
471
  }, {
466
472
  instructions: `AgentWallet gives AI agents their own blockchain wallets. Private keys are encrypted server-side and never exposed — agents sign and broadcast transactions without ever touching raw keys.
467
473
 
@@ -994,6 +1000,39 @@ async function payerAddress(walletId) {
994
1000
  throw new Error(`x402: could not resolve the EVM address of wallet ${walletId} (got "${a}").`);
995
1001
  return a;
996
1002
  }
1003
+ /**
1004
+ * Best-effort look at the payer's account code. An EIP-7702 delegated EOA whose delegate
1005
+ * does not implement ERC-1271 is declined by facilitators that check code before recovering
1006
+ * the signer, with an error that reads like a signature fault (issue #9). Nothing is refused
1007
+ * here: the authorization costs nothing to sign and other facilitators accept it. The result
1008
+ * carries the warning so the agent can explain a signature-shaped rejection. A lookup failure
1009
+ * (a hosted server without the route, RPC trouble) reports nothing rather than blocking the payment.
1010
+ */
1011
+ async function payerDelegation(chainId, payer) {
1012
+ try {
1013
+ const r = (await api('/eth-get-code', 'POST', { chain_id: chainId, address: payer }, { 'X-AGW-SKIP-X402': 'true' }));
1014
+ const delegate = parseEip7702Delegation(r?.code);
1015
+ if (!delegate)
1016
+ return null;
1017
+ let erc1271 = 'unknown';
1018
+ try {
1019
+ const probe = (await api('/eth-call', 'POST', { chain_id: chainId, to: payer, data: erc1271ProbeCalldata() }, { 'X-AGW-SKIP-X402': 'true' }));
1020
+ erc1271 = classifyErc1271Probe(probe?.result);
1021
+ }
1022
+ catch {
1023
+ erc1271 = 'unknown';
1024
+ }
1025
+ const warning = erc1271 === 'no'
1026
+ ? `Payer ${payer} is an EIP-7702 delegated account (delegate ${delegate}) and the delegate does not answer ERC-1271 isValidSignature. ` +
1027
+ `Facilitators that check account code before recovering the signer decline this authorization with a signature error. ` +
1028
+ `Pay from a plain EOA, or clear the delegation, for reliable x402 settlement.`
1029
+ : `Payer ${payer} is an EIP-7702 delegated account (delegate ${delegate}); a facilitator may verify the authorization through ERC-1271 on the delegate.`;
1030
+ return { delegate, erc1271, warning };
1031
+ }
1032
+ catch {
1033
+ return null;
1034
+ }
1035
+ }
997
1036
  async function ethCallHex(chainId, to, data) {
998
1037
  const r = (await api('/eth-call', 'POST', { chain_id: chainId, to, data }, { 'X-AGW-SKIP-X402': 'true' }));
999
1038
  return String(r?.result || '');
@@ -1225,8 +1264,10 @@ server.tool('pay_x402', 'Handle an x402 payment flow. Fetches a URL, and if the
1225
1264
  let uptoAuth = null;
1226
1265
  let payer = null;
1227
1266
  let permit2ApprovalTx = null;
1267
+ let payerDelegationInfo = null;
1228
1268
  if (isUpto) {
1229
1269
  payer = await payerAddress(wallet_id);
1270
+ payerDelegationInfo = await payerDelegation(chainId, payer);
1230
1271
  const allowance = decodeUint(await ethCallHex(chainId, tokenAddress, permit2AllowanceCalldata(payer)));
1231
1272
  if (allowance < BigInt(rawAmount)) {
1232
1273
  if (process.env.AGENTWALLET_PERMIT2_AUTO_APPROVE === '1') {
@@ -1253,6 +1294,7 @@ server.tool('pay_x402', 'Handle an x402 payment flow. Fetches a URL, and if the
1253
1294
  }
1254
1295
  else if (standardExact) {
1255
1296
  payer = await payerAddress(wallet_id);
1297
+ payerDelegationInfo = await payerDelegation(chainId, payer);
1256
1298
  const domain = await resolveTokenDomain(chainId, tokenAddress, option.extra);
1257
1299
  authorization = buildAuthorization(payer, option);
1258
1300
  const signature = await signAuthorization(wallet_id, chainId, tokenAddress, domain, authorization, approvalUsed);
@@ -1306,6 +1348,8 @@ server.tool('pay_x402', 'Handle an x402 payment flow. Fetches a URL, and if the
1306
1348
  if (retryRes.status === 402) {
1307
1349
  const again = parsePaymentRequired(n => retryRes.headers.get(n), retryParsed);
1308
1350
  retryError = String(again?.error || retryParsed?.error || 'Payment was not accepted (no reason given).');
1351
+ if (payerDelegationInfo && /signature/i.test(retryError))
1352
+ retryError += ` Likely cause: ${payerDelegationInfo.warning}`;
1309
1353
  }
1310
1354
  return jsonResponse({
1311
1355
  status: retryRes.status,
@@ -1326,6 +1370,7 @@ server.tool('pay_x402', 'Handle an x402 payment flow. Fetches a URL, and if the
1326
1370
  chain_id: chainId,
1327
1371
  pay_to: option.payTo,
1328
1372
  payer,
1373
+ payer_delegation: payerDelegationInfo,
1329
1374
  tx_hash: txHash ?? settlement?.transaction ?? null,
1330
1375
  settlement,
1331
1376
  authorization: authorization ? { nonce: authorization.nonce, valid_before: authorization.validBefore }
@@ -108,6 +108,10 @@ export declare function localSignAuthorization(chainId: number, asset: Address,
108
108
  export declare function localEthCall(chainId: number, to: Address, data: Hex): Promise<{
109
109
  result: string;
110
110
  }>;
111
+ /** Read-only eth_getCode against the local RPC, same shape as the hosted /eth-get-code route. */
112
+ export declare function localGetCode(chainId: number, address: Address): Promise<{
113
+ code: string;
114
+ }>;
111
115
  /** x402 "upto": sign a Permit2 max-authorization in-process. The maximum goes through the token cap like a transfer would. */
112
116
  export declare function localSignPermit2Upto(chainId: number, auth: UptoPermit2Authorization): Promise<{
113
117
  signature: `0x${string}`;
@@ -380,6 +380,12 @@ export async function localEthCall(chainId, to, data) {
380
380
  const r = await client.call({ to, data });
381
381
  return { result: r.data ?? '0x' };
382
382
  }
383
+ /** Read-only eth_getCode against the local RPC, same shape as the hosted /eth-get-code route. */
384
+ export async function localGetCode(chainId, address) {
385
+ const client = createPublicClient({ transport: http(resolveRpcUrl(chainId)) });
386
+ const code = await client.getCode({ address });
387
+ return { code: code ?? '0x' };
388
+ }
383
389
  /** x402 "upto": sign a Permit2 max-authorization in-process. The maximum goes through the token cap like a transfer would. */
384
390
  export async function localSignPermit2Upto(chainId, auth) {
385
391
  const token = auth.permitted.token;
@@ -169,3 +169,22 @@ export declare function pickOption(accepts: X402Requirement[], resolveChainId: (
169
169
  chainId: number | null;
170
170
  reason?: string;
171
171
  };
172
+ /**
173
+ * An EIP-7702 delegated EOA has code 0xef0100 || delegate (23 bytes). A facilitator that
174
+ * checks account code before recovering the signer treats such a payer as a contract
175
+ * wallet and calls ERC-1271 isValidSignature on it; a delegate that does not implement
176
+ * it answers with empty data, and the payment is declined with a signature-shaped error
177
+ * that has nothing to do with the signature (issue #9: a well-known test key that
178
+ * sweeper bots had delegated on Base mainnet).
179
+ */
180
+ export declare function parseEip7702Delegation(code: string | null | undefined): string | null;
181
+ export declare const ERC1271_MAGIC = "0x1626ba7e";
182
+ /** Calldata for isValidSignature(bytes32, bytes) with a placeholder hash and a 65-byte placeholder signature. */
183
+ export declare function erc1271ProbeCalldata(): `0x${string}`;
184
+ export type Erc1271Support = 'yes' | 'no' | 'unknown';
185
+ /**
186
+ * Classify an isValidSignature probe. Empty return data means the account has no such
187
+ * function (the failure shape from issue #9); a 4-byte word means the interface exists,
188
+ * whatever it thought of the placeholder signature; a revert or transport failure is unknown.
189
+ */
190
+ export declare function classifyErc1271Probe(result: string | null | undefined, failed?: boolean): Erc1271Support;
@@ -205,3 +205,40 @@ export function pickOption(accepts, resolveChainId, preferChain) {
205
205
  option = payable.find(a => resolveChainId(a.network) === preferChain) ?? option;
206
206
  return { option, chainId: resolveChainId(option.network) };
207
207
  }
208
+ // ─── Payer account shape (EIP-7702) ──────────────────────────────
209
+ /**
210
+ * An EIP-7702 delegated EOA has code 0xef0100 || delegate (23 bytes). A facilitator that
211
+ * checks account code before recovering the signer treats such a payer as a contract
212
+ * wallet and calls ERC-1271 isValidSignature on it; a delegate that does not implement
213
+ * it answers with empty data, and the payment is declined with a signature-shaped error
214
+ * that has nothing to do with the signature (issue #9: a well-known test key that
215
+ * sweeper bots had delegated on Base mainnet).
216
+ */
217
+ export function parseEip7702Delegation(code) {
218
+ const m = /^0xef0100([0-9a-f]{40})$/.exec(String(code || '').toLowerCase());
219
+ return m ? `0x${m[1]}` : null;
220
+ }
221
+ export const ERC1271_MAGIC = '0x1626ba7e';
222
+ /** Calldata for isValidSignature(bytes32, bytes) with a placeholder hash and a 65-byte placeholder signature. */
223
+ export function erc1271ProbeCalldata() {
224
+ const hash = '11'.repeat(32);
225
+ const offset = (64).toString(16).padStart(64, '0');
226
+ const length = (65).toString(16).padStart(64, '0');
227
+ const sig = 'aa'.repeat(65).padEnd(192, '0');
228
+ return `${ERC1271_MAGIC}${hash}${offset}${length}${sig}`;
229
+ }
230
+ /**
231
+ * Classify an isValidSignature probe. Empty return data means the account has no such
232
+ * function (the failure shape from issue #9); a 4-byte word means the interface exists,
233
+ * whatever it thought of the placeholder signature; a revert or transport failure is unknown.
234
+ */
235
+ export function classifyErc1271Probe(result, failed = false) {
236
+ if (failed)
237
+ return 'unknown';
238
+ const r = String(result || '').toLowerCase();
239
+ if (r === '' || r === '0x')
240
+ return 'no';
241
+ if (/^0x[0-9a-f]{8}0{56}$/.test(r))
242
+ return 'yes';
243
+ return 'unknown';
244
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentwallet-mcp",
3
3
  "mcpName": "io.github.hifriendbot/agentwallet",
4
- "version": "1.12.3",
4
+ "version": "1.12.4",
5
5
  "description": "MCP server for AgentWallet: self-custody local signing on EVM and Solana, or hosted wallets. Sign, broadcast, pay x402 invoices, and accept x402 payments.",
6
6
  "type": "module",
7
7
  "main": "build/index.js",