@agent402-dev/pay-mcp 0.3.0 → 0.5.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/dist/policy.js CHANGED
@@ -57,6 +57,7 @@ export function policyFromEnv(env) {
57
57
  maxUsdPerDay: num(env.X402_MAX_USD_PER_DAY, 1),
58
58
  maxUsdPerRecipientPerDay: Number(env.X402_MAX_USD_PER_RECIPIENT_PER_DAY) > 0 ? Number(env.X402_MAX_USD_PER_RECIPIENT_PER_DAY) : null,
59
59
  maxPreqPerRecipientPerDay: atomic(env.X402_MAX_PREQ_PER_RECIPIENT_PER_DAY_ATOMIC),
60
+ lock: lockPolicyFromEnv(env),
60
61
  confirmAboveUsd: env.X402_CONFIRM_ABOVE_USD ? Number(env.X402_CONFIRM_ABOVE_USD) : null,
61
62
  tokenLimits: { PREQ: limitsFor('PREQ'), A402: limitsFor('A402') },
62
63
  prefer,
@@ -82,6 +83,28 @@ export function domainCheck(p, url) {
82
83
  return { ok: false, reason: `domain_not_allowed: ${host}` };
83
84
  return { ok: true, host };
84
85
  }
86
+ export const WSOL_MINT = 'So11111111111111111111111111111111111111112';
87
+ function lockPolicyFromEnv(env) {
88
+ const always = env.X402_REQUIRE_LOCK === 'yes';
89
+ const aboveUsd = Number(env.X402_REQUIRE_LOCK_ABOVE_USD) > 0 ? Number(env.X402_REQUIRE_LOCK_ABOVE_USD) : null;
90
+ const min = {};
91
+ for (const [a, v] of [['PREQ', env.X402_MIN_LOCK_PREQ_ATOMIC], ['USDC', env.X402_MIN_LOCK_USDC_ATOMIC], ['SOL', env.X402_MIN_LOCK_SOL_ATOMIC]]) {
92
+ const x = atomic(v);
93
+ if (x !== null)
94
+ min[a] = x;
95
+ }
96
+ if ((always || aboveUsd !== null) && !Object.keys(min).length) {
97
+ throw new Error('Lock requirement is on but no minimum is set: set at least one of X402_MIN_LOCK_PREQ_ATOMIC, X402_MIN_LOCK_USDC_ATOMIC, X402_MIN_LOCK_SOL_ATOMIC (smallest units).');
98
+ }
99
+ const days = Number(env.X402_MIN_LOCK_DAYS);
100
+ return { always, aboveUsd, minDays: Number.isFinite(days) && days >= 0 && env.X402_MIN_LOCK_DAYS ? days : 90, min };
101
+ }
102
+ /** Whether this payment option needs a seller lock check */
103
+ export function needsLock(p, e) {
104
+ if (p.lock.always)
105
+ return true;
106
+ return p.lock.aboveUsd !== null && e.asset === 'USDC' && e.usd !== null && e.usd >= p.lock.aboveUsd;
107
+ }
85
108
  const NO_RECIPIENT_USAGE = { count: 0, usd: 0, preq: 0n };
86
109
  export function symbolOf(p, mint) {
87
110
  if (!mint)
@@ -0,0 +1,24 @@
1
+ export declare const REGISTRATION_PATH = "/.well-known/agent402.json";
2
+ export declare const REGISTRATION_KIND = "agent402.seller-registration";
3
+ export interface RegistrationPayload {
4
+ v: 1;
5
+ kind: typeof REGISTRATION_KIND;
6
+ host: string;
7
+ payTo: string[];
8
+ locks: {
9
+ protocol: 'jupiter-lock' | 'streamflow';
10
+ account: string;
11
+ }[];
12
+ receiptSigners?: string[];
13
+ issuedAt: string;
14
+ expiresAt?: string;
15
+ }
16
+ export type VerifiedRegistration = {
17
+ ok: true;
18
+ payload: RegistrationPayload;
19
+ signers: Set<string>;
20
+ } | {
21
+ ok: false;
22
+ reason: string;
23
+ };
24
+ export declare function verifyRegistration(doc: unknown, host: string, now: Date): Promise<VerifiedRegistration>;
@@ -0,0 +1,39 @@
1
+ // Seller registration (Agent402 standard, asset-neutral): https://<seller host>/.well-known/agent402.json
2
+ // { "v": 1, "payload": "<base64url JSON>", "signatures": [{ "signer": "<base58 key>", "sig": "<base64url Ed25519 signature over the payload bytes>" }] }
3
+ // Payload: { v: 1, kind: "agent402.seller-registration", host, payTo: [...], locks: [{ protocol: "jupiter-lock" | "streamflow", account }], receiptSigners?: [...], issuedAt, expiresAt? }
4
+ // Each lock counts only if its recipient key signed the payload, so nobody can claim someone else's lock.
5
+ import { getBase58Encoder } from '@solana/kit';
6
+ export const REGISTRATION_PATH = '/.well-known/agent402.json';
7
+ export const REGISTRATION_KIND = 'agent402.seller-registration';
8
+ const b64 = (s) => new Uint8Array(Buffer.from(s, 'base64url'));
9
+ export async function verifyRegistration(doc, host, now) {
10
+ const d = doc;
11
+ if (!d || d.v !== 1 || typeof d.payload !== 'string' || !Array.isArray(d.signatures))
12
+ return { ok: false, reason: 'registration_malformed' };
13
+ const bytes = b64(d.payload);
14
+ let p;
15
+ try {
16
+ p = JSON.parse(new TextDecoder().decode(bytes));
17
+ }
18
+ catch {
19
+ return { ok: false, reason: 'registration_malformed' };
20
+ }
21
+ if (p.v !== 1 || p.kind !== REGISTRATION_KIND || !Array.isArray(p.payTo) || !Array.isArray(p.locks))
22
+ return { ok: false, reason: 'registration_unknown_format' };
23
+ if (String(p.host).toLowerCase() !== host.toLowerCase())
24
+ return { ok: false, reason: `registration_host_mismatch: ${p.host}` };
25
+ if (p.expiresAt && Date.parse(p.expiresAt) <= now.getTime())
26
+ return { ok: false, reason: 'registration_expired' };
27
+ const signers = new Set();
28
+ for (const s of d.signatures.slice(0, 16)) {
29
+ if (typeof s?.signer !== 'string' || typeof s.sig !== 'string')
30
+ continue;
31
+ try {
32
+ const key = await crypto.subtle.importKey('raw', getBase58Encoder().encode(s.signer), { name: 'Ed25519' }, false, ['verify']);
33
+ if (await crypto.subtle.verify('Ed25519', key, b64(s.sig), bytes))
34
+ signers.add(s.signer);
35
+ }
36
+ catch { /* invalid key or signature: ignored */ }
37
+ }
38
+ return { ok: true, payload: p, signers };
39
+ }
package/dist/server.js CHANGED
@@ -11,6 +11,9 @@ import { join } from 'node:path';
11
11
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
12
12
  import { historyToCsv } from './csv.js';
13
13
  import { jsonlHistory } from './history.js';
14
+ import { rpcAccounts } from './locks.js';
15
+ import { rpcClock } from './bond.js';
16
+ import { bondPolicyFromEnv, bondRpc } from './bond-sign.js';
14
17
  import { initWallet } from './init.js';
15
18
  import { policyFromEnv } from './policy.js';
16
19
  import { createPayServer } from './tools.js';
@@ -74,5 +77,6 @@ else {
74
77
  })
75
78
  : null;
76
79
  const history = jsonlHistory(process.env.X402_HISTORY_PATH ?? DEFAULT_HISTORY, () => policy.mints);
77
- await createPayServer({ policy, wallet, history, fetch }).connect(new StdioServerTransport());
80
+ const rpc = process.env.X402_RPC_URL ?? (policy.network.includes('EtWTRAB') ? 'https://api.devnet.solana.com' : 'https://api.mainnet-beta.solana.com');
81
+ await createPayServer({ policy, wallet, history, fetch, accounts: rpcAccounts(rpc), clock: rpcClock(rpc), bondPolicy: bondPolicyFromEnv(process.env), bondRpc: bondRpc(rpc) }).connect(new StdioServerTransport());
78
82
  }
