@aifinpay/agent 0.1.0-alpha.1

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 ADDED
@@ -0,0 +1,77 @@
1
+ # @aifinpay/agent (Node / TypeScript)
2
+
3
+ Non-custodial x402 payment client for autonomous AI agents on
4
+ [AiFinPay](https://aifinpay.company).
5
+
6
+ The Ed25519 keypair is generated locally with `tweetnacl` and never leaves
7
+ your process. The SDK only sends a one-time SHA-256 + Ed25519 signature in
8
+ the `x-signature` header to authenticate against AiFinPay-protected endpoints.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @aifinpay/agent
14
+ # or pnpm add @aifinpay/agent
15
+ # or yarn add @aifinpay/agent
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```ts
21
+ import { Agent } from "@aifinpay/agent";
22
+
23
+ // Generate a fresh keypair locally — never transmitted
24
+ const agent = Agent.new();
25
+ console.log("Fund this address:", agent.address);
26
+ console.log("Save this secret:", agent.secretB58); // store securely!
27
+
28
+ // Wait until the wallet has at least $0.01 worth on-chain
29
+ await agent.waitForFunding({ minUsdCents: 1 });
30
+
31
+ // Request an invoice for a Seat (USDC on Solana)
32
+ const invoice = await agent.reserveSeatInvoice({
33
+ amountUsd: 1.0,
34
+ asset: "USDC",
35
+ });
36
+ // Build + sign + submit the on-chain tx with @solana/web3.js or viem.
37
+ // `invoice.raw` has program_id, treasury_vault, mints, nonce, etc.
38
+
39
+ // Once the Seat is on-chain, gated endpoints just work:
40
+ const res = await agent.get("https://aifinpay.company/api/stats");
41
+ console.log(await res.json());
42
+ ```
43
+
44
+ ## Loading an existing keypair
45
+
46
+ ```ts
47
+ // from solana-keygen JSON file (Node only)
48
+ const agent = await Agent.fromKeypairFile("./agent-wallet.json");
49
+
50
+ // from base58 secret string (works in browser too)
51
+ const agent2 = Agent.fromSecretB58("3RvZm7Gw...");
52
+ ```
53
+
54
+ ## How x402 auth works under the hood
55
+
56
+ For every gated request the SDK:
57
+
58
+ 1. `GET /nonce` → receives a one-time UUID with 60s TTL.
59
+ 2. computes `SHA-256("AiFinPay-x402:{nonce}:{pubkey}")`.
60
+ 3. signs with Ed25519, base58-encodes the signature.
61
+ 4. retries the original request with headers:
62
+ - `x-agent-pubkey: <base58 pubkey>`
63
+ - `x-nonce: <uuid>`
64
+ - `x-signature: <base58 sig>`
65
+
66
+ The server verifies the signature, checks the agent has a live Seat PDA
67
+ on-chain, and serves the resource.
68
+
69
+ ## Privacy
70
+
71
+ - **The server never sees your private key.** Period.
72
+ - Nonces are consumed on use; replay-resistant.
73
+ - All transactions are public and on-chain — Solana + Polygon mainnet.
74
+
75
+ ## License
76
+
77
+ MIT.
@@ -0,0 +1,61 @@
1
+ export declare class AiFinPayError extends Error {
2
+ }
3
+ export declare class X402Error extends AiFinPayError {
4
+ }
5
+ export declare class FundingTimeoutError extends AiFinPayError {
6
+ }
7
+ export declare class SeatNotFoundError extends AiFinPayError {
8
+ }
9
+ export interface Invoice {
10
+ amountUsd: number;
11
+ treasuryVault: string;
12
+ programId: string;
13
+ nonce: string;
14
+ raw: Record<string, unknown>;
15
+ }
16
+ export interface AgentOptions {
17
+ baseUrl?: string;
18
+ timeoutMs?: number;
19
+ fetchImpl?: typeof fetch;
20
+ }
21
+ export declare class Agent {
22
+ readonly publicKey: Uint8Array;
23
+ readonly secretKey: Uint8Array;
24
+ readonly baseUrl: string;
25
+ readonly timeoutMs: number;
26
+ private readonly fetchImpl;
27
+ private constructor();
28
+ static new(opts?: AgentOptions): Agent;
29
+ /** Load from base58 secret (Solana style: 64 bytes = secret + public). */
30
+ static fromSecretB58(secretB58: string, opts?: AgentOptions): Agent;
31
+ /** Load from a Solana CLI ``solana-keygen`` JSON file path (Node only). */
32
+ static fromKeypairFile(path: string, opts?: AgentOptions): Promise<Agent>;
33
+ /** Solana base58 public key. */
34
+ get address(): string;
35
+ /** 64-byte base58 secret. Save this safely — server never sees it. */
36
+ get secretB58(): string;
37
+ manifesto(): Promise<Record<string, unknown>>;
38
+ wellKnown(): Promise<Record<string, unknown>>;
39
+ fetchNonce(): Promise<{
40
+ nonce: string;
41
+ expires_at: string;
42
+ }>;
43
+ /** Build a fresh x402 header set (nonce is one-time, 60s TTL). */
44
+ authHeaders(): Promise<Record<string, string>>;
45
+ hasSeat(): Promise<boolean>;
46
+ /** Poll the merged leaderboard until this address shows ≥ minUsdCents. */
47
+ waitForFunding({ minUsdCents, pollMs, timeoutMs, }?: {
48
+ minUsdCents?: number;
49
+ pollMs?: number;
50
+ timeoutMs?: number;
51
+ }): Promise<void>;
52
+ reserveSeatInvoice({ amountUsd, asset, }: {
53
+ amountUsd: number;
54
+ asset?: "SOL" | "USDC" | "USDT";
55
+ }): Promise<Invoice>;
56
+ request(method: string, url: string, init?: RequestInit): Promise<Response>;
57
+ get(url: string, init?: RequestInit): Promise<Response>;
58
+ post(url: string, init?: RequestInit): Promise<Response>;
59
+ private json;
60
+ }
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,qBAAa,aAAc,SAAQ,KAAK;CAAG;AAC3C,qBAAa,SAAU,SAAQ,aAAa;CAAG;AAC/C,qBAAa,mBAAoB,SAAQ,aAAa;CAAG;AACzD,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AAEvD,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,qBAAa,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kBAAkB,CAAC,EACvB,SAAS,EACT,KAAc,GACf,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;KACjC,GAAG,OAAO,CAAC,OAAO,CAAC;IAsBd,OAAO,CACX,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,QAAQ,CAAC;IAepB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI3D,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;YAM9C,IAAI;CA6BnB"}
package/dist/index.js ADDED
@@ -0,0 +1,203 @@
1
+ /**
2
+ * AiFinPay agent SDK — non-custodial x402 payment client.
3
+ *
4
+ * Quick start:
5
+ * import { Agent } from "@aifinpay/agent";
6
+ * const agent = Agent.new();
7
+ * console.log("Fund this address:", agent.address);
8
+ * await agent.waitForFunding({ minUsdCents: 1 });
9
+ * const invoice = await agent.reserveSeatInvoice({ amountUsd: 1.0, asset: "USDC" });
10
+ * const r = await agent.get("https://aifinpay.company/api/stats");
11
+ */
12
+ import nacl from "tweetnacl";
13
+ import bs58 from "bs58";
14
+ const DEFAULT_BASE_URL = "https://aifinpay.company";
15
+ const DEFAULT_TIMEOUT_MS = 30_000;
16
+ const SDK_UA = "aifinpay-agent-node/0.1.0";
17
+ export class AiFinPayError extends Error {
18
+ }
19
+ export class X402Error extends AiFinPayError {
20
+ }
21
+ export class FundingTimeoutError extends AiFinPayError {
22
+ }
23
+ export class SeatNotFoundError extends AiFinPayError {
24
+ }
25
+ export class Agent {
26
+ publicKey;
27
+ secretKey; // 64 bytes (secret + public)
28
+ baseUrl;
29
+ timeoutMs;
30
+ fetchImpl;
31
+ constructor(secretKey, publicKey, opts = {}) {
32
+ this.secretKey = secretKey;
33
+ this.publicKey = publicKey;
34
+ this.baseUrl = (opts.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
35
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
36
+ this.fetchImpl = opts.fetchImpl ?? globalThis.fetch;
37
+ if (!this.fetchImpl) {
38
+ throw new AiFinPayError("global fetch not available. Pass opts.fetchImpl or upgrade to Node 18+.");
39
+ }
40
+ }
41
+ // ── Constructors ───────────────────────────────────────────────────────
42
+ static new(opts = {}) {
43
+ const kp = nacl.sign.keyPair();
44
+ return new Agent(kp.secretKey, kp.publicKey, opts);
45
+ }
46
+ /** Load from base58 secret (Solana style: 64 bytes = secret + public). */
47
+ static fromSecretB58(secretB58, opts = {}) {
48
+ const raw = bs58.decode(secretB58);
49
+ let kp;
50
+ if (raw.length === 64) {
51
+ kp = nacl.sign.keyPair.fromSecretKey(raw);
52
+ }
53
+ else if (raw.length === 32) {
54
+ kp = nacl.sign.keyPair.fromSeed(raw);
55
+ }
56
+ else {
57
+ throw new AiFinPayError(`secret must decode to 32 or 64 bytes, got ${raw.length}`);
58
+ }
59
+ return new Agent(kp.secretKey, kp.publicKey, opts);
60
+ }
61
+ /** Load from a Solana CLI ``solana-keygen`` JSON file path (Node only). */
62
+ static async fromKeypairFile(path, opts = {}) {
63
+ const fs = await import("node:fs/promises");
64
+ const raw = await fs.readFile(path, "utf8");
65
+ const arr = JSON.parse(raw);
66
+ if (!Array.isArray(arr) || arr.length !== 64) {
67
+ throw new AiFinPayError(`${path}: expected 64-byte JSON array`);
68
+ }
69
+ const sk = Uint8Array.from(arr);
70
+ const kp = nacl.sign.keyPair.fromSecretKey(sk);
71
+ return new Agent(kp.secretKey, kp.publicKey, opts);
72
+ }
73
+ // ── Public properties ──────────────────────────────────────────────────
74
+ /** Solana base58 public key. */
75
+ get address() {
76
+ return bs58.encode(this.publicKey);
77
+ }
78
+ /** 64-byte base58 secret. Save this safely — server never sees it. */
79
+ get secretB58() {
80
+ return bs58.encode(this.secretKey);
81
+ }
82
+ // ── Discovery ──────────────────────────────────────────────────────────
83
+ async manifesto() {
84
+ return (await this.json("GET", "/manifesto.json"));
85
+ }
86
+ async wellKnown() {
87
+ return (await this.json("GET", "/.well-known/x402.json"));
88
+ }
89
+ // ── x402 auth ──────────────────────────────────────────────────────────
90
+ async fetchNonce() {
91
+ return this.json("GET", "/nonce");
92
+ }
93
+ /** Build a fresh x402 header set (nonce is one-time, 60s TTL). */
94
+ async authHeaders() {
95
+ const { nonce } = await this.fetchNonce();
96
+ const msg = new TextEncoder().encode(`AiFinPay-x402:${nonce}:${this.address}`);
97
+ const digest = await sha256(msg);
98
+ const sig = nacl.sign.detached(digest, this.secretKey);
99
+ return {
100
+ "x-agent-pubkey": this.address,
101
+ "x-nonce": nonce,
102
+ "x-signature": bs58.encode(sig),
103
+ };
104
+ }
105
+ // ── Seat / funding ────────────────────────────────────────────────────
106
+ async hasSeat() {
107
+ const r = (await this.json("GET", `/api/seat/${this.address}`));
108
+ return Boolean(r.has_seat);
109
+ }
110
+ /** Poll the merged leaderboard until this address shows ≥ minUsdCents. */
111
+ async waitForFunding({ minUsdCents = 100, pollMs = 5_000, timeoutMs = 600_000, } = {}) {
112
+ const deadline = Date.now() + timeoutMs;
113
+ while (Date.now() < deadline) {
114
+ const data = (await this.json("GET", "/api/leaderboard?merge=true"));
115
+ for (const entry of data.leaderboard || []) {
116
+ if (entry.pubkey === this.address) {
117
+ const cents = Math.round(parseFloat(entry.usd) * 100);
118
+ if (cents >= minUsdCents)
119
+ return;
120
+ }
121
+ }
122
+ await new Promise((res) => setTimeout(res, pollMs));
123
+ }
124
+ throw new FundingTimeoutError(`address ${this.address} never reached ${minUsdCents} cents on-chain`);
125
+ }
126
+ // ── Invoices ──────────────────────────────────────────────────────────
127
+ async reserveSeatInvoice({ amountUsd, asset = "USDC", }) {
128
+ const endpoint = asset === "SOL" ? "/api/invoice" : "/api/invoice-spl";
129
+ const payload = {
130
+ amount_usd: amountUsd,
131
+ agent_pubkey: this.address,
132
+ };
133
+ if (asset !== "SOL")
134
+ payload.asset = asset;
135
+ const data = (await this.json("POST", endpoint, payload));
136
+ return {
137
+ amountUsd,
138
+ treasuryVault: data.treasury_vault || "",
139
+ programId: data.program_id || "",
140
+ nonce: data.nonce || "",
141
+ raw: data,
142
+ };
143
+ }
144
+ // ── x402-aware HTTP request wrapper ───────────────────────────────────
145
+ async request(method, url, init = {}) {
146
+ const auth = await this.authHeaders();
147
+ const headers = new Headers(init.headers);
148
+ Object.entries(auth).forEach(([k, v]) => headers.set(k, v));
149
+ headers.set("user-agent", SDK_UA);
150
+ const res = await this.fetchImpl(url, { ...init, method, headers });
151
+ if (res.status === 402) {
152
+ const body = await res.clone().text();
153
+ throw new X402Error(`402 Payment Required. Reserve a Seat first via reserveSeatInvoice(). Body: ${body}`);
154
+ }
155
+ return res;
156
+ }
157
+ get(url, init = {}) {
158
+ return this.request("GET", url, init);
159
+ }
160
+ post(url, init = {}) {
161
+ return this.request("POST", url, init);
162
+ }
163
+ // ── Internal helpers ──────────────────────────────────────────────────
164
+ async json(method, path, body) {
165
+ const init = {
166
+ method,
167
+ headers: {
168
+ accept: "application/json",
169
+ "user-agent": SDK_UA,
170
+ ...(body ? { "content-type": "application/json" } : {}),
171
+ },
172
+ };
173
+ if (body)
174
+ init.body = JSON.stringify(body);
175
+ const ctrl = new AbortController();
176
+ const t = setTimeout(() => ctrl.abort(), this.timeoutMs);
177
+ try {
178
+ const r = await this.fetchImpl(this.baseUrl + path, {
179
+ ...init,
180
+ signal: ctrl.signal,
181
+ });
182
+ if (!r.ok) {
183
+ throw new AiFinPayError(`${method} ${path} → ${r.status}`);
184
+ }
185
+ return await r.json();
186
+ }
187
+ finally {
188
+ clearTimeout(t);
189
+ }
190
+ }
191
+ }
192
+ async function sha256(bytes) {
193
+ if (typeof crypto !== "undefined" && crypto.subtle) {
194
+ // Force ArrayBuffer (not SharedArrayBuffer) for strict TS lib check
195
+ const data = new Uint8Array(bytes);
196
+ const buf = await crypto.subtle.digest("SHA-256", data.buffer);
197
+ return new Uint8Array(buf);
198
+ }
199
+ // Node fallback (unlikely on Node ≥18 since global crypto is available)
200
+ const { createHash } = await import("node:crypto");
201
+ return new Uint8Array(createHash("sha256").update(bytes).digest());
202
+ }
203
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AACpD,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAE3C,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAC3C,MAAM,OAAO,SAAU,SAAQ,aAAa;CAAG;AAC/C,MAAM,OAAO,mBAAoB,SAAQ,aAAa;CAAG;AACzD,MAAM,OAAO,iBAAkB,SAAQ,aAAa;CAAG;AAgBvD,MAAM,OAAO,KAAK;IACP,SAAS,CAAa;IACtB,SAAS,CAAa,CAAC,6BAA6B;IACpD,OAAO,CAAS;IAChB,SAAS,CAAS;IACV,SAAS,CAAe;IAEzC,YACE,SAAqB,EACrB,SAAqB,EACrB,OAAqB,EAAE;QAEvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,kBAAkB,CAAC;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;QACpD,IAAI,C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,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@aifinpay/agent",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Non-custodial x402 payment client for autonomous AI agents on AiFinPay (Solana + Polygon)",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md", "LICENSE"],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "keywords": [
20
+ "x402",
21
+ "ai-agent",
22
+ "solana",
23
+ "polygon",
24
+ "payments",
25
+ "non-custodial",
26
+ "ed25519"
27
+ ],
28
+ "author": "CoinSecurities (SECCO) <contact@aifinpay.company>",
29
+ "license": "MIT",
30
+ "homepage": "https://aifinpay.company",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/enot3615/oracle-financial-hub-59.git",
34
+ "directory": "sdk/node"
35
+ },
36
+ "bugs": "https://github.com/enot3615/oracle-financial-hub-59/issues",
37
+ "dependencies": {
38
+ "bs58": "^6.0.0",
39
+ "tweetnacl": "^1.0.3"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^20.0.0",
43
+ "typescript": "^5.4.0"
44
+ },
45
+ "engines": {
46
+ "node": ">=18"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }