@agent402-dev/pay-server 0.3.0 → 0.4.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
@@ -90,6 +90,25 @@ const gate = createPaymentGate({ /* ... */ receipts: { signer } });
90
90
  - Publish the receipt key's public key (`signer.publicKey`) so buyers can tell that receipts come from you.
91
91
  - If signing fails, the paid resource is still delivered, without a receipt.
92
92
 
93
+ ## Seller registration and locks (optional)
94
+ Buyers using `@agent402-dev/pay-mcp` can require sellers to have an on-chain lock. To be eligible, lock tokens (PREQ, USDC or wrapped SOL) with [Jupiter Lock](https://lock.jup.ag/) to your own address with **no cancel and no recipient-change permission**, then serve a signed registration at `https://<your host>/.well-known/agent402.json`:
95
+
96
+ ```ts
97
+ import { receiptSignerFromBytes, signRegistration } from '@agent402-dev/pay-server';
98
+
99
+ const lockKey = await receiptSignerFromBytes(lockRecipientKeyBytes); // offline; the key that receives the lock
100
+ const doc = await signRegistration({ host: 'api.example.com', payTo: ['YOUR_RECEIVING_ADDRESS'], locks: [{ protocol: 'jupiter-lock', account: 'LOCK_ESCROW_ADDRESS' }] }, [lockKey]);
101
+ // Serve JSON.stringify(doc) at /.well-known/agent402.json
102
+ ```
103
+ Or from the command line (keys are read on your computer and never sent):
104
+ ```bash
105
+ npx -y @agent402-dev/pay-server register --host api.example.com --pay-to <receiving address> \
106
+ --lock jupiter-lock:<lock escrow address> --key <lock recipient key file> --out agent402.json
107
+ ```
108
+ - Sign offline and serve only the resulting document. The gate never needs the lock key or the receiving wallet's key.
109
+ - Use a lock received by a regular key. A lock received by a multisig vault cannot sign the registration yet.
110
+ - The format is the same for every asset. A lock is a commitment signal only; nothing can be confiscated.
111
+
93
112
  ## Data
94
113
  - No telemetry and no analytics.
95
114
  - It contacts only the facilitators you configure (`/supported`, `/verify`, `/settle`) and the RPC you pass to `rpcChain` (settlement checks, receiving token accounts, pool prices for the PREQ rate).
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ // @agent402-dev/pay-server command line: register (signed seller registration). The library itself is used from code (createPaymentGate).
3
+ import { writeFileSync } from 'node:fs';
4
+ import { buildRegistration, REGISTER_HELP } from './register.js';
5
+ const [cmd, ...args] = process.argv.slice(2);
6
+ if (cmd === 'register') {
7
+ try {
8
+ const doc = await buildRegistration(args);
9
+ const json = JSON.stringify(doc, null, 2) + '\n';
10
+ const i = args.indexOf('--out');
11
+ if (i >= 0 && args[i + 1]) {
12
+ writeFileSync(args[i + 1], json, { flag: 'wx' });
13
+ console.error(`Wrote ${args[i + 1]}. Serve it at /.well-known/agent402.json`);
14
+ }
15
+ else
16
+ process.stdout.write(json);
17
+ }
18
+ catch (e) {
19
+ console.error(e.code === 'EEXIST' ? 'The --out file already exists. It was not changed.' : e.message);
20
+ process.exitCode = 1;
21
+ }
22
+ }
23
+ else {
24
+ console.log(REGISTER_HELP);
25
+ if (cmd && cmd !== 'help' && cmd !== '--help')
26
+ process.exitCode = 2;
27
+ }
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export { rpcChain, receivedBy, type ChainReader, type ChainTx, type AccountFetch
4
4
  export { createRateBook, memoryRateStore, type RateBook, type RateStore } from './rates.js';
5
5
  export { DEFAULT_GUARDS, fixRate, samplePrice, tokenAmountFor, PREQ_POOL_TARGET, A402_POOL_TARGET, type DailyRate, type PoolTarget, type PriceSample, type RateGuards, } from './pricing.js';
6
6
  export { receiptSignerFromBytes, signReceipt, RECEIPT_HEADER, type Receipt, type ReceiptSigner } from './receipt.js';
7
+ export { signRegistration, REGISTRATION_PATH, type RegistrationDocument, type RegistrationPayload } from './registration.js';
7
8
  export { memoryX402Ledger, ledgerClaim, SETTLE_UNKNOWN_EXPIRY_MS, type X402Ledger, type LedgerEntry, type Asset } from './x402.js';
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ export { rpcChain, receivedBy } from './chain.js';
6
6
  export { createRateBook, memoryRateStore } from './rates.js';
7
7
  export { DEFAULT_GUARDS, fixRate, samplePrice, tokenAmountFor, PREQ_POOL_TARGET, A402_POOL_TARGET, } from './pricing.js';
8
8
  export { receiptSignerFromBytes, signReceipt, RECEIPT_HEADER } from './receipt.js';
9
+ export { signRegistration, REGISTRATION_PATH } from './registration.js';
9
10
  export { memoryX402Ledger, ledgerClaim, SETTLE_UNKNOWN_EXPIRY_MS } from './x402.js';
@@ -0,0 +1,3 @@
1
+ import { type RegistrationDocument } from './registration.js';
2
+ export declare const REGISTER_HELP = "agent402-pay-server register \u2014 make a signed seller registration (asset-neutral)\n\n --host <host> host buyers call, e.g. api.example.com (required)\n --pay-to <address>[,<address>] receiving addresses (required)\n --lock <protocol>:<account> a lock account; protocol jupiter-lock or streamflow (repeat for more)\n --key <file> Solana CLI key file of a lock recipient; signs the registration (repeat for more)\n --receipt-signer <public key> receipt key buyers should expect (optional, repeatable)\n --expires-days <n> expiry in days (optional)\n --out <file> write here (never overwrites); default: print to the terminal\n\nServe the output at https://<host>/.well-known/agent402.json. Keys stay on this computer.";
3
+ export declare function buildRegistration(argv: string[], now?: Date, read?: (p: string) => string): Promise<RegistrationDocument>;
@@ -0,0 +1,54 @@
1
+ // `agent402-pay-server register`: makes the signed seller registration (/.well-known/agent402.json) from key files on this computer.
2
+ // Keys are read locally and never sent anywhere. Sign with the key that receives each lock (not the receiving wallet's key, unless it is the same).
3
+ import { readFileSync } from 'node:fs';
4
+ import { receiptSignerFromBytes } from './receipt.js';
5
+ import { signRegistration } from './registration.js';
6
+ export const REGISTER_HELP = `agent402-pay-server register — make a signed seller registration (asset-neutral)
7
+
8
+ --host <host> host buyers call, e.g. api.example.com (required)
9
+ --pay-to <address>[,<address>] receiving addresses (required)
10
+ --lock <protocol>:<account> a lock account; protocol jupiter-lock or streamflow (repeat for more)
11
+ --key <file> Solana CLI key file of a lock recipient; signs the registration (repeat for more)
12
+ --receipt-signer <public key> receipt key buyers should expect (optional, repeatable)
13
+ --expires-days <n> expiry in days (optional)
14
+ --out <file> write here (never overwrites); default: print to the terminal
15
+
16
+ Serve the output at https://<host>/.well-known/agent402.json. Keys stay on this computer.`;
17
+ const BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
18
+ export async function buildRegistration(argv, now = new Date(), read = (p) => readFileSync(p, 'utf8')) {
19
+ const all = (name) => argv.flatMap((a, i) => (a === name && argv[i + 1] ? [argv[i + 1]] : []));
20
+ const one = (name) => all(name)[0];
21
+ const host = one('--host');
22
+ if (!host || /[/:]/.test(host.replace(/:\d+$/, '')))
23
+ throw new Error('--host is required (a host name such as api.example.com, no scheme or path)');
24
+ const payTo = (one('--pay-to') ?? '').split(',').map((s) => s.trim()).filter(Boolean);
25
+ if (!payTo.length || payTo.some((a) => !BASE58.test(a)))
26
+ throw new Error('--pay-to needs one or more Solana addresses');
27
+ const locks = all('--lock').map((l) => {
28
+ const [protocol, account] = l.split(':');
29
+ if ((protocol !== 'jupiter-lock' && protocol !== 'streamflow') || !BASE58.test(account ?? ''))
30
+ throw new Error(`--lock ${l}: use jupiter-lock:<account> or streamflow:<account>`);
31
+ return { protocol, account };
32
+ });
33
+ const keyFiles = all('--key');
34
+ if (locks.length && !keyFiles.length)
35
+ throw new Error('--key is required: the lock recipient must sign, or buyers will not count the lock');
36
+ const signers = await Promise.all(keyFiles.map(async (f) => {
37
+ const bytes = Uint8Array.from(JSON.parse(read(f)));
38
+ try {
39
+ return await receiptSignerFromBytes(bytes);
40
+ }
41
+ finally {
42
+ bytes.fill(0);
43
+ }
44
+ }));
45
+ const receiptSigners = all('--receipt-signer');
46
+ if (receiptSigners.some((a) => !BASE58.test(a)))
47
+ throw new Error('--receipt-signer needs a base58 public key');
48
+ const days = Number(one('--expires-days'));
49
+ return signRegistration({
50
+ host, payTo, locks, issuedAt: now.toISOString(),
51
+ ...(receiptSigners.length ? { receiptSigners } : {}),
52
+ ...(days > 0 ? { expiresAt: new Date(now.getTime() + days * 86_400_000).toISOString() } : {}),
53
+ }, signers);
54
+ }
@@ -0,0 +1,29 @@
1
+ import { type ReceiptSigner } from './receipt.js';
2
+ export declare const REGISTRATION_PATH = "/.well-known/agent402.json";
3
+ export declare const REGISTRATION_KIND = "agent402.seller-registration";
4
+ export interface RegistrationPayload {
5
+ v: 1;
6
+ kind: typeof REGISTRATION_KIND;
7
+ /** Host buyers call (e.g. api.example.com), lowercase */
8
+ host: string;
9
+ payTo: string[];
10
+ locks: {
11
+ protocol: 'jupiter-lock' | 'streamflow';
12
+ account: string;
13
+ }[];
14
+ receiptSigners?: string[];
15
+ issuedAt: string;
16
+ expiresAt?: string;
17
+ }
18
+ export interface RegistrationDocument {
19
+ v: 1;
20
+ payload: string;
21
+ signatures: {
22
+ signer: string;
23
+ sig: string;
24
+ }[];
25
+ }
26
+ /** Signs a registration with each given key (usually the recipient key of every lock) */
27
+ export declare function signRegistration(p: Omit<RegistrationPayload, 'v' | 'kind' | 'issuedAt'> & {
28
+ issuedAt?: string;
29
+ }, signers: ReceiptSigner[]): Promise<RegistrationDocument>;
@@ -0,0 +1,13 @@
1
+ // Seller registration (Agent402 standard, asset-neutral): the JSON document a seller serves at https://<host>/.well-known/agent402.json
2
+ // It lists the receiving addresses and lock accounts, and each lock's recipient key signs it (so nobody can claim someone else's lock).
3
+ // @agent402-dev/pay-mcp reads it when a buyer requires a seller lock. Signing happens offline with the lock recipient's key; the gate never needs it.
4
+ import { b64url } from './receipt.js';
5
+ export const REGISTRATION_PATH = '/.well-known/agent402.json';
6
+ export const REGISTRATION_KIND = 'agent402.seller-registration';
7
+ /** Signs a registration with each given key (usually the recipient key of every lock) */
8
+ export async function signRegistration(p, signers) {
9
+ const payload = { v: 1, kind: REGISTRATION_KIND, ...p, host: p.host.toLowerCase(), issuedAt: p.issuedAt ?? new Date().toISOString() };
10
+ const bytes = new TextEncoder().encode(JSON.stringify(payload));
11
+ const signatures = await Promise.all(signers.map(async (s) => ({ signer: s.publicKey, sig: b64url(await s.sign(bytes)) })));
12
+ return { v: 1, payload: b64url(bytes), signatures };
13
+ }
package/package.json CHANGED
@@ -8,6 +8,9 @@
8
8
  "token-2022",
9
9
  "payments"
10
10
  ],
11
+ "bin": {
12
+ "agent402-pay-server": "./dist/cli.js"
13
+ },
11
14
  "main": "./dist/index.js",
12
15
  "types": "./dist/index.d.ts",
13
16
  "exports": {
@@ -25,7 +28,7 @@
25
28
  "@x402/core": "2.31.0",
26
29
  "@x402/svm": "2.31.0"
27
30
  },
28
- "version": "0.3.0",
31
+ "version": "0.4.0",
29
32
  "author": "Agent402",
30
33
  "license": "Apache-2.0",
31
34
  "type": "module",