@@ -0,0 +1 @@
1
+ export declare function withSpendLock<T>(fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,8 @@
1
+ // One spending operation at a time per process: limit check → human confirmation → sign → send → record.
2
+ // Without this, two tool calls in parallel could both pass the daily cap before either is recorded.
3
+ let tail = Promise.resolve();
4
+ export function withSpendLock(fn) {
5
+ const run = tail.then(fn, fn);
6
+ tail = run.catch(() => undefined);
7
+ return run;
8
+ }
package/dist/tools.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type BondPolicy, type BondRpc } from './bond-sign.js';
2
3
  import type { History } from './history.js';
4
+ import type { AccountsFetcher } from './locks.js';
3
5
  import { type PayPolicy } from './policy.js';
4
6
  import type { Wallet } from './wallet.js';
5
7
  export interface PayServerDeps {
@@ -8,5 +10,13 @@ export interface PayServerDeps {
8
10
  history: History;
9
11
  fetch: typeof fetch;
10
12
  now?: () => Date;
13
+ /** Read-only account reader for seller lock checks and bond_deal_status */
14
+ accounts?: AccountsFetcher;
15
+ /** Solana clock (unix seconds) for the bond tools */
16
+ clock?: () => Promise<bigint>;
17
+ /** Agent402 Bond signing rules (bondPolicyFromEnv). Missing = bond signing tools refuse */
18
+ bondPolicy?: BondPolicy;
19
+ /** RPC for sending bond transactions */
20
+ bondRpc?: BondRpc;
11
21
  }
12
22
  export declare function createPayServer(d: PayServerDeps): McpServer;
package/dist/tools.js CHANGED
@@ -1,7 +1,11 @@
1
- // @agent402-dev/pay-mcp's 4 tools: x402_fetch, x402_quote, wallet_status, payment_history
1
+ // @agent402-dev/pay-mcp's 11 tools: x402_fetch, x402_quote, wallet_status, payment_history, and Agent402 Bond: bond_deal_status (read-only), bond_open, bond_confirm_and_pay, bond_settle, and the Bond Job Protocol: bond_job_quote (read-only), bond_job_start, bond_job_result
2
2
  import { z } from 'zod';
3
3
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { createAgent } from './agent.js';
5
+ import { bondDealStatus } from './bond.js';
6
+ import { bondConfirmAndPay, bondOpen, bondSettle } from './bond-sign.js';
7
+ import { bondJobQuote, bondJobResult, bondJobStart } from './bond-job.js';
8
+ import { withSpendLock } from './spend-lock.js';
5
9
  import { historyToCsv } from './csv.js';
6
10
  import { nearLimits, tokenEnv } from './policy.js';
7
11
  import { formatUnits } from './units.js';
@@ -37,7 +41,7 @@ function tokenLimitFields(p, t) {
37
41
  };
38
42
  }
39
43
  export function createPayServer(d) {
40
- const server = new McpServer({ name: 'a402-pay', version: '0.3.0' });
44
+ const server = new McpServer({ name: 'a402-pay', version: '0.5.0' });
41
45
  const confirm = async (message) => {
42
46
  if (!server.server.getClientCapabilities()?.elicitation)
43
47
  return 'unsupported';
@@ -49,7 +53,7 @@ export function createPayServer(d) {
49
53
  };
50
54
  const agent = createAgent({ ...d, confirm });
51
55
  const req = { url: z.string().url(), method: z.enum(['GET', 'POST']).optional(), headers: z.record(z.string(), z.string()).optional(), body: z.string().max(100_000).optional() };
52
- server.tool('x402_fetch', 'Fetch a URL and, if it answers HTTP 402 (x402), pay from the configured wallet only when every rule passes before signing: allowed domain (X402_ALLOWED_DOMAINS), trusted recipient (X402_TRUSTED_PAY_TO), allowed asset (USDC by default; PREQ only if listed; A402 (v1) is deprecated), per-payment and daily limits, and human confirmation above the configured amount. Signs at most once per call. Pass quoteId from x402_quote to refuse if the requirements changed. The wallet key never leaves this machine.', { ...req, quoteId: z.string().optional() }, async (a) => { const r = await agent.payAndFetch(a); return out(withUnits(r), !['paid', 'not_required'].includes(r.result)); });
56
+ server.tool('x402_fetch', 'Fetch a URL and, if it answers HTTP 402 (x402), pay from the configured wallet only when every rule passes before signing: allowed domain (X402_ALLOWED_DOMAINS), trusted recipient (X402_TRUSTED_PAY_TO), allowed asset (USDC by default; PREQ only if listed; A402 (v1) is deprecated), per-payment and daily limits, and human confirmation above the configured amount. Signs at most once per call. Pass quoteId from x402_quote to refuse if the requirements changed. The wallet key never leaves this machine.', { ...req, quoteId: z.string().optional() }, async (a) => { const r = await withSpendLock(() => agent.payAndFetch(a)); return out(withUnits(r), !['paid', 'not_required'].includes(r.result)); });
53
57
  server.tool('x402_quote', 'Show the x402 payment requirements of a URL and whether each option passes the payment rules. Never signs or pays. Returns a quoteId that x402_fetch can use to pin the amount, asset and recipient.', req, async (a) => { const r = await agent.quote(a); return out(withUnits(r), r.result === 'refused'); });
54
58
  server.tool('wallet_status', 'Payment wallet address, network, USDC and PREQ balances, payments signed today, and the configured limits and allowlists.', {}, async () => {
55
59
  const usage = d.history.today(d.now?.());
@@ -73,12 +77,20 @@ export function createPayServer(d) {
73
77
  maxUsdPerPayment: d.policy.maxUsdPerPayment, maxUsdPerDay: d.policy.maxUsdPerDay, maxPaymentsPerDay: d.policy.maxPaymentsPerDay,
74
78
  confirmAboveUsd: d.policy.confirmAboveUsd,
75
79
  maxUsdPerRecipientPerDay: d.policy.maxUsdPerRecipientPerDay,
80
+ sellerLock: d.policy.lock.always || d.policy.lock.aboveUsd !== null
81
+ ? { required: d.policy.lock.always ? 'always' : `USDC payments of ${d.policy.lock.aboveUsd} USD or more`, minDays: d.policy.lock.minDays, minimums: d.policy.lock.min }
82
+ : 'off',
76
83
  maxPreqPerRecipientPerDayAtomic: d.policy.maxPreqPerRecipientPerDay,
77
84
  ...tokenLimitFields(d.policy, 'PREQ'),
78
85
  ...(showA402 ? tokenLimitFields(d.policy, 'A402') : {}),
79
86
  units: '…Usd = US dollars (USDC); …Atomic = token smallest unit (1 PREQ = 1,000,000)',
80
87
  },
81
88
  allowedDomains: d.policy.allowedDomains, trustedPayTo: d.policy.trustedPayTo, allowedAssets: d.policy.allowedAssets,
89
+ bond: d.bondPolicy ? {
90
+ sellers: d.bondPolicy.sellers, maxUsdPerDeal: d.bondPolicy.maxPriceUsd ?? 'not set (X402_BOND_MAX_USD) — bond_open refused',
91
+ minSellerBondBps: d.bondPolicy.minBondBps.toString(), maxDays: d.bondPolicy.maxDays, confirmAboveUsd: d.bondPolicy.confirmAboveUsd,
92
+ note: 'Bond deposits and balances count toward the daily USDC cap and payment count.',
93
+ } : 'off',
82
94
  ...(d.policy.warnings.length || near.length ? { warnings: [...d.policy.warnings, ...near] } : {}),
83
95
  ...(d.wallet ? {} : { note: 'No wallet configured (X402_KEYPAIR_PATH): x402_fetch will not pay.' }),
84
96
  }));
@@ -87,5 +99,36 @@ export function createPayServer(d) {
87
99
  const xs = d.history.list(limit ?? 20);
88
100
  return format === 'csv' ? { content: [{ type: 'text', text: historyToCsv([...xs].reverse()) }] } : out(withUnits(xs));
89
101
  });
102
+ server.tool('bond_deal_status', 'Read-only. Show an Agent402 Bond deal (program 9hiCZZ6ddFG9oJBR1Su43Pj4JRFHeHC5cGiCgXtTuAaK): parties, amounts with units, deadlines on the Solana clock, what each side can still do, and the settlement that applies now or the earliest time it opens. Never signs. Predicted from the program rules; the program on chain decides.', { deal: z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/, 'Solana base58 deal account address') }, async ({ deal }) => {
103
+ if (!d.accounts || !d.clock)
104
+ return out({ result: 'unavailable', message: 'No RPC configured for reading accounts (X402_RPC_URL).' }, true);
105
+ try {
106
+ const r = await bondDealStatus({ accounts: d.accounts, clock: d.clock, wallet: d.wallet?.address ?? null }, deal);
107
+ return out(r, r.result === 'not_found' || r.result === 'not_a_deal');
108
+ }
109
+ catch {
110
+ return out({ result: 'rpc_error', message: 'Could not read the deal from the configured RPC.' }, true);
111
+ }
112
+ });
113
+ // Signing tools refuse by themselves when there is no wallet (signer null)
114
+ const bondDeps = () => (d.accounts && d.clock && d.bondPolicy && d.bondRpc
115
+ ? { policy: d.policy, bond: d.bondPolicy, signer: d.wallet ? { address: d.wallet.address, signBytes: (m) => d.wallet.signBytes(m) } : null,
116
+ rpc: d.bondRpc, history: d.history, confirm, accounts: d.accounts, clock: d.clock, wallet: d.wallet?.address ?? null, now: d.now, fetch: d.fetch }
117
+ : null);
118
+ const noBond = () => out({ result: 'refused', reasons: ['Agent402 Bond is not configured (RPC and bond rules)'] }, true);
119
+ const ADDR = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/, 'Solana base58 address');
120
+ server.tool('bond_open', 'Agent402 Bond, buyer side. Sign an `open` transaction that the seller built and signed as fee payer (base64, legacy). Before signing, the instruction is rebuilt for this wallet from its own terms and must match byte for byte (one instruction, seller and this wallet as the only signers, USDC). Rules: seller in X402_BOND_SELLERS, price at most X402_BOND_MAX_USD, seller bond at least X402_BOND_MIN_SELLER_BOND_BPS (default 5%), delivery within X402_BOND_MAX_DAYS (default 30), the deposit within the daily USDC cap, and human confirmation (by default always). Empty settings refuse everything. Locks this wallet\'s deposit in the deal vault.', { transaction: z.string().min(100).max(4000) }, async ({ transaction }) => { const b = bondDeps(); if (!b)
121
+ return noBond(); const r = await withSpendLock(() => bondOpen(b, transaction)); return out(r, r.result !== 'opened'); });
122
+ server.tool('bond_confirm_and_pay', 'Agent402 Bond, buyer side. Confirm receipt and pay the balance (price minus deposit) directly to the seller. Only for deals where this wallet is the buyer, before the buyer deadline, within the daily USDC cap, with human confirmation (by default always). Confirming releases the seller bond and the deposit to the seller; the program does not judge quality.', { deal: ADDR }, async ({ deal }) => { const b = bondDeps(); if (!b)
123
+ return noBond(); const r = await withSpendLock(() => bondConfirmAndPay(b, deal)); return out(r, r.result !== 'confirmed_and_paid'); });
124
+ server.tool('bond_settle', 'Agent402 Bond. Settle a deal whose outcome is fixed by signatures and time, then send both claims in the same transaction (buyer share, then seller share). Only for deals where this wallet is the buyer or the seller; this wallet pays only the network fee.', { deal: ADDR }, async ({ deal }) => { const b = bondDeps(); if (!b)
125
+ return noBond(); const r = await withSpendLock(() => bondSettle(b, deal)); return out(r, r.result !== 'settled'); });
126
+ const URL_ = z.string().url();
127
+ server.tool('bond_job_quote', 'Agent402 Bond Job Protocol v1. Read a seller\'s job quote (GET {url}/quote) and check it against this wallet\'s bond rules: seller in X402_BOND_SELLERS, price at most X402_BOND_MAX_USD, seller bond at least the minimum share, delivery time, and the daily USDC cap. The URL host must be in X402_ALLOWED_DOMAINS. Never signs.', { url: URL_ }, async ({ url }) => { const b = bondDeps(); if (!b)
128
+ return noBond(); const r = await bondJobQuote(b, url); return out(r, r.result !== 'ok'); });
129
+ server.tool('bond_job_start', 'Agent402 Bond Job Protocol v1, buyer side. Send the job input (POST {url}/open), receive the seller-signed open transaction, check that the quote, the reported terms and the transaction terms all agree, then run bond_open (rebuild and compare, bond rules, human confirmation). Locks your deposit. Returns the deal address.', { url: URL_, input: z.string().min(1).max(16_384) }, async ({ url, input }) => { const b = bondDeps(); if (!b)
130
+ return noBond(); const r = await withSpendLock(() => bondJobStart(b, url, input)); return out(r, r.result !== 'opened'); });
131
+ server.tool('bond_job_result', 'Agent402 Bond Job Protocol v1, buyer side. Fetch the delivered work for a deal where this wallet is the buyer (POST {url}/deliver with a signed request; the signed bytes start with 0xff so they can never be a transaction). Does not confirm or pay: check the work, then call bond_confirm_and_pay only if it is acceptable.', { url: URL_, deal: ADDR }, async ({ url, deal }) => { const b = bondDeps(); if (!b)
132
+ return noBond(); const r = await bondJobResult(b, url, deal); return out(r, r.result !== 'delivered'); });
90
133
  return server;
