@agentsmarket/cli 0.1.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 +91 -0
- package/dist/commands/balance.d.ts +1 -0
- package/dist/commands/balance.js +20 -0
- package/dist/commands/balance.js.map +1 -0
- package/dist/commands/call.d.ts +1 -0
- package/dist/commands/call.js +64 -0
- package/dist/commands/call.js.map +1 -0
- package/dist/commands/info.d.ts +11 -0
- package/dist/commands/info.js +60 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +12 -0
- package/dist/commands/init.js +80 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/install.d.ts +15 -0
- package/dist/commands/install.js +75 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/mcp.d.ts +14 -0
- package/dist/commands/mcp.js +275 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/publish.d.ts +1 -0
- package/dist/commands/publish.js +97 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/rate.d.ts +8 -0
- package/dist/commands/rate.js +24 -0
- package/dist/commands/rate.js.map +1 -0
- package/dist/commands/refund.d.ts +7 -0
- package/dist/commands/refund.js +38 -0
- package/dist/commands/refund.js.map +1 -0
- package/dist/commands/register.d.ts +6 -0
- package/dist/commands/register.js +55 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/rename.d.ts +7 -0
- package/dist/commands/rename.js +33 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/scan.d.ts +35 -0
- package/dist/commands/scan.js +193 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/search.d.ts +4 -0
- package/dist/commands/search.js +29 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +115 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +37 -0
- package/dist/lib/config.js +112 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/http.d.ts +25 -0
- package/dist/lib/http.js +105 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/keys.d.ts +69 -0
- package/dist/lib/keys.js +85 -0
- package/dist/lib/keys.js.map +1 -0
- package/dist/lib/payment-keys.d.ts +25 -0
- package/dist/lib/payment-keys.js +55 -0
- package/dist/lib/payment-keys.js.map +1 -0
- package/dist/lib/payment.d.ts +27 -0
- package/dist/lib/payment.js +123 -0
- package/dist/lib/payment.js.map +1 -0
- package/package.json +36 -0
package/dist/lib/http.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authenticated HTTP client for the marketplace server.
|
|
3
|
+
*
|
|
4
|
+
* Signs every request with the agent's Ed25519 key per server protocol:
|
|
5
|
+
* Headers:
|
|
6
|
+
* X-Agent-ID: ed25519:...
|
|
7
|
+
* X-Signature: base64(64-byte Ed25519 sig)
|
|
8
|
+
* X-Timestamp: unix ms (within 5 min drift)
|
|
9
|
+
* Message: METHOD\nPATH\nTIMESTAMP\nSHA256(BODY)
|
|
10
|
+
*/
|
|
11
|
+
import * as crypto from 'node:crypto';
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as os from 'node:os';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import { loadConfig } from './config.js';
|
|
17
|
+
import { loadPrivateKey, exportPublicKeyRaw } from './keys.js';
|
|
18
|
+
// Override at runtime with AGENTSMARKET_URL env var (used by smoke.sh, tests, dev).
|
|
19
|
+
const DEFAULT_BASE_URL = 'https://api.agentsmarket.world';
|
|
20
|
+
export class HttpError extends Error {
|
|
21
|
+
status;
|
|
22
|
+
code;
|
|
23
|
+
constructor(status, code, message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.name = 'HttpError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getKeyPath() {
|
|
31
|
+
const home = os.homedir();
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
return path.join(home, 'AppData', 'Roaming', 'agentsmarket', 'agent.key');
|
|
34
|
+
}
|
|
35
|
+
if (process.platform === 'darwin') {
|
|
36
|
+
return path.join(home, 'Library', 'Application Support', 'agentsmarket', 'agent.key');
|
|
37
|
+
}
|
|
38
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME ?? path.join(home, '.config');
|
|
39
|
+
return path.join(xdgConfig, 'agentsmarket', 'agent.key');
|
|
40
|
+
}
|
|
41
|
+
function getSigningKey() {
|
|
42
|
+
const config = loadConfig();
|
|
43
|
+
if (!config) {
|
|
44
|
+
throw new Error('Agent not initialized. Run `agentsmarket init` first.');
|
|
45
|
+
}
|
|
46
|
+
const pem = fs.readFileSync(getKeyPath(), 'utf-8');
|
|
47
|
+
const privateKey = loadPrivateKey(pem);
|
|
48
|
+
const publicKey = crypto.createPublicKey(privateKey);
|
|
49
|
+
const raw = exportPublicKeyRaw(publicKey);
|
|
50
|
+
const derivedId = 'ed25519:' + raw.toString('base64url');
|
|
51
|
+
if (derivedId !== config.agent_id) {
|
|
52
|
+
throw new Error(`Key file does not match stored agent_id. Stored: ${config.agent_id}, Derived: ${derivedId}`);
|
|
53
|
+
}
|
|
54
|
+
return { privateKey, agentId: config.agent_id };
|
|
55
|
+
}
|
|
56
|
+
function signRequest(privateKey, method, path, body) {
|
|
57
|
+
const timestamp = Date.now().toString();
|
|
58
|
+
const bodyHash = createHash('sha256').update(body || '').digest('hex');
|
|
59
|
+
const message = `${method}\n${path}\n${timestamp}\n${bodyHash}`;
|
|
60
|
+
const sig = crypto.sign(null, Buffer.from(message), privateKey);
|
|
61
|
+
return { signature: sig.toString('base64'), timestamp };
|
|
62
|
+
}
|
|
63
|
+
/** Make an authenticated request to the marketplace server. */
|
|
64
|
+
export async function authedFetch(method, path, body, opts = {}) {
|
|
65
|
+
const baseUrl = (opts.baseUrl ?? process.env.AGENTSMARKET_URL ?? DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
66
|
+
const bodyStr = body !== undefined ? JSON.stringify(body) : '';
|
|
67
|
+
const url = `${baseUrl}${path}`;
|
|
68
|
+
const headers = {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
};
|
|
71
|
+
if (opts.requireAuth !== false) {
|
|
72
|
+
const { privateKey, agentId } = getSigningKey();
|
|
73
|
+
const { signature, timestamp } = signRequest(privateKey, method, path, bodyStr);
|
|
74
|
+
headers['X-Agent-ID'] = agentId;
|
|
75
|
+
headers['X-Signature'] = signature;
|
|
76
|
+
headers['X-Timestamp'] = timestamp;
|
|
77
|
+
}
|
|
78
|
+
const res = await fetch(url, {
|
|
79
|
+
method,
|
|
80
|
+
headers,
|
|
81
|
+
body: method === 'GET' || method === 'HEAD' ? undefined : bodyStr,
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
let code = 'UNKNOWN';
|
|
85
|
+
let message = `HTTP ${res.status}`;
|
|
86
|
+
try {
|
|
87
|
+
const parsed = await res.json();
|
|
88
|
+
if (parsed.code)
|
|
89
|
+
code = parsed.code;
|
|
90
|
+
if (parsed.error)
|
|
91
|
+
message = `${parsed.code ?? 'UNKNOWN'}: ${parsed.error}`;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// not JSON
|
|
95
|
+
}
|
|
96
|
+
throw new HttpError(res.status, code, message);
|
|
97
|
+
}
|
|
98
|
+
return res;
|
|
99
|
+
}
|
|
100
|
+
/** Convenience: authed JSON request, returns parsed body. */
|
|
101
|
+
export async function authedJson(method, path, body, opts) {
|
|
102
|
+
const res = await authedFetch(method, path, body, opts);
|
|
103
|
+
return await res.json();
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAC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,IAAI,IAAI,GAAG,SAAS,CAAC;QACrB,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAuC,CAAC;YACrE,IAAI,MAAM,CAAC,IAAI;gBAAE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACpC,IAAI,MAAM,CAAC,KAAK;gBAAE,OAAO,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,SAAS,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;QAC7E,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;QACD,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,IAAY,EACZ,IAAc,EACd,IAAkD;IAElD,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxD,OAAO,MAAM,GAAG,CAAC,IAAI,EAAO,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 key management for agentsmarket agents.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node.js built-in `crypto` (RFC 8032 compliant). NO external crypto
|
|
5
|
+
* dependencies — battle-tested by the Node.js team.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY: This is the foundation of agent identity. If keys are generated
|
|
8
|
+
* incorrectly, agents lose their identity, reputation, and any funds.
|
|
9
|
+
* Every function here is unit-tested.
|
|
10
|
+
*/
|
|
11
|
+
import * as crypto from 'node:crypto';
|
|
12
|
+
/**
|
|
13
|
+
* Pair of Ed25519 keys for an agent.
|
|
14
|
+
*/
|
|
15
|
+
export interface AgentKeypair {
|
|
16
|
+
publicKey: crypto.KeyObject;
|
|
17
|
+
privateKey: crypto.KeyObject;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate a fresh Ed25519 keypair.
|
|
21
|
+
* Uses Node's built-in crypto (constant-time, side-channel resistant).
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateKeypair(): AgentKeypair;
|
|
24
|
+
/**
|
|
25
|
+
* Derive agent_id from public key.
|
|
26
|
+
*
|
|
27
|
+
* Format: "ed25519:" + base64url(raw 32-byte Ed25519 public key)
|
|
28
|
+
* Example: "ed25519:wdlEEYI0rCNkobjR0d1aPJBl6v2HQ4Sqh8C5FZ3mNoE"
|
|
29
|
+
*
|
|
30
|
+
* The base64url encoding has no padding and uses URL-safe characters.
|
|
31
|
+
*/
|
|
32
|
+
export declare function agentIdFromPublicKey(publicKey: crypto.KeyObject): string;
|
|
33
|
+
/**
|
|
34
|
+
* Export public key as raw 32-byte buffer.
|
|
35
|
+
*
|
|
36
|
+
* SPKI DER for Ed25519 ends with the BIT STRING containing the 32-byte key.
|
|
37
|
+
* The last 32 bytes of the DER encoding ARE the raw public key.
|
|
38
|
+
*/
|
|
39
|
+
export declare function exportPublicKeyRaw(publicKey: crypto.KeyObject): Buffer;
|
|
40
|
+
/**
|
|
41
|
+
* Export public key as hex string (64 chars).
|
|
42
|
+
* Useful for debugging.
|
|
43
|
+
*/
|
|
44
|
+
export declare function exportPublicKeyHex(publicKey: crypto.KeyObject): string;
|
|
45
|
+
/**
|
|
46
|
+
* Sign a message with the private key.
|
|
47
|
+
*
|
|
48
|
+
* Returns 64-byte Ed25519 signature.
|
|
49
|
+
*
|
|
50
|
+
* Ed25519 doesn't use a separate hash algorithm — first arg to crypto.sign is null.
|
|
51
|
+
*/
|
|
52
|
+
export declare function signMessage(privateKey: crypto.KeyObject, message: Buffer | Uint8Array): Buffer;
|
|
53
|
+
/**
|
|
54
|
+
* Verify a signature against a public key and message.
|
|
55
|
+
* Returns true if valid, false otherwise.
|
|
56
|
+
*/
|
|
57
|
+
export declare function verifySignature(publicKey: crypto.KeyObject, message: Buffer | Uint8Array, signature: Buffer | Uint8Array): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Load private key from PEM string (PKCS8 format).
|
|
60
|
+
*/
|
|
61
|
+
export declare function loadPrivateKey(pem: string): crypto.KeyObject;
|
|
62
|
+
/**
|
|
63
|
+
* Derive public key from private key.
|
|
64
|
+
*/
|
|
65
|
+
export declare function derivePublicKey(privateKey: crypto.KeyObject): crypto.KeyObject;
|
|
66
|
+
/**
|
|
67
|
+
* Export private key as PEM string (PKCS8 format, standard).
|
|
68
|
+
*/
|
|
69
|
+
export declare function exportPrivateKeyPem(privateKey: crypto.KeyObject): string;
|
package/dist/lib/keys.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 key management for agentsmarket agents.
|
|
3
|
+
*
|
|
4
|
+
* Uses Node.js built-in `crypto` (RFC 8032 compliant). NO external crypto
|
|
5
|
+
* dependencies — battle-tested by the Node.js team.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY: This is the foundation of agent identity. If keys are generated
|
|
8
|
+
* incorrectly, agents lose their identity, reputation, and any funds.
|
|
9
|
+
* Every function here is unit-tested.
|
|
10
|
+
*/
|
|
11
|
+
import * as crypto from 'node:crypto';
|
|
12
|
+
/**
|
|
13
|
+
* Generate a fresh Ed25519 keypair.
|
|
14
|
+
* Uses Node's built-in crypto (constant-time, side-channel resistant).
|
|
15
|
+
*/
|
|
16
|
+
export function generateKeypair() {
|
|
17
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync('ed25519');
|
|
18
|
+
return { publicKey, privateKey };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Derive agent_id from public key.
|
|
22
|
+
*
|
|
23
|
+
* Format: "ed25519:" + base64url(raw 32-byte Ed25519 public key)
|
|
24
|
+
* Example: "ed25519:wdlEEYI0rCNkobjR0d1aPJBl6v2HQ4Sqh8C5FZ3mNoE"
|
|
25
|
+
*
|
|
26
|
+
* The base64url encoding has no padding and uses URL-safe characters.
|
|
27
|
+
*/
|
|
28
|
+
export function agentIdFromPublicKey(publicKey) {
|
|
29
|
+
const raw = exportPublicKeyRaw(publicKey);
|
|
30
|
+
return 'ed25519:' + raw.toString('base64url');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Export public key as raw 32-byte buffer.
|
|
34
|
+
*
|
|
35
|
+
* SPKI DER for Ed25519 ends with the BIT STRING containing the 32-byte key.
|
|
36
|
+
* The last 32 bytes of the DER encoding ARE the raw public key.
|
|
37
|
+
*/
|
|
38
|
+
export function exportPublicKeyRaw(publicKey) {
|
|
39
|
+
const der = publicKey.export({ format: 'der', type: 'spki' });
|
|
40
|
+
return Buffer.from(der).subarray(-32);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Export public key as hex string (64 chars).
|
|
44
|
+
* Useful for debugging.
|
|
45
|
+
*/
|
|
46
|
+
export function exportPublicKeyHex(publicKey) {
|
|
47
|
+
return exportPublicKeyRaw(publicKey).toString('hex');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sign a message with the private key.
|
|
51
|
+
*
|
|
52
|
+
* Returns 64-byte Ed25519 signature.
|
|
53
|
+
*
|
|
54
|
+
* Ed25519 doesn't use a separate hash algorithm — first arg to crypto.sign is null.
|
|
55
|
+
*/
|
|
56
|
+
export function signMessage(privateKey, message) {
|
|
57
|
+
const signature = crypto.sign(null, Buffer.from(message), privateKey);
|
|
58
|
+
return Buffer.from(signature);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verify a signature against a public key and message.
|
|
62
|
+
* Returns true if valid, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
export function verifySignature(publicKey, message, signature) {
|
|
65
|
+
return crypto.verify(null, Buffer.from(message), publicKey, Buffer.from(signature));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Load private key from PEM string (PKCS8 format).
|
|
69
|
+
*/
|
|
70
|
+
export function loadPrivateKey(pem) {
|
|
71
|
+
return crypto.createPrivateKey(pem);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Derive public key from private key.
|
|
75
|
+
*/
|
|
76
|
+
export function derivePublicKey(privateKey) {
|
|
77
|
+
return crypto.createPublicKey(privateKey);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Export private key as PEM string (PKCS8 format, standard).
|
|
81
|
+
*/
|
|
82
|
+
export function exportPrivateKeyPem(privateKey) {
|
|
83
|
+
return privateKey.export({ format: 'pem', type: 'pkcs8' });
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/lib/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAUtC;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACxE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA2B;IAC9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC1C,OAAO,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAA2B;IAC5D,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,GAA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. Agent has BOTH:
|
|
5
|
+
* - Ed25519 (agent.key): identity + HTTP request signing
|
|
6
|
+
* - secp256k1 (payment.key): USDC payment authorization signing
|
|
7
|
+
*
|
|
8
|
+
* Both are saved as PKCS8 PEM (mode 0600). Node crypto handles both.
|
|
9
|
+
*/
|
|
10
|
+
import * as crypto from 'node:crypto';
|
|
11
|
+
export interface PaymentKeypair {
|
|
12
|
+
publicKey: crypto.KeyObject;
|
|
13
|
+
privateKey: crypto.KeyObject;
|
|
14
|
+
}
|
|
15
|
+
export declare function generatePaymentKeypair(): PaymentKeypair;
|
|
16
|
+
export declare function exportPaymentPublicKeyRaw(key: crypto.KeyObject): Buffer;
|
|
17
|
+
export declare function exportPaymentPublicKeyHex(key: crypto.KeyObject): string;
|
|
18
|
+
export declare function exportPaymentAddress(key: crypto.KeyObject): string;
|
|
19
|
+
export declare function loadPaymentPrivateKey(pem: string): crypto.KeyObject;
|
|
20
|
+
export declare function exportPaymentPrivateKeyPem(privateKey: crypto.KeyObject): string;
|
|
21
|
+
/**
|
|
22
|
+
* Sign a 32-byte message hash with secp256k1 (used for EIP-3009).
|
|
23
|
+
* Returns 65-byte signature: r (32) || s (32) || v (1, value 27 or 28).
|
|
24
|
+
*/
|
|
25
|
+
export declare function signSecp256k1(privateKey: crypto.KeyObject, msgHash: Buffer): Buffer;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secp256k1 key management for USDC payments (EIP-3009).
|
|
3
|
+
*
|
|
4
|
+
* Separate from Ed25519 agent identity keys. Agent has BOTH:
|
|
5
|
+
* - Ed25519 (agent.key): identity + HTTP request signing
|
|
6
|
+
* - secp256k1 (payment.key): USDC payment authorization signing
|
|
7
|
+
*
|
|
8
|
+
* Both are saved as PKCS8 PEM (mode 0600). Node crypto handles both.
|
|
9
|
+
*/
|
|
10
|
+
import * as crypto from 'node:crypto';
|
|
11
|
+
export function generatePaymentKeypair() {
|
|
12
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' });
|
|
13
|
+
return { publicKey, privateKey };
|
|
14
|
+
}
|
|
15
|
+
function toPublicKey(key) {
|
|
16
|
+
return key.type === 'private' ? crypto.createPublicKey(key) : key;
|
|
17
|
+
}
|
|
18
|
+
export function exportPaymentPublicKeyRaw(key) {
|
|
19
|
+
const der = toPublicKey(key).export({ format: 'der', type: 'spki' });
|
|
20
|
+
return Buffer.from(der).subarray(-65).subarray(1);
|
|
21
|
+
}
|
|
22
|
+
export function exportPaymentPublicKeyHex(key) {
|
|
23
|
+
return '0x' + exportPaymentPublicKeyRaw(key).toString('hex');
|
|
24
|
+
}
|
|
25
|
+
export function exportPaymentAddress(key) {
|
|
26
|
+
const uncompressed = exportPaymentPublicKeyRaw(key);
|
|
27
|
+
const hash = crypto.createHash('sha256').update(uncompressed).digest();
|
|
28
|
+
return '0x' + hash.subarray(-20).toString('hex');
|
|
29
|
+
}
|
|
30
|
+
export function loadPaymentPrivateKey(pem) {
|
|
31
|
+
return crypto.createPrivateKey(pem);
|
|
32
|
+
}
|
|
33
|
+
export function exportPaymentPrivateKeyPem(privateKey) {
|
|
34
|
+
return privateKey.export({ format: 'pem', type: 'pkcs8' });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sign a 32-byte message hash with secp256k1 (used for EIP-3009).
|
|
38
|
+
* Returns 65-byte signature: r (32) || s (32) || v (1, value 27 or 28).
|
|
39
|
+
*/
|
|
40
|
+
export function signSecp256k1(privateKey, msgHash) {
|
|
41
|
+
const sig = crypto.sign('sha256', msgHash, { key: privateKey, dsaEncoding: 'der' });
|
|
42
|
+
const der = Buffer.from(sig);
|
|
43
|
+
if (der.length < 8)
|
|
44
|
+
throw new Error('invalid DER signature');
|
|
45
|
+
const rLen = der[3];
|
|
46
|
+
const sLen = der[4 + rLen];
|
|
47
|
+
const r = der.subarray(4, 4 + rLen);
|
|
48
|
+
const sStart = 4 + rLen + 2;
|
|
49
|
+
const s = der.subarray(sStart, sStart + sLen);
|
|
50
|
+
let rPadded = r.length === 32 ? r : (r.length < 32 ? Buffer.concat([Buffer.alloc(32 - r.length), r]) : r.subarray(-32));
|
|
51
|
+
let sPadded = s.length === 32 ? s : (s.length < 32 ? Buffer.concat([Buffer.alloc(32 - s.length), s]) : s.subarray(-32));
|
|
52
|
+
const v = 27 + (der[der.length - 1] & 1);
|
|
53
|
+
return Buffer.concat([rPadded, sPadded, Buffer.from([v])]);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=payment-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-keys.js","sourceRoot":"","sources":["../../src/lib/payment-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAOtC,MAAM,UAAU,sBAAsB;IACpC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAChG,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,GAAqB;IACxC,OAAO,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAqB;IAC7D,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAqB;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
|
4
|
+
* Phase 2 MVP: build the typed data for USDC on Base Sepolia, sign with
|
|
5
|
+
* secp256k1, submit to server. Server verifies signature, nonce uniqueness,
|
|
6
|
+
* and time window.
|
|
7
|
+
*/
|
|
8
|
+
import type { KeyObject } from 'node:crypto';
|
|
9
|
+
export interface Eip3009Payload {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
value: string;
|
|
13
|
+
validAfter: string;
|
|
14
|
+
validBefore: string;
|
|
15
|
+
nonce: string;
|
|
16
|
+
v: number;
|
|
17
|
+
r: string;
|
|
18
|
+
s: string;
|
|
19
|
+
}
|
|
20
|
+
export interface BuildAuthorizationParams {
|
|
21
|
+
privateKey: KeyObject;
|
|
22
|
+
to: string;
|
|
23
|
+
valueUsdcBaseUnits: string | number;
|
|
24
|
+
validForSeconds?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function buildAndSignAuthorization(params: BuildAuthorizationParams): Eip3009Payload;
|
|
27
|
+
export declare function loadPaymentKey(pem: string): KeyObject;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EIP-3009 receiveWithAuthorization message builder + signer (CLI side).
|
|
3
|
+
*
|
|
4
|
+
* Phase 2 MVP: build the typed data for USDC on Base Sepolia, sign with
|
|
5
|
+
* secp256k1, submit to server. Server verifies signature, nonce uniqueness,
|
|
6
|
+
* and time window.
|
|
7
|
+
*/
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
9
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
10
|
+
import { exportPaymentAddress, loadPaymentPrivateKey, signSecp256k1, } from './payment-keys.js';
|
|
11
|
+
const BASE_SEPOLIA_USDC = '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
|
|
12
|
+
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
13
|
+
const RECEIVE_WITH_AUTHORIZATION_TYPEHASH = keccak256(utf8('ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)'));
|
|
14
|
+
const DOMAIN_TYPEHASH = keccak256(utf8('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'));
|
|
15
|
+
export function buildAndSignAuthorization(params) {
|
|
16
|
+
const { privateKey, to, valueUsdcBaseUnits, validForSeconds = 3600 } = params;
|
|
17
|
+
const from = exportPaymentAddress(privateKey);
|
|
18
|
+
const now = Math.floor(Date.now() / 1000);
|
|
19
|
+
const value = BigInt(valueUsdcBaseUnits);
|
|
20
|
+
const validAfter = '0';
|
|
21
|
+
const validBefore = String(now + validForSeconds);
|
|
22
|
+
const nonceBytes = randomBytes(32);
|
|
23
|
+
const nonce = '0x' + Buffer.from(nonceBytes).toString('hex');
|
|
24
|
+
const domain = computeDomainSeparator(BASE_SEPOLIA_CHAIN_ID, BASE_SEPOLIA_USDC);
|
|
25
|
+
const structHash = computeStructHash({
|
|
26
|
+
from,
|
|
27
|
+
to,
|
|
28
|
+
value: value.toString(),
|
|
29
|
+
validAfter,
|
|
30
|
+
validBefore,
|
|
31
|
+
nonce,
|
|
32
|
+
});
|
|
33
|
+
const msgHash = keccak256(concatBytes([
|
|
34
|
+
new Uint8Array([0x19, 0x01]),
|
|
35
|
+
domain,
|
|
36
|
+
structHash,
|
|
37
|
+
]));
|
|
38
|
+
const sig = signSecp256k1(privateKey, Buffer.from(msgHash));
|
|
39
|
+
const r = '0x' + sig.subarray(0, 32).toString('hex');
|
|
40
|
+
const s = '0x' + sig.subarray(32, 64).toString('hex');
|
|
41
|
+
const v = sig[64];
|
|
42
|
+
return {
|
|
43
|
+
from,
|
|
44
|
+
to,
|
|
45
|
+
value: value.toString(),
|
|
46
|
+
validAfter,
|
|
47
|
+
validBefore,
|
|
48
|
+
nonce,
|
|
49
|
+
v,
|
|
50
|
+
r,
|
|
51
|
+
s,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function loadPaymentKey(pem) {
|
|
55
|
+
return loadPaymentPrivateKey(pem);
|
|
56
|
+
}
|
|
57
|
+
function utf8(s) {
|
|
58
|
+
return new TextEncoder().encode(s);
|
|
59
|
+
}
|
|
60
|
+
function keccak256(data) {
|
|
61
|
+
return keccak_256(data);
|
|
62
|
+
}
|
|
63
|
+
function pad32(hexNoPrefix) {
|
|
64
|
+
return hexToBytes(hexNoPrefix.padStart(64, '0'));
|
|
65
|
+
}
|
|
66
|
+
function hexToBytes(hex) {
|
|
67
|
+
const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
68
|
+
if (clean.length % 2 !== 0)
|
|
69
|
+
throw new Error(`odd hex length: ${hex}`);
|
|
70
|
+
const out = new Uint8Array(clean.length / 2);
|
|
71
|
+
for (let i = 0; i < out.length; i++) {
|
|
72
|
+
out[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
function bytesToHex(bytes) {
|
|
77
|
+
let s = '';
|
|
78
|
+
for (const b of bytes)
|
|
79
|
+
s += b.toString(16).padStart(2, '0');
|
|
80
|
+
return s;
|
|
81
|
+
}
|
|
82
|
+
function concatBytes(arrays) {
|
|
83
|
+
const total = arrays.reduce((s, a) => s + a.length, 0);
|
|
84
|
+
const out = new Uint8Array(total);
|
|
85
|
+
let offset = 0;
|
|
86
|
+
for (const a of arrays) {
|
|
87
|
+
out.set(a, offset);
|
|
88
|
+
offset += a.length;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
function addressToBytes32(addr) {
|
|
93
|
+
return pad32(addr.slice(2).toLowerCase());
|
|
94
|
+
}
|
|
95
|
+
function uint256Bytes(value) {
|
|
96
|
+
const v = BigInt(value);
|
|
97
|
+
if (v < 0n)
|
|
98
|
+
throw new Error('negative uint256');
|
|
99
|
+
return pad32(v.toString(16));
|
|
100
|
+
}
|
|
101
|
+
function computeDomainSeparator(chainId, verifyingContract) {
|
|
102
|
+
const nameHash = keccak256(utf8('USD Coin'));
|
|
103
|
+
const versionHash = keccak256(utf8('2'));
|
|
104
|
+
return keccak256(concatBytes([
|
|
105
|
+
pad32(bytesToHex(DOMAIN_TYPEHASH)),
|
|
106
|
+
nameHash,
|
|
107
|
+
versionHash,
|
|
108
|
+
pad32(BigInt(chainId).toString(16)),
|
|
109
|
+
pad32(verifyingContract.slice(2).toLowerCase()),
|
|
110
|
+
]));
|
|
111
|
+
}
|
|
112
|
+
function computeStructHash(p) {
|
|
113
|
+
return keccak256(concatBytes([
|
|
114
|
+
pad32(bytesToHex(RECEIVE_WITH_AUTHORIZATION_TYPEHASH)),
|
|
115
|
+
addressToBytes32(p.from),
|
|
116
|
+
addressToBytes32(p.to),
|
|
117
|
+
uint256Bytes(p.value),
|
|
118
|
+
uint256Bytes(p.validAfter),
|
|
119
|
+
uint256Bytes(p.validBefore),
|
|
120
|
+
hexToBytes(p.nonce.slice(2)),
|
|
121
|
+
]));
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../src/lib/payment.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,MAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC,MAAM,mCAAmC,GAAG,SAAS,CACnD,IAAI,CAAC,sHAAsH,CAAC,CAC7H,CAAC;AAEF,MAAM,eAAe,GAAG,SAAS,CAC/B,IAAI,CAAC,oFAAoF,CAAC,CAC3F,CAAC;AAqBF,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACxE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,kBAAkB,EA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,iBAAyB;IACxE,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,OAAO,SAAS,CAAC,WAAW,CAAC;QAC3B,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QAClC,QAAQ;QACR,WAAW;QACX,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACnC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;KAChD,CAAC,CAAC,CAAC;AACN,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAsG;IAC/H,OAAO,SAAS,CAAC,WAAW,CAAC;QAC3B,KAAK,CAAC,UAAU,CAAC,mCAAmC,CAAC,CAAC;QACtD,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC;QACxB,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;QACtB,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;QACrB,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;QAC1B,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;QAC3B,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC7B,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentsmarket/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for agentsmarket.world — agent identity, wallet, and skill invocations",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"agentsmarket": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "node --test --import tsx/esm tests/*.test.ts",
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"lint": "tsc --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
23
|
+
"@noble/curves": "^2.4.0",
|
|
24
|
+
"@noble/hashes": "^2.4.0",
|
|
25
|
+
"commander": "^12.1.0",
|
|
26
|
+
"zod": "^3.25"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"tsx": "^4.19.0",
|
|
31
|
+
"typescript": "^5.6.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
}
|
|
36
|
+
}
|