91
134
  }
package/dist/units.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const DECIMALS = 6;
2
2
  /** Base-unit integer → "140,000 PREQ" */
3
- export declare function formatUnits(atomic: string | bigint, symbol: string): string;
3
+ export declare function formatUnits(atomic: string | bigint, symbol: string, decimals?: number): string;
4
4
  /** "140,000 PREQ (140000000000 smallest units)" */
5
5
  export declare const withSmallest: (atomic: string | bigint, symbol: string) => string;
package/dist/units.js CHANGED
@@ -1,10 +1,12 @@
1
1
  // Amount display: USDC and PREQ (and the deprecated A402) all have 6 decimals. Token amounts are always shown with units
2
2
  export const DECIMALS = 6;
3
3
  /** Base-unit integer → "140,000 PREQ" */
4
- export function formatUnits(atomic, symbol) {
5
- const s = atomic.toString().padStart(DECIMALS + 1, '0');
6
- const int = s.slice(0, -DECIMALS).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
7
- const frac = s.slice(-DECIMALS).replace(/0+$/, '');
4
+ export function formatUnits(atomic, symbol, decimals = DECIMALS) {
5
+ if (decimals === 0)
6
+ return `${atomic.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')} ${symbol}`;
7
+ const s = atomic.toString().padStart(decimals + 1, '0');
8
+ const int = s.slice(0, -decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
9
+ const frac = s.slice(-decimals).replace(/0+$/, '');
8
10
  return `${int}${frac ? '.' + frac : ''} ${symbol}`;
9
11
  }
10
12
  /** "140,000 PREQ (140000000000 smallest units)" */
package/dist/wallet.d.ts CHANGED
@@ -8,5 +8,7 @@ export interface Wallet {
8
8
  /** Number of signatures made in this process */
9
9
  readonly signedCount: number;
10
10
  balances(): Promise<Record<string, string>>;
11
+ /** Raw ed25519 signature over transaction message bytes (Agent402 Bond tools only; every rule is checked by the caller first) */
12
+ signBytes(message: Uint8Array): Promise<Uint8Array>;
11
13
  }
12
14
  export declare function loadWallet(keyPath: string, policy: PayPolicy, rpcUrl?: string): Promise<Wallet>;
package/dist/wallet.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Payment wallet: signs x402 exact payment transactions with a key file on the user's computer (official @x402 client).
2
2
  // The key is never sent to the server; only the partially signed transaction goes in the PAYMENT-SIGNATURE header. This module signs only one requirement that passed the policy check
3
3
  import { readFileSync } from 'node:fs';
4
- import { createKeyPairSignerFromBytes } from '@solana/kit';
4
+ import { createKeyPairSignerFromBytes, signBytes } from '@solana/kit';
5
5
  import { encodePaymentSignatureHeader } from '@x402/core/http';
6
6
  import { x402Client } from '@x402/fetch';
7
7
  import { toClientSvmSigner } from '@x402/svm';
@@ -32,6 +32,11 @@ export async function loadWallet(keyPath, policy, rpcUrl) {
32
32
  address: signer.address,
33
33
  network: policy.network,
34
34
  get signedCount() { return signed; },
35
+ async signBytes(message) {
36
+ const sig = new Uint8Array(await signBytes(signer.keyPair.privateKey, message));
37
+ signed++;
38
+ return sig;
39
+ },
35
40
  async sign(resource, requirement) {
36
41
  const payload = await client.createPaymentPayload({ x402Version: 2, resource, accepts: [requirement] });
37
42
  signed++;
package/package.json CHANGED
@@ -20,6 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
+ "@agent402-dev/bond-client": "^0.2.0",
23
24
  "@modelcontextprotocol/sdk": "1.32.2",
24
25
  "@solana/kit": "8.6.0",
25
26
  "@x402/core": "2.31.0",
@@ -27,7 +28,7 @@
27
28
  "@x402/svm": "2.31.0",
28
29
  "zod": "^4.6.7"
29
30
  },
30
- "version": "0.3.0",
31
+ "version": "0.5.0",
31
32
  "author": "Agent402",
32
33
  "license": "Apache-2.0",
33
34
  "type": "module",