@auteng/agent-utils 0.2.0 → 0.2.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 +54 -23
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @auteng/agent-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Give your AI agent its own crypto wallets. Create purpose-specific wallets funded with USDC on Base, then let the agent spend autonomously on x402-enabled services like sandboxed compute. No accounts, no KYC — just wallet addresses and USDC.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,36 +8,54 @@ Utility belt for autonomous AI agents — multi-wallet, compute, and x402 paymen
|
|
|
8
8
|
npm install @auteng/agent-utils
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { wallet, compute } from '@auteng/agent-utils';
|
|
15
|
+
|
|
16
|
+
// 1. Create a wallet for this task
|
|
17
|
+
const w = await wallet.create({ name: "my-task" });
|
|
18
|
+
console.log(`Fund me: send USDC on Base to ${w.address}`);
|
|
19
|
+
|
|
20
|
+
// 2. Wait for funding
|
|
21
|
+
await w.waitForFunding(5_000000n); // wait for $5 USDC
|
|
22
|
+
|
|
23
|
+
// 3. Run sandboxed code (payment handled automatically)
|
|
24
|
+
const result = await compute.run({
|
|
25
|
+
code: 'print("hello from the sandbox")',
|
|
26
|
+
stack: 'python',
|
|
27
|
+
wallet: w,
|
|
28
|
+
});
|
|
29
|
+
console.log(result.stdout);
|
|
30
|
+
```
|
|
31
|
+
|
|
11
32
|
## Wallets
|
|
12
33
|
|
|
13
|
-
|
|
34
|
+
Each wallet is an independent keypair with its own address and balance. Create as many as you need — one per task, one per month, one per budget.
|
|
14
35
|
|
|
15
36
|
```typescript
|
|
16
37
|
import { wallet } from '@auteng/agent-utils';
|
|
17
38
|
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
console.log(monthly.address); // 0xABC...
|
|
23
|
-
console.log(task.address); // 0xDEF...
|
|
39
|
+
const monthly = await wallet.create({ name: "feb-2026" });
|
|
40
|
+
const task = await wallet.create({ name: "data-pipeline" });
|
|
41
|
+
const dev = await wallet.create({ name: "testnet", network: "base-sepolia" });
|
|
24
42
|
```
|
|
25
43
|
|
|
26
|
-
Wallets are
|
|
44
|
+
Wallets are persisted at `.auteng/wallets/<name>.json`. Creating a wallet that already exists loads it from disk.
|
|
27
45
|
|
|
28
46
|
### Check balance
|
|
29
47
|
|
|
30
48
|
```typescript
|
|
31
49
|
const balance = await monthly.checkBalance();
|
|
32
|
-
// Returns USDC
|
|
33
|
-
//
|
|
50
|
+
// Returns USDC in minor units (6 decimals)
|
|
51
|
+
// 10_000000n = $10.00 USDC
|
|
34
52
|
```
|
|
35
53
|
|
|
36
54
|
### Wait for funding
|
|
37
55
|
|
|
38
56
|
```typescript
|
|
39
57
|
await monthly.waitForFunding(10_000000n);
|
|
40
|
-
// Polls every 10s until >= 10 USDC is available
|
|
58
|
+
// Polls Base every 10s until >= $10 USDC is available
|
|
41
59
|
```
|
|
42
60
|
|
|
43
61
|
### x402 fetch
|
|
@@ -52,18 +70,23 @@ const res = await monthly.fetch('https://x402.auteng.ai/api/x402/compute', {
|
|
|
52
70
|
});
|
|
53
71
|
```
|
|
54
72
|
|
|
55
|
-
If the server returns `402 Payment Required`, the library signs an EIP-3009 authorization and retries with payment headers.
|
|
73
|
+
If the server returns `402 Payment Required`, the library signs an EIP-3009 authorization and retries with payment headers. No gas needed.
|
|
56
74
|
|
|
57
75
|
### Retrieve and list wallets
|
|
58
76
|
|
|
59
77
|
```typescript
|
|
60
|
-
const w = wallet.get("
|
|
61
|
-
const all = wallet.list();
|
|
78
|
+
const w = wallet.get("feb-2026"); // load by name
|
|
79
|
+
const all = wallet.list(); // list all wallets
|
|
80
|
+
|
|
81
|
+
for (const w of all) {
|
|
82
|
+
const bal = await w.checkBalance();
|
|
83
|
+
console.log(`${w.name}: ${w.address} — ${bal} USDC`);
|
|
84
|
+
}
|
|
62
85
|
```
|
|
63
86
|
|
|
64
87
|
## Compute
|
|
65
88
|
|
|
66
|
-
Run sandboxed code via AutEng's x402 compute endpoint:
|
|
89
|
+
Run sandboxed code via AutEng's x402 compute endpoint. Pass a wallet to pay for execution:
|
|
67
90
|
|
|
68
91
|
```typescript
|
|
69
92
|
import { wallet, compute } from '@auteng/agent-utils';
|
|
@@ -81,16 +104,24 @@ console.log(result.stdout); // "hello world\n"
|
|
|
81
104
|
|
|
82
105
|
### Pricing
|
|
83
106
|
|
|
107
|
+
| Size | vCPU | RAM | Base price | Per second |
|
|
108
|
+
|-------|------|-------|-----------|------------|
|
|
109
|
+
| small | 2 | 1 GB | $0.002 | $0.00005 |
|
|
110
|
+
| med | 4 | 4 GB | $0.008 | $0.00012 |
|
|
111
|
+
| large | 8 | 16 GB | $0.03 | $0.00025 |
|
|
112
|
+
|
|
84
113
|
```typescript
|
|
85
|
-
compute.pricing();
|
|
86
|
-
// { small: { base_price_usd: 0.002, ... }, med: { ... }, large: { ... } }
|
|
114
|
+
compute.pricing(); // returns full pricing table
|
|
87
115
|
```
|
|
88
116
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm install # install dependencies
|
|
121
|
+
npm run build # build CJS/ESM/DTS to dist/
|
|
122
|
+
npm test # run unit + integration tests
|
|
123
|
+
npm run test:watch # run tests in watch mode
|
|
124
|
+
```
|
|
94
125
|
|
|
95
126
|
## License
|
|
96
127
|
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -191,6 +191,7 @@ var Wallet = class {
|
|
|
191
191
|
// src/wallet/index.ts
|
|
192
192
|
var DEFAULT_WALLETS_DIR = ".auteng/wallets";
|
|
193
193
|
var _wallets = /* @__PURE__ */ new Map();
|
|
194
|
+
var _walletsDir = (0, import_node_path2.resolve)(DEFAULT_WALLETS_DIR);
|
|
194
195
|
var wallet = {
|
|
195
196
|
/**
|
|
196
197
|
* Create a new named wallet or load an existing one from disk.
|
|
@@ -201,6 +202,7 @@ var wallet = {
|
|
|
201
202
|
validateWalletName(name);
|
|
202
203
|
if (_wallets.has(name)) return _wallets.get(name);
|
|
203
204
|
const dir = (0, import_node_path2.resolve)(opts?.walletsDir ?? DEFAULT_WALLETS_DIR);
|
|
205
|
+
_walletsDir = dir;
|
|
204
206
|
const filePath = (0, import_node_path2.join)(dir, `${name}.json`);
|
|
205
207
|
const network = opts?.network ?? "base";
|
|
206
208
|
const rpcUrl = opts?.rpcUrl;
|
|
@@ -243,7 +245,7 @@ var wallet = {
|
|
|
243
245
|
get(name) {
|
|
244
246
|
validateWalletName(name);
|
|
245
247
|
if (_wallets.has(name)) return _wallets.get(name);
|
|
246
|
-
const filePath = (0, import_node_path2.join)(
|
|
248
|
+
const filePath = (0, import_node_path2.join)(_walletsDir, `${name}.json`);
|
|
247
249
|
const data = readWalletFile(filePath);
|
|
248
250
|
if (!data) throw new Error(`Wallet "${name}" not found`);
|
|
249
251
|
const { account } = loadKeypair(data.privateKey);
|
|
@@ -260,12 +262,16 @@ var wallet = {
|
|
|
260
262
|
},
|
|
261
263
|
/** List all persisted wallets. */
|
|
262
264
|
list() {
|
|
263
|
-
const
|
|
264
|
-
const names = listWalletFiles(dir);
|
|
265
|
+
const names = listWalletFiles(_walletsDir);
|
|
265
266
|
return names.map((n) => {
|
|
266
267
|
if (_wallets.has(n)) return _wallets.get(n);
|
|
267
268
|
return wallet.get(n);
|
|
268
269
|
});
|
|
270
|
+
},
|
|
271
|
+
/** @internal Clear in-memory cache and reset wallets dir. For testing only. */
|
|
272
|
+
_reset() {
|
|
273
|
+
_wallets.clear();
|
|
274
|
+
_walletsDir = (0, import_node_path2.resolve)(DEFAULT_WALLETS_DIR);
|
|
269
275
|
}
|
|
270
276
|
};
|
|
271
277
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/x402/index.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/wallet/wallet.ts","../src/compute/index.ts"],"sourcesContent":["export { wallet } from \"./wallet/index.js\"\nexport { Wallet } from \"./wallet/wallet.js\"\nexport { compute } from \"./compute/index.js\"\n\nexport type { CreateWalletOptions, WalletConfig, WaitForFundingOptions, Network } from \"./wallet/types.js\"\nexport type { ComputeRequest, ComputeResponse, PricingTier, Stack, Size } from \"./compute/types.js\"\n","import { join, resolve } from \"node:path\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile, listWalletFiles, migrateLegacyWallet, validateWalletName } from \"./storage.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport { Wallet } from \"./wallet.js\"\nimport type { CreateWalletOptions } from \"./types.js\"\n\nconst DEFAULT_WALLETS_DIR = \".auteng/wallets\"\n\nconst _wallets = new Map<string, Wallet>()\n\nexport const wallet = {\n /**\n * Create a new named wallet or load an existing one from disk.\n * Idempotent: if a wallet with this name already exists, returns it.\n */\n async create(opts?: CreateWalletOptions): Promise<Wallet> {\n const name = opts?.name ?? \"default\"\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const dir = resolve(opts?.walletsDir ?? DEFAULT_WALLETS_DIR)\n const filePath = join(dir, `${name}.json`)\n const network = opts?.network ?? \"base\"\n const rpcUrl = opts?.rpcUrl\n\n let existing = readWalletFile(filePath)\n\n if (!existing && name === \"default\") {\n existing = migrateLegacyWallet(dir)\n }\n\n let privateKey: `0x${string}`\n let account: ReturnType<typeof loadKeypair>[\"account\"]\n\n if (existing) {\n privateKey = existing.privateKey\n account = loadKeypair(existing.privateKey).account\n } else {\n const kp = createKeypair()\n privateKey = kp.privateKey\n account = kp.account\n writeWalletFile(filePath, {\n privateKey,\n address: account.address,\n network,\n })\n }\n\n const effectiveNetwork = existing?.network ?? network\n const paymentFetch = createPaymentFetch(privateKey, effectiveNetwork, rpcUrl)\n const w = new Wallet({\n name,\n account,\n privateKey,\n network: effectiveNetwork,\n rpcUrl,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /**\n * Retrieve a previously-created wallet by name.\n * Loads from disk if not in memory. Throws if not found.\n */\n get(name: string): Wallet {\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const filePath = join(resolve(DEFAULT_WALLETS_DIR), `${name}.json`)\n const data = readWalletFile(filePath)\n if (!data) throw new Error(`Wallet \"${name}\" not found`)\n\n const { account } = loadKeypair(data.privateKey)\n const paymentFetch = createPaymentFetch(data.privateKey, data.network)\n const w = new Wallet({\n name,\n account,\n privateKey: data.privateKey,\n network: data.network,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /** List all persisted wallets. */\n list(): Wallet[] {\n const dir = resolve(DEFAULT_WALLETS_DIR)\n const names = listWalletFiles(dir)\n return names.map((n) => {\n if (_wallets.has(n)) return _wallets.get(n)!\n return wallet.get(n)\n })\n },\n}\n","import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\"\nimport type { PrivateKeyAccount } from \"viem\"\n\nexport function createKeypair(): {\n privateKey: `0x${string}`\n account: PrivateKeyAccount\n} {\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n return { privateKey, account }\n}\n\nexport function loadKeypair(privateKey: `0x${string}`): {\n account: PrivateKeyAccount\n} {\n const account = privateKeyToAccount(privateKey)\n return { account }\n}\n","import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, copyFileSync } from \"node:fs\"\nimport { dirname, join, resolve } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\n\nconst VALID_NAME = /^[a-z0-9_-]+$/\n\nexport function validateWalletName(name: string): void {\n if (!VALID_NAME.test(name)) {\n throw new Error(\n `Invalid wallet name \"${name}\". Use lowercase letters, numbers, hyphens, and underscores only.`\n )\n }\n}\n\nexport function readWalletFile(path: string): WalletFile | null {\n if (!existsSync(path)) return null\n const raw = readFileSync(path, \"utf-8\")\n return JSON.parse(raw) as WalletFile\n}\n\nexport function writeWalletFile(path: string, data: WalletFile): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(data, null, 2) + \"\\n\", {\n mode: 0o600,\n })\n}\n\nexport function listWalletFiles(dir: string): string[] {\n const resolved = resolve(dir)\n if (!existsSync(resolved)) return []\n return readdirSync(resolved)\n .filter((f) => f.endsWith(\".json\"))\n .map((f) => f.replace(/\\.json$/, \"\"))\n}\n\nexport function migrateLegacyWallet(walletsDir: string): WalletFile | null {\n const legacyPath = resolve(walletsDir, \"..\", \"wallet.json\")\n const newPath = join(resolve(walletsDir), \"default.json\")\n if (existsSync(legacyPath) && !existsSync(newPath)) {\n const data = readWalletFile(legacyPath)\n if (data) {\n mkdirSync(resolve(walletsDir), { recursive: true })\n copyFileSync(legacyPath, newPath)\n return data\n }\n }\n return null\n}\n","import { x402Client } from \"@x402/core/client\"\nimport { registerExactEvmScheme } from \"@x402/evm/exact/client\"\nimport { toClientEvmSigner } from \"@x402/evm\"\nimport { wrapFetchWithPayment } from \"@x402/fetch\"\nimport { privateKeyToAccount } from \"viem/accounts\"\nimport { createPublicClient, http } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\nimport type { Network } from \"../wallet/types.js\"\n\n/**\n * Create a fetch function that automatically handles x402 payments.\n * When the server returns 402, the SDK signs an EIP-3009 authorization\n * using the provided private key and retries with payment headers.\n */\nexport function createPaymentFetch(\n privateKey: `0x${string}`,\n network: Network = \"base\",\n rpcUrl?: string\n): typeof globalThis.fetch {\n const account = privateKeyToAccount(privateKey)\n const chain = network === \"base\" ? base : baseSepolia\n const publicClient = createPublicClient({\n chain,\n transport: http(rpcUrl),\n })\n const signer = toClientEvmSigner(account, publicClient)\n\n const client = new x402Client()\n registerExactEvmScheme(client, { signer })\n return wrapFetchWithPayment(fetch, client)\n}\n","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface CreateWalletOptions {\n /** Wallet identifier. Default: \"default\" */\n name?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n /** Base directory for wallet storage. Default: \".auteng/wallets\" */\n walletsDir?: string\n}\n\n/** @deprecated Use CreateWalletOptions instead */\nexport type WalletConfig = CreateWalletOptions\n\nexport interface WalletFile {\n privateKey: `0x${string}`\n address: `0x${string}`\n network: Network\n}\n\nexport interface WaitForFundingOptions {\n /** Poll interval in milliseconds. Default: 10000 (10s) */\n pollInterval?: number\n /** Timeout in milliseconds. Default: none (waits forever) */\n timeout?: number\n}\n\nexport const NETWORK_CONFIG: Record<Network, { chainId: number; usdcAddress: `0x${string}`; rpcUrl: string }> = {\n base: {\n chainId: 8453,\n usdcAddress: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n rpcUrl: \"https://mainnet.base.org\",\n },\n \"base-sepolia\": {\n chainId: 84532,\n usdcAddress: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n rpcUrl: \"https://sepolia.base.org\",\n },\n}\n","import type { Network } from \"./types.js\"\nimport { NETWORK_CONFIG } from \"./types.js\"\n\n/**\n * Read USDC balance for `address` via a direct `eth_call` to the USDC\n * contract's `balanceOf(address)` function. No viem client needed — just\n * a plain JSON-RPC POST.\n */\nexport async function getUsdcBalance(address: `0x${string}`, network: Network, rpcUrl?: string): Promise<bigint> {\n const config = NETWORK_CONFIG[network]\n const url = rpcUrl ?? config.rpcUrl\n\n // balanceOf(address) selector = 0x70a08231\n const paddedAddress = address.slice(2).toLowerCase().padStart(64, \"0\")\n const data = `0x70a08231${paddedAddress}`\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: config.usdcAddress, data }, \"latest\"],\n }),\n })\n\n const json = (await res.json()) as { result?: string; error?: unknown }\n if (json.error) {\n throw new Error(`RPC error: ${JSON.stringify(json.error)}`)\n }\n return BigInt(json.result ?? \"0x0\")\n}\n","import type { PrivateKeyAccount } from \"viem\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport type { Network, WaitForFundingOptions } from \"./types.js\"\n\nexport class Wallet {\n readonly name: string\n readonly address: `0x${string}`\n readonly network: Network\n\n private _account: PrivateKeyAccount\n private _privateKey: `0x${string}`\n private _rpcUrl: string | undefined\n private _paymentFetch: typeof globalThis.fetch\n\n constructor(params: {\n name: string\n account: PrivateKeyAccount\n privateKey: `0x${string}`\n network: Network\n rpcUrl?: string\n paymentFetch: typeof globalThis.fetch\n }) {\n this.name = params.name\n this._account = params.account\n this._privateKey = params.privateKey\n this.address = params.account.address\n this.network = params.network\n this._rpcUrl = params.rpcUrl\n this._paymentFetch = params.paymentFetch\n }\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n return getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n }\n\n /**\n * Poll until USDC balance >= minAmount.\n * @param minAmount - minimum USDC balance in minor units (6 decimals)\n */\n async waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void> {\n const interval = opts?.pollInterval ?? 10_000\n const deadline = opts?.timeout ? Date.now() + opts.timeout : null\n\n while (true) {\n const balance = await getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n if (balance >= minAmount) return\n\n if (deadline && Date.now() >= deadline) {\n throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`)\n }\n\n await new Promise((r) => setTimeout(r, interval))\n }\n }\n\n /**\n * Drop-in `fetch()` replacement that handles x402 payments automatically.\n * If the server returns 402, the library signs an EIP-3009 authorization\n * and retries the request with payment headers.\n */\n async fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {\n return this._paymentFetch(input, init)\n }\n}\n","import type { ComputeRequest, ComputeResponse, PricingTier, Size } from \"./types.js\"\n\nconst DEFAULT_ENDPOINT = \"https://x402.auteng.ai/api/x402/compute\"\n\nlet _endpoint = DEFAULT_ENDPOINT\n\nconst PRICING: Record<Size, PricingTier> = {\n small: {\n vcpu: 2,\n ram_gb: 1,\n default_timeout_s: 30,\n max_timeout_s: 300,\n base_price_usd: 0.002,\n per_second_usd: 0.00005,\n },\n med: {\n vcpu: 4,\n ram_gb: 4,\n default_timeout_s: 60,\n max_timeout_s: 600,\n base_price_usd: 0.008,\n per_second_usd: 0.00012,\n },\n large: {\n vcpu: 8,\n ram_gb: 16,\n default_timeout_s: 120,\n max_timeout_s: 3600,\n base_price_usd: 0.03,\n per_second_usd: 0.00025,\n },\n}\n\nexport const compute = {\n /**\n * Execute sandboxed code via AutEng's x402 compute endpoint.\n * Payment is handled automatically via the wallet's x402 layer.\n */\n async run(request: ComputeRequest): Promise<ComputeResponse> {\n if (!request.code) {\n throw new Error(\"compute.run: 'code' is required\")\n }\n if (!request.stack) {\n throw new Error(\"compute.run: 'stack' is required\")\n }\n\n const body = {\n code: request.code,\n stack: request.stack,\n size: request.size ?? \"small\",\n ...(request.timeout_seconds != null && {\n timeout_seconds: request.timeout_seconds,\n }),\n ...(request.files != null && { files: request.files }),\n }\n\n if (!request.wallet) {\n throw new Error(\"compute.run: 'wallet' is required\")\n }\n\n const response = await request.wallet.fetch(_endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\")\n throw new Error(`Compute request failed (${response.status}): ${text}`)\n }\n\n return (await response.json()) as ComputeResponse\n },\n\n /** Returns the pricing table for all compute sizes. */\n pricing(): Record<Size, PricingTier> {\n return { ...PRICING }\n },\n\n /**\n * Override the compute endpoint URL.\n * Default: https://x402.auteng.ai/api/x402/compute\n */\n setEndpoint(url: string): void {\n _endpoint = url\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAA8B;;;ACA9B,sBAAwD;AAGjD,SAAS,gBAGd;AACA,QAAM,iBAAa,oCAAmB;AACtC,QAAM,cAAU,qCAAoB,UAAU;AAC9C,SAAO,EAAE,YAAY,QAAQ;AAC/B;AAEO,SAAS,YAAY,YAE1B;AACA,QAAM,cAAU,qCAAoB,UAAU;AAC9C,SAAO,EAAE,QAAQ;AACnB;;;ACjBA,qBAA8F;AAC9F,uBAAuC;AAGvC,IAAM,aAAa;AAEZ,SAAS,mBAAmB,MAAoB;AACrD,MAAI,CAAC,WAAW,KAAK,IAAI,GAAG;AAC1B,UAAM,IAAI;AAAA,MACR,wBAAwB,IAAI;AAAA,IAC9B;AAAA,EACF;AACF;AAEO,SAAS,eAAe,MAAiC;AAC9D,MAAI,KAAC,2BAAW,IAAI,EAAG,QAAO;AAC9B,QAAM,UAAM,6BAAa,MAAM,OAAO;AACtC,SAAO,KAAK,MAAM,GAAG;AACvB;AAEO,SAAS,gBAAgB,MAAc,MAAwB;AACpE,oCAAU,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC5C,oCAAc,MAAM,KAAK,UAAU,MAAM,MAAM,CAAC,IAAI,MAAM;AAAA,IACxD,MAAM;AAAA,EACR,CAAC;AACH;AAEO,SAAS,gBAAgB,KAAuB;AACrD,QAAM,eAAW,0BAAQ,GAAG;AAC5B,MAAI,KAAC,2BAAW,QAAQ,EAAG,QAAO,CAAC;AACnC,aAAO,4BAAY,QAAQ,EACxB,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO,CAAC,EACjC,IAAI,CAAC,MAAM,EAAE,QAAQ,WAAW,EAAE,CAAC;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":["import_node_path","import_client","import_accounts"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/x402/index.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/wallet/wallet.ts","../src/compute/index.ts"],"sourcesContent":["export { wallet } from \"./wallet/index.js\"\nexport { Wallet } from \"./wallet/wallet.js\"\nexport { compute } from \"./compute/index.js\"\n\nexport type { CreateWalletOptions, WalletConfig, WaitForFundingOptions, Network } from \"./wallet/types.js\"\nexport type { ComputeRequest, ComputeResponse, PricingTier, Stack, Size } from \"./compute/types.js\"\n","import { join, resolve } from \"node:path\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile, listWalletFiles, migrateLegacyWallet, validateWalletName } from \"./storage.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport { Wallet } from \"./wallet.js\"\nimport type { CreateWalletOptions } from \"./types.js\"\n\nconst DEFAULT_WALLETS_DIR = \".auteng/wallets\"\n\nconst _wallets = new Map<string, Wallet>()\nlet _walletsDir = resolve(DEFAULT_WALLETS_DIR)\n\nexport const wallet = {\n /**\n * Create a new named wallet or load an existing one from disk.\n * Idempotent: if a wallet with this name already exists, returns it.\n */\n async create(opts?: CreateWalletOptions): Promise<Wallet> {\n const name = opts?.name ?? \"default\"\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const dir = resolve(opts?.walletsDir ?? DEFAULT_WALLETS_DIR)\n _walletsDir = dir\n const filePath = join(dir, `${name}.json`)\n const network = opts?.network ?? \"base\"\n const rpcUrl = opts?.rpcUrl\n\n let existing = readWalletFile(filePath)\n\n if (!existing && name === \"default\") {\n existing = migrateLegacyWallet(dir)\n }\n\n let privateKey: `0x${string}`\n let account: ReturnType<typeof loadKeypair>[\"account\"]\n\n if (existing) {\n privateKey = existing.privateKey\n account = loadKeypair(existing.privateKey).account\n } else {\n const kp = createKeypair()\n privateKey = kp.privateKey\n account = kp.account\n writeWalletFile(filePath, {\n privateKey,\n address: account.address,\n network,\n })\n }\n\n const effectiveNetwork = existing?.network ?? network\n const paymentFetch = createPaymentFetch(privateKey, effectiveNetwork, rpcUrl)\n const w = new Wallet({\n name,\n account,\n privateKey,\n network: effectiveNetwork,\n rpcUrl,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /**\n * Retrieve a previously-created wallet by name.\n * Loads from disk if not in memory. Throws if not found.\n */\n get(name: string): Wallet {\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const filePath = join(_walletsDir, `${name}.json`)\n const data = readWalletFile(filePath)\n if (!data) throw new Error(`Wallet \"${name}\" not found`)\n\n const { account } = loadKeypair(data.privateKey)\n const paymentFetch = createPaymentFetch(data.privateKey, data.network)\n const w = new Wallet({\n name,\n account,\n privateKey: data.privateKey,\n network: data.network,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /** List all persisted wallets. */\n list(): Wallet[] {\n const names = listWalletFiles(_walletsDir)\n return names.map((n) => {\n if (_wallets.has(n)) return _wallets.get(n)!\n return wallet.get(n)\n })\n },\n\n /** @internal Clear in-memory cache and reset wallets dir. For testing only. */\n _reset(): void {\n _wallets.clear()\n _walletsDir = resolve(DEFAULT_WALLETS_DIR)\n },\n}\n","import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\"\nimport type { PrivateKeyAccount } from \"viem\"\n\nexport function createKeypair(): {\n privateKey: `0x${string}`\n account: PrivateKeyAccount\n} {\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n return { privateKey, account }\n}\n\nexport function loadKeypair(privateKey: `0x${string}`): {\n account: PrivateKeyAccount\n} {\n const account = privateKeyToAccount(privateKey)\n return { account }\n}\n","import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, copyFileSync } from \"node:fs\"\nimport { dirname, join, resolve } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\n\nconst VALID_NAME = /^[a-z0-9_-]+$/\n\nexport function validateWalletName(name: string): void {\n if (!VALID_NAME.test(name)) {\n throw new Error(\n `Invalid wallet name \"${name}\". Use lowercase letters, numbers, hyphens, and underscores only.`\n )\n }\n}\n\nexport function readWalletFile(path: string): WalletFile | null {\n if (!existsSync(path)) return null\n const raw = readFileSync(path, \"utf-8\")\n return JSON.parse(raw) as WalletFile\n}\n\nexport function writeWalletFile(path: string, data: WalletFile): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(data, null, 2) + \"\\n\", {\n mode: 0o600,\n })\n}\n\nexport function listWalletFiles(dir: string): string[] {\n const resolved = resolve(dir)\n if (!existsSync(resolved)) return []\n return readdirSync(resolved)\n .filter((f) => f.endsWith(\".json\"))\n .map((f) => f.replace(/\\.json$/, \"\"))\n}\n\nexport function migrateLegacyWallet(walletsDir: string): WalletFile | null {\n const legacyPath = resolve(walletsDir, \"..\", \"wallet.json\")\n const newPath = join(resolve(walletsDir), \"default.json\")\n if (existsSync(legacyPath) && !existsSync(newPath)) {\n const data = readWalletFile(legacyPath)\n if (data) {\n mkdirSync(resolve(walletsDir), { recursive: true })\n copyFileSync(legacyPath, newPath)\n return data\n }\n }\n return null\n}\n","import { x402Client } from \"@x402/core/client\"\nimport { registerExactEvmScheme } from \"@x402/evm/exact/client\"\nimport { toClientEvmSigner } from \"@x402/evm\"\nimport { wrapFetchWithPayment } from \"@x402/fetch\"\nimport { privateKeyToAccount } from \"viem/accounts\"\nimport { createPublicClient, http } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\nimport type { Network } from \"../wallet/types.js\"\n\n/**\n * Create a fetch function that automatically handles x402 payments.\n * When the server returns 402, the SDK signs an EIP-3009 authorization\n * using the provided private key and retries with payment headers.\n */\nexport function createPaymentFetch(\n privateKey: `0x${string}`,\n network: Network = \"base\",\n rpcUrl?: string\n): typeof globalThis.fetch {\n const account = privateKeyToAccount(privateKey)\n const chain = network === \"base\" ? base : baseSepolia\n const publicClient = createPublicClient({\n chain,\n transport: http(rpcUrl),\n })\n const signer = toClientEvmSigner(account, publicClient)\n\n const client = new x402Client()\n registerExactEvmScheme(client, { signer })\n return wrapFetchWithPayment(fetch, client)\n}\n","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface CreateWalletOptions {\n /** Wallet identifier. Default: \"default\" */\n name?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n /** Base directory for wallet storage. Default: \".auteng/wallets\" */\n walletsDir?: string\n}\n\n/** @deprecated Use CreateWalletOptions instead */\nexport type WalletConfig = CreateWalletOptions\n\nexport interface WalletFile {\n privateKey: `0x${string}`\n address: `0x${string}`\n network: Network\n}\n\nexport interface WaitForFundingOptions {\n /** Poll interval in milliseconds. Default: 10000 (10s) */\n pollInterval?: number\n /** Timeout in milliseconds. Default: none (waits forever) */\n timeout?: number\n}\n\nexport const NETWORK_CONFIG: Record<Network, { chainId: number; usdcAddress: `0x${string}`; rpcUrl: string }> = {\n base: {\n chainId: 8453,\n usdcAddress: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n rpcUrl: \"https://mainnet.base.org\",\n },\n \"base-sepolia\": {\n chainId: 84532,\n usdcAddress: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n rpcUrl: \"https://sepolia.base.org\",\n },\n}\n","import type { Network } from \"./types.js\"\nimport { NETWORK_CONFIG } from \"./types.js\"\n\n/**\n * Read USDC balance for `address` via a direct `eth_call` to the USDC\n * contract's `balanceOf(address)` function. No viem client needed — just\n * a plain JSON-RPC POST.\n */\nexport async function getUsdcBalance(address: `0x${string}`, network: Network, rpcUrl?: string): Promise<bigint> {\n const config = NETWORK_CONFIG[network]\n const url = rpcUrl ?? config.rpcUrl\n\n // balanceOf(address) selector = 0x70a08231\n const paddedAddress = address.slice(2).toLowerCase().padStart(64, \"0\")\n const data = `0x70a08231${paddedAddress}`\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: config.usdcAddress, data }, \"latest\"],\n }),\n })\n\n const json = (await res.json()) as { result?: string; error?: unknown }\n if (json.error) {\n throw new Error(`RPC error: ${JSON.stringify(json.error)}`)\n }\n return BigInt(json.result ?? \"0x0\")\n}\n","import type { PrivateKeyAccount } from \"viem\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport type { Network, WaitForFundingOptions } from \"./types.js\"\n\nexport class Wallet {\n readonly name: string\n readonly address: `0x${string}`\n readonly network: Network\n\n private _account: PrivateKeyAccount\n private _privateKey: `0x${string}`\n private _rpcUrl: string | undefined\n private _paymentFetch: typeof globalThis.fetch\n\n constructor(params: {\n name: string\n account: PrivateKeyAccount\n privateKey: `0x${string}`\n network: Network\n rpcUrl?: string\n paymentFetch: typeof globalThis.fetch\n }) {\n this.name = params.name\n this._account = params.account\n this._privateKey = params.privateKey\n this.address = params.account.address\n this.network = params.network\n this._rpcUrl = params.rpcUrl\n this._paymentFetch = params.paymentFetch\n }\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n return getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n }\n\n /**\n * Poll until USDC balance >= minAmount.\n * @param minAmount - minimum USDC balance in minor units (6 decimals)\n */\n async waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void> {\n const interval = opts?.pollInterval ?? 10_000\n const deadline = opts?.timeout ? Date.now() + opts.timeout : null\n\n while (true) {\n const balance = await getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n if (balance >= minAmount) return\n\n if (deadline && Date.now() >= deadline) {\n throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`)\n }\n\n await new Promise((r) => setTimeout(r, interval))\n }\n }\n\n /**\n * Drop-in `fetch()` replacement that handles x402 payments automatically.\n * If the server returns 402, the library signs an EIP-3009 authorization\n * and retries the request with payment headers.\n */\n async fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {\n return this._paymentFetch(input, init)\n }\n}\n","import type { ComputeRequest, ComputeResponse, PricingTier, Size } from \"./types.js\"\n\nconst DEFAULT_ENDPOINT = \"https://x402.auteng.ai/api/x402/compute\"\n\nlet _endpoint = DEFAULT_ENDPOINT\n\nconst PRICING: Record<Size, PricingTier> = {\n small: {\n vcpu: 2,\n ram_gb: 1,\n default_timeout_s: 30,\n max_timeout_s: 300,\n base_price_usd: 0.002,\n per_second_usd: 0.00005,\n },\n med: {\n vcpu: 4,\n ram_gb: 4,\n default_timeout_s: 60,\n max_timeout_s: 600,\n base_price_usd: 0.008,\n per_second_usd: 0.00012,\n },\n large: {\n vcpu: 8,\n ram_gb: 16,\n default_timeout_s: 120,\n max_timeout_s: 3600,\n base_price_usd: 0.03,\n per_second_usd: 0.00025,\n },\n}\n\nexport const compute = {\n /**\n * Execute sandboxed code via AutEng's x402 compute endpoint.\n * Payment is handled automatically via the wallet's x402 layer.\n */\n async run(request: ComputeRequest): Promise<ComputeResponse> {\n if (!request.code) {\n throw new Error(\"compute.run: 'code' is required\")\n }\n if (!request.stack) {\n throw new Error(\"compute.run: 'stack' is required\")\n }\n\n const body = {\n code: request.code,\n stack: request.stack,\n size: request.size ?? \"small\",\n ...(request.timeout_seconds != null && {\n timeout_seconds: request.timeout_seconds,\n }),\n ...(request.files != null && { files: request.files }),\n }\n\n if (!request.wallet) {\n throw new Error(\"compute.run: 'wallet' is required\")\n }\n\n const response = await request.wallet.fetch(_endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\")\n throw new Error(`Compute request failed (${response.status}): ${text}`)\n }\n\n return (await response.json()) as ComputeResponse\n },\n\n /** Returns the pricing table for all compute sizes. */\n pricing(): Record<Size, PricingTier> {\n return { ...PRICING }\n },\n\n /**\n * Override the compute endpoint URL.\n * Default: https://x402.au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;AACF;","names":["import_node_path","import_client","import_accounts"]}
|
package/dist/index.mjs
CHANGED
|
@@ -163,6 +163,7 @@ var Wallet = class {
|
|
|
163
163
|
// src/wallet/index.ts
|
|
164
164
|
var DEFAULT_WALLETS_DIR = ".auteng/wallets";
|
|
165
165
|
var _wallets = /* @__PURE__ */ new Map();
|
|
166
|
+
var _walletsDir = resolve2(DEFAULT_WALLETS_DIR);
|
|
166
167
|
var wallet = {
|
|
167
168
|
/**
|
|
168
169
|
* Create a new named wallet or load an existing one from disk.
|
|
@@ -173,6 +174,7 @@ var wallet = {
|
|
|
173
174
|
validateWalletName(name);
|
|
174
175
|
if (_wallets.has(name)) return _wallets.get(name);
|
|
175
176
|
const dir = resolve2(opts?.walletsDir ?? DEFAULT_WALLETS_DIR);
|
|
177
|
+
_walletsDir = dir;
|
|
176
178
|
const filePath = join2(dir, `${name}.json`);
|
|
177
179
|
const network = opts?.network ?? "base";
|
|
178
180
|
const rpcUrl = opts?.rpcUrl;
|
|
@@ -215,7 +217,7 @@ var wallet = {
|
|
|
215
217
|
get(name) {
|
|
216
218
|
validateWalletName(name);
|
|
217
219
|
if (_wallets.has(name)) return _wallets.get(name);
|
|
218
|
-
const filePath = join2(
|
|
220
|
+
const filePath = join2(_walletsDir, `${name}.json`);
|
|
219
221
|
const data = readWalletFile(filePath);
|
|
220
222
|
if (!data) throw new Error(`Wallet "${name}" not found`);
|
|
221
223
|
const { account } = loadKeypair(data.privateKey);
|
|
@@ -232,12 +234,16 @@ var wallet = {
|
|
|
232
234
|
},
|
|
233
235
|
/** List all persisted wallets. */
|
|
234
236
|
list() {
|
|
235
|
-
const
|
|
236
|
-
const names = listWalletFiles(dir);
|
|
237
|
+
const names = listWalletFiles(_walletsDir);
|
|
237
238
|
return names.map((n) => {
|
|
238
239
|
if (_wallets.has(n)) return _wallets.get(n);
|
|
239
240
|
return wallet.get(n);
|
|
240
241
|
});
|
|
242
|
+
},
|
|
243
|
+
/** @internal Clear in-memory cache and reset wallets dir. For testing only. */
|
|
244
|
+
_reset() {
|
|
245
|
+
_wallets.clear();
|
|
246
|
+
_walletsDir = resolve2(DEFAULT_WALLETS_DIR);
|
|
241
247
|
}
|
|
242
248
|
};
|
|
243
249
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/x402/index.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/wallet/wallet.ts","../src/compute/index.ts"],"sourcesContent":["import { join, resolve } from \"node:path\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile, listWalletFiles, migrateLegacyWallet, validateWalletName } from \"./storage.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport { Wallet } from \"./wallet.js\"\nimport type { CreateWalletOptions } from \"./types.js\"\n\nconst DEFAULT_WALLETS_DIR = \".auteng/wallets\"\n\nconst _wallets = new Map<string, Wallet>()\n\nexport const wallet = {\n /**\n * Create a new named wallet or load an existing one from disk.\n * Idempotent: if a wallet with this name already exists, returns it.\n */\n async create(opts?: CreateWalletOptions): Promise<Wallet> {\n const name = opts?.name ?? \"default\"\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const dir = resolve(opts?.walletsDir ?? DEFAULT_WALLETS_DIR)\n const filePath = join(dir, `${name}.json`)\n const network = opts?.network ?? \"base\"\n const rpcUrl = opts?.rpcUrl\n\n let existing = readWalletFile(filePath)\n\n if (!existing && name === \"default\") {\n existing = migrateLegacyWallet(dir)\n }\n\n let privateKey: `0x${string}`\n let account: ReturnType<typeof loadKeypair>[\"account\"]\n\n if (existing) {\n privateKey = existing.privateKey\n account = loadKeypair(existing.privateKey).account\n } else {\n const kp = createKeypair()\n privateKey = kp.privateKey\n account = kp.account\n writeWalletFile(filePath, {\n privateKey,\n address: account.address,\n network,\n })\n }\n\n const effectiveNetwork = existing?.network ?? network\n const paymentFetch = createPaymentFetch(privateKey, effectiveNetwork, rpcUrl)\n const w = new Wallet({\n name,\n account,\n privateKey,\n network: effectiveNetwork,\n rpcUrl,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /**\n * Retrieve a previously-created wallet by name.\n * Loads from disk if not in memory. Throws if not found.\n */\n get(name: string): Wallet {\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const filePath = join(resolve(DEFAULT_WALLETS_DIR), `${name}.json`)\n const data = readWalletFile(filePath)\n if (!data) throw new Error(`Wallet \"${name}\" not found`)\n\n const { account } = loadKeypair(data.privateKey)\n const paymentFetch = createPaymentFetch(data.privateKey, data.network)\n const w = new Wallet({\n name,\n account,\n privateKey: data.privateKey,\n network: data.network,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /** List all persisted wallets. */\n list(): Wallet[] {\n const dir = resolve(DEFAULT_WALLETS_DIR)\n const names = listWalletFiles(dir)\n return names.map((n) => {\n if (_wallets.has(n)) return _wallets.get(n)!\n return wallet.get(n)\n })\n },\n}\n","import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\"\nimport type { PrivateKeyAccount } from \"viem\"\n\nexport function createKeypair(): {\n privateKey: `0x${string}`\n account: PrivateKeyAccount\n} {\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n return { privateKey, account }\n}\n\nexport function loadKeypair(privateKey: `0x${string}`): {\n account: PrivateKeyAccount\n} {\n const account = privateKeyToAccount(privateKey)\n return { account }\n}\n","import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, copyFileSync } from \"node:fs\"\nimport { dirname, join, resolve } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\n\nconst VALID_NAME = /^[a-z0-9_-]+$/\n\nexport function validateWalletName(name: string): void {\n if (!VALID_NAME.test(name)) {\n throw new Error(\n `Invalid wallet name \"${name}\". Use lowercase letters, numbers, hyphens, and underscores only.`\n )\n }\n}\n\nexport function readWalletFile(path: string): WalletFile | null {\n if (!existsSync(path)) return null\n const raw = readFileSync(path, \"utf-8\")\n return JSON.parse(raw) as WalletFile\n}\n\nexport function writeWalletFile(path: string, data: WalletFile): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(data, null, 2) + \"\\n\", {\n mode: 0o600,\n })\n}\n\nexport function listWalletFiles(dir: string): string[] {\n const resolved = resolve(dir)\n if (!existsSync(resolved)) return []\n return readdirSync(resolved)\n .filter((f) => f.endsWith(\".json\"))\n .map((f) => f.replace(/\\.json$/, \"\"))\n}\n\nexport function migrateLegacyWallet(walletsDir: string): WalletFile | null {\n const legacyPath = resolve(walletsDir, \"..\", \"wallet.json\")\n const newPath = join(resolve(walletsDir), \"default.json\")\n if (existsSync(legacyPath) && !existsSync(newPath)) {\n const data = readWalletFile(legacyPath)\n if (data) {\n mkdirSync(resolve(walletsDir), { recursive: true })\n copyFileSync(legacyPath, newPath)\n return data\n }\n }\n return null\n}\n","import { x402Client } from \"@x402/core/client\"\nimport { registerExactEvmScheme } from \"@x402/evm/exact/client\"\nimport { toClientEvmSigner } from \"@x402/evm\"\nimport { wrapFetchWithPayment } from \"@x402/fetch\"\nimport { privateKeyToAccount } from \"viem/accounts\"\nimport { createPublicClient, http } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\nimport type { Network } from \"../wallet/types.js\"\n\n/**\n * Create a fetch function that automatically handles x402 payments.\n * When the server returns 402, the SDK signs an EIP-3009 authorization\n * using the provided private key and retries with payment headers.\n */\nexport function createPaymentFetch(\n privateKey: `0x${string}`,\n network: Network = \"base\",\n rpcUrl?: string\n): typeof globalThis.fetch {\n const account = privateKeyToAccount(privateKey)\n const chain = network === \"base\" ? base : baseSepolia\n const publicClient = createPublicClient({\n chain,\n transport: http(rpcUrl),\n })\n const signer = toClientEvmSigner(account, publicClient)\n\n const client = new x402Client()\n registerExactEvmScheme(client, { signer })\n return wrapFetchWithPayment(fetch, client)\n}\n","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface CreateWalletOptions {\n /** Wallet identifier. Default: \"default\" */\n name?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n /** Base directory for wallet storage. Default: \".auteng/wallets\" */\n walletsDir?: string\n}\n\n/** @deprecated Use CreateWalletOptions instead */\nexport type WalletConfig = CreateWalletOptions\n\nexport interface WalletFile {\n privateKey: `0x${string}`\n address: `0x${string}`\n network: Network\n}\n\nexport interface WaitForFundingOptions {\n /** Poll interval in milliseconds. Default: 10000 (10s) */\n pollInterval?: number\n /** Timeout in milliseconds. Default: none (waits forever) */\n timeout?: number\n}\n\nexport const NETWORK_CONFIG: Record<Network, { chainId: number; usdcAddress: `0x${string}`; rpcUrl: string }> = {\n base: {\n chainId: 8453,\n usdcAddress: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n rpcUrl: \"https://mainnet.base.org\",\n },\n \"base-sepolia\": {\n chainId: 84532,\n usdcAddress: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n rpcUrl: \"https://sepolia.base.org\",\n },\n}\n","import type { Network } from \"./types.js\"\nimport { NETWORK_CONFIG } from \"./types.js\"\n\n/**\n * Read USDC balance for `address` via a direct `eth_call` to the USDC\n * contract's `balanceOf(address)` function. No viem client needed — just\n * a plain JSON-RPC POST.\n */\nexport async function getUsdcBalance(address: `0x${string}`, network: Network, rpcUrl?: string): Promise<bigint> {\n const config = NETWORK_CONFIG[network]\n const url = rpcUrl ?? config.rpcUrl\n\n // balanceOf(address) selector = 0x70a08231\n const paddedAddress = address.slice(2).toLowerCase().padStart(64, \"0\")\n const data = `0x70a08231${paddedAddress}`\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: config.usdcAddress, data }, \"latest\"],\n }),\n })\n\n const json = (await res.json()) as { result?: string; error?: unknown }\n if (json.error) {\n throw new Error(`RPC error: ${JSON.stringify(json.error)}`)\n }\n return BigInt(json.result ?? \"0x0\")\n}\n","import type { PrivateKeyAccount } from \"viem\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport type { Network, WaitForFundingOptions } from \"./types.js\"\n\nexport class Wallet {\n readonly name: string\n readonly address: `0x${string}`\n readonly network: Network\n\n private _account: PrivateKeyAccount\n private _privateKey: `0x${string}`\n private _rpcUrl: string | undefined\n private _paymentFetch: typeof globalThis.fetch\n\n constructor(params: {\n name: string\n account: PrivateKeyAccount\n privateKey: `0x${string}`\n network: Network\n rpcUrl?: string\n paymentFetch: typeof globalThis.fetch\n }) {\n this.name = params.name\n this._account = params.account\n this._privateKey = params.privateKey\n this.address = params.account.address\n this.network = params.network\n this._rpcUrl = params.rpcUrl\n this._paymentFetch = params.paymentFetch\n }\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n return getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n }\n\n /**\n * Poll until USDC balance >= minAmount.\n * @param minAmount - minimum USDC balance in minor units (6 decimals)\n */\n async waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void> {\n const interval = opts?.pollInterval ?? 10_000\n const deadline = opts?.timeout ? Date.now() + opts.timeout : null\n\n while (true) {\n const balance = await getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n if (balance >= minAmount) return\n\n if (deadline && Date.now() >= deadline) {\n throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`)\n }\n\n await new Promise((r) => setTimeout(r, interval))\n }\n }\n\n /**\n * Drop-in `fetch()` replacement that handles x402 payments automatically.\n * If the server returns 402, the library signs an EIP-3009 authorization\n * and retries the request with payment headers.\n */\n async fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {\n return this._paymentFetch(input, init)\n }\n}\n","import type { ComputeRequest, ComputeResponse, PricingTier, Size } from \"./types.js\"\n\nconst DEFAULT_ENDPOINT = \"https://x402.auteng.ai/api/x402/compute\"\n\nlet _endpoint = DEFAULT_ENDPOINT\n\nconst PRICING: Record<Size, PricingTier> = {\n small: {\n vcpu: 2,\n ram_gb: 1,\n default_timeout_s: 30,\n max_timeout_s: 300,\n base_price_usd: 0.002,\n per_second_usd: 0.00005,\n },\n med: {\n vcpu: 4,\n ram_gb: 4,\n default_timeout_s: 60,\n max_timeout_s: 600,\n base_price_usd: 0.008,\n per_second_usd: 0.00012,\n },\n large: {\n vcpu: 8,\n ram_gb: 16,\n default_timeout_s: 120,\n max_timeout_s: 3600,\n base_price_usd: 0.03,\n per_second_usd: 0.00025,\n },\n}\n\nexport const compute = {\n /**\n * Execute sandboxed code via AutEng's x402 compute endpoint.\n * Payment is handled automatically via the wallet's x402 layer.\n */\n async run(request: ComputeRequest): Promise<ComputeResponse> {\n if (!request.code) {\n throw new Error(\"compute.run: 'code' is required\")\n }\n if (!request.stack) {\n throw new Error(\"compute.run: 'stack' is required\")\n }\n\n const body = {\n code: request.code,\n stack: request.stack,\n size: request.size ?? \"small\",\n ...(request.timeout_seconds != null && {\n timeout_seconds: request.timeout_seconds,\n }),\n ...(request.files != null && { files: request.files }),\n }\n\n if (!request.wallet) {\n throw new Error(\"compute.run: 'wallet' is required\")\n }\n\n const response = await request.wallet.fetch(_endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\")\n throw new Error(`Compute request failed (${response.status}): ${text}`)\n }\n\n return (await response.json()) as ComputeResponse\n },\n\n /** Returns the pricing table for all compute sizes. */\n pricing(): Record<Size, PricingTier> {\n return { ...PRICING }\n },\n\n /**\n * Override the compute endpoint URL.\n * Default: https://x402.auteng.ai/api/x402/compute\n */\n setEndpoint(url: string): void {\n _endpoint = url\n },\n}\n"],"mappings":";AAAA,SAAS,QAAAA,OAAM,WAAAC,gBAAe;;;ACA9B,SAAS,oBAAoB,2BAA2B;AAGjD,SAAS,gBAGd;A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AA;AAAA,EAKrB,MAAM,IAAI,SAAmD;AAC3D,QAAI,CAAC,QAAQ,MAAM;AACjB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,QAAI,CAAC,QAAQ,OAAO;AAClB,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AAEA,UAAM,OAAO;AAAA,MACX,MAAM,QAAQ;AAAA,MACd,OAAO,QAAQ;AAAA,MACf,MAAM,QAAQ,QAAQ;AAAA,MACtB,GAAI,QAAQ,mBAAmB,QAAQ;AAAA,QACrC,iBAAiB,QAAQ;AAAA,MAC3B;AAAA,MACA,GAAI,QAAQ,SAAS,QAAQ,EAAE,OAAO,QAAQ,MAAM;AAAA,IACtD;AAEA,QAAI,CAAC,QAAQ,QAAQ;AACnB,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AAEA,UAAM,WAAW,MAAM,QAAQ,OAAO,MAAM,WAAW;AAAA,MACrD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,EAAE;AACjD,YAAM,IAAI,MAAM,2BAA2B,SAAS,MAAM,MAAM,IAAI,EAAE;AAAA,IACxE;AAEA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAC9B;AAAA;AAAA,EAGA,UAAqC;AACnC,WAAO,EAAE,GAAG,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAY,KAAmB;AAC7B,gBAAY;AAAA,EACd;AACF;","names":["join","resolve","privateKeyToAccount","resolve","join"]}
|
|
1
|
+
{"version":3,"sources":["../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/x402/index.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/wallet/wallet.ts","../src/compute/index.ts"],"sourcesContent":["import { join, resolve } from \"node:path\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile, listWalletFiles, migrateLegacyWallet, validateWalletName } from \"./storage.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport { Wallet } from \"./wallet.js\"\nimport type { CreateWalletOptions } from \"./types.js\"\n\nconst DEFAULT_WALLETS_DIR = \".auteng/wallets\"\n\nconst _wallets = new Map<string, Wallet>()\nlet _walletsDir = resolve(DEFAULT_WALLETS_DIR)\n\nexport const wallet = {\n /**\n * Create a new named wallet or load an existing one from disk.\n * Idempotent: if a wallet with this name already exists, returns it.\n */\n async create(opts?: CreateWalletOptions): Promise<Wallet> {\n const name = opts?.name ?? \"default\"\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const dir = resolve(opts?.walletsDir ?? DEFAULT_WALLETS_DIR)\n _walletsDir = dir\n const filePath = join(dir, `${name}.json`)\n const network = opts?.network ?? \"base\"\n const rpcUrl = opts?.rpcUrl\n\n let existing = readWalletFile(filePath)\n\n if (!existing && name === \"default\") {\n existing = migrateLegacyWallet(dir)\n }\n\n let privateKey: `0x${string}`\n let account: ReturnType<typeof loadKeypair>[\"account\"]\n\n if (existing) {\n privateKey = existing.privateKey\n account = loadKeypair(existing.privateKey).account\n } else {\n const kp = createKeypair()\n privateKey = kp.privateKey\n account = kp.account\n writeWalletFile(filePath, {\n privateKey,\n address: account.address,\n network,\n })\n }\n\n const effectiveNetwork = existing?.network ?? network\n const paymentFetch = createPaymentFetch(privateKey, effectiveNetwork, rpcUrl)\n const w = new Wallet({\n name,\n account,\n privateKey,\n network: effectiveNetwork,\n rpcUrl,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /**\n * Retrieve a previously-created wallet by name.\n * Loads from disk if not in memory. Throws if not found.\n */\n get(name: string): Wallet {\n validateWalletName(name)\n\n if (_wallets.has(name)) return _wallets.get(name)!\n\n const filePath = join(_walletsDir, `${name}.json`)\n const data = readWalletFile(filePath)\n if (!data) throw new Error(`Wallet \"${name}\" not found`)\n\n const { account } = loadKeypair(data.privateKey)\n const paymentFetch = createPaymentFetch(data.privateKey, data.network)\n const w = new Wallet({\n name,\n account,\n privateKey: data.privateKey,\n network: data.network,\n paymentFetch,\n })\n _wallets.set(name, w)\n return w\n },\n\n /** List all persisted wallets. */\n list(): Wallet[] {\n const names = listWalletFiles(_walletsDir)\n return names.map((n) => {\n if (_wallets.has(n)) return _wallets.get(n)!\n return wallet.get(n)\n })\n },\n\n /** @internal Clear in-memory cache and reset wallets dir. For testing only. */\n _reset(): void {\n _wallets.clear()\n _walletsDir = resolve(DEFAULT_WALLETS_DIR)\n },\n}\n","import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\"\nimport type { PrivateKeyAccount } from \"viem\"\n\nexport function createKeypair(): {\n privateKey: `0x${string}`\n account: PrivateKeyAccount\n} {\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n return { privateKey, account }\n}\n\nexport function loadKeypair(privateKey: `0x${string}`): {\n account: PrivateKeyAccount\n} {\n const account = privateKeyToAccount(privateKey)\n return { account }\n}\n","import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, copyFileSync } from \"node:fs\"\nimport { dirname, join, resolve } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\n\nconst VALID_NAME = /^[a-z0-9_-]+$/\n\nexport function validateWalletName(name: string): void {\n if (!VALID_NAME.test(name)) {\n throw new Error(\n `Invalid wallet name \"${name}\". Use lowercase letters, numbers, hyphens, and underscores only.`\n )\n }\n}\n\nexport function readWalletFile(path: string): WalletFile | null {\n if (!existsSync(path)) return null\n const raw = readFileSync(path, \"utf-8\")\n return JSON.parse(raw) as WalletFile\n}\n\nexport function writeWalletFile(path: string, data: WalletFile): void {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(data, null, 2) + \"\\n\", {\n mode: 0o600,\n })\n}\n\nexport function listWalletFiles(dir: string): string[] {\n const resolved = resolve(dir)\n if (!existsSync(resolved)) return []\n return readdirSync(resolved)\n .filter((f) => f.endsWith(\".json\"))\n .map((f) => f.replace(/\\.json$/, \"\"))\n}\n\nexport function migrateLegacyWallet(walletsDir: string): WalletFile | null {\n const legacyPath = resolve(walletsDir, \"..\", \"wallet.json\")\n const newPath = join(resolve(walletsDir), \"default.json\")\n if (existsSync(legacyPath) && !existsSync(newPath)) {\n const data = readWalletFile(legacyPath)\n if (data) {\n mkdirSync(resolve(walletsDir), { recursive: true })\n copyFileSync(legacyPath, newPath)\n return data\n }\n }\n return null\n}\n","import { x402Client } from \"@x402/core/client\"\nimport { registerExactEvmScheme } from \"@x402/evm/exact/client\"\nimport { toClientEvmSigner } from \"@x402/evm\"\nimport { wrapFetchWithPayment } from \"@x402/fetch\"\nimport { privateKeyToAccount } from \"viem/accounts\"\nimport { createPublicClient, http } from \"viem\"\nimport { base, baseSepolia } from \"viem/chains\"\nimport type { Network } from \"../wallet/types.js\"\n\n/**\n * Create a fetch function that automatically handles x402 payments.\n * When the server returns 402, the SDK signs an EIP-3009 authorization\n * using the provided private key and retries with payment headers.\n */\nexport function createPaymentFetch(\n privateKey: `0x${string}`,\n network: Network = \"base\",\n rpcUrl?: string\n): typeof globalThis.fetch {\n const account = privateKeyToAccount(privateKey)\n const chain = network === \"base\" ? base : baseSepolia\n const publicClient = createPublicClient({\n chain,\n transport: http(rpcUrl),\n })\n const signer = toClientEvmSigner(account, publicClient)\n\n const client = new x402Client()\n registerExactEvmScheme(client, { signer })\n return wrapFetchWithPayment(fetch, client)\n}\n","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface CreateWalletOptions {\n /** Wallet identifier. Default: \"default\" */\n name?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n /** Base directory for wallet storage. Default: \".auteng/wallets\" */\n walletsDir?: string\n}\n\n/** @deprecated Use CreateWalletOptions instead */\nexport type WalletConfig = CreateWalletOptions\n\nexport interface WalletFile {\n privateKey: `0x${string}`\n address: `0x${string}`\n network: Network\n}\n\nexport interface WaitForFundingOptions {\n /** Poll interval in milliseconds. Default: 10000 (10s) */\n pollInterval?: number\n /** Timeout in milliseconds. Default: none (waits forever) */\n timeout?: number\n}\n\nexport const NETWORK_CONFIG: Record<Network, { chainId: number; usdcAddress: `0x${string}`; rpcUrl: string }> = {\n base: {\n chainId: 8453,\n usdcAddress: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n rpcUrl: \"https://mainnet.base.org\",\n },\n \"base-sepolia\": {\n chainId: 84532,\n usdcAddress: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n rpcUrl: \"https://sepolia.base.org\",\n },\n}\n","import type { Network } from \"./types.js\"\nimport { NETWORK_CONFIG } from \"./types.js\"\n\n/**\n * Read USDC balance for `address` via a direct `eth_call` to the USDC\n * contract's `balanceOf(address)` function. No viem client needed — just\n * a plain JSON-RPC POST.\n */\nexport async function getUsdcBalance(address: `0x${string}`, network: Network, rpcUrl?: string): Promise<bigint> {\n const config = NETWORK_CONFIG[network]\n const url = rpcUrl ?? config.rpcUrl\n\n // balanceOf(address) selector = 0x70a08231\n const paddedAddress = address.slice(2).toLowerCase().padStart(64, \"0\")\n const data = `0x70a08231${paddedAddress}`\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_call\",\n params: [{ to: config.usdcAddress, data }, \"latest\"],\n }),\n })\n\n const json = (await res.json()) as { result?: string; error?: unknown }\n if (json.error) {\n throw new Error(`RPC error: ${JSON.stringify(json.error)}`)\n }\n return BigInt(json.result ?? \"0x0\")\n}\n","import type { PrivateKeyAccount } from \"viem\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport type { Network, WaitForFundingOptions } from \"./types.js\"\n\nexport class Wallet {\n readonly name: string\n readonly address: `0x${string}`\n readonly network: Network\n\n private _account: PrivateKeyAccount\n private _privateKey: `0x${string}`\n private _rpcUrl: string | undefined\n private _paymentFetch: typeof globalThis.fetch\n\n constructor(params: {\n name: string\n account: PrivateKeyAccount\n privateKey: `0x${string}`\n network: Network\n rpcUrl?: string\n paymentFetch: typeof globalThis.fetch\n }) {\n this.name = params.name\n this._account = params.account\n this._privateKey = params.privateKey\n this.address = params.account.address\n this.network = params.network\n this._rpcUrl = params.rpcUrl\n this._paymentFetch = params.paymentFetch\n }\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n return getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n }\n\n /**\n * Poll until USDC balance >= minAmount.\n * @param minAmount - minimum USDC balance in minor units (6 decimals)\n */\n async waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void> {\n const interval = opts?.pollInterval ?? 10_000\n const deadline = opts?.timeout ? Date.now() + opts.timeout : null\n\n while (true) {\n const balance = await getUsdcBalance(this._account.address, this.network, this._rpcUrl)\n if (balance >= minAmount) return\n\n if (deadline && Date.now() >= deadline) {\n throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`)\n }\n\n await new Promise((r) => setTimeout(r, interval))\n }\n }\n\n /**\n * Drop-in `fetch()` replacement that handles x402 payments automatically.\n * If the server returns 402, the library signs an EIP-3009 authorization\n * and retries the request with payment headers.\n */\n async fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {\n return this._paymentFetch(input, init)\n }\n}\n","import type { ComputeRequest, ComputeResponse, PricingTier, Size } from \"./types.js\"\n\nconst DEFAULT_ENDPOINT = \"https://x402.auteng.ai/api/x402/compute\"\n\nlet _endpoint = DEFAULT_ENDPOINT\n\nconst PRICING: Record<Size, PricingTier> = {\n small: {\n vcpu: 2,\n ram_gb: 1,\n default_timeout_s: 30,\n max_timeout_s: 300,\n base_price_usd: 0.002,\n per_second_usd: 0.00005,\n },\n med: {\n vcpu: 4,\n ram_gb: 4,\n default_timeout_s: 60,\n max_timeout_s: 600,\n base_price_usd: 0.008,\n per_second_usd: 0.00012,\n },\n large: {\n vcpu: 8,\n ram_gb: 16,\n default_timeout_s: 120,\n max_timeout_s: 3600,\n base_price_usd: 0.03,\n per_second_usd: 0.00025,\n },\n}\n\nexport const compute = {\n /**\n * Execute sandboxed code via AutEng's x402 compute endpoint.\n * Payment is handled automatically via the wallet's x402 layer.\n */\n async run(request: ComputeRequest): Promise<ComputeResponse> {\n if (!request.code) {\n throw new Error(\"compute.run: 'code' is required\")\n }\n if (!request.stack) {\n throw new Error(\"compute.run: 'stack' is required\")\n }\n\n const body = {\n code: request.code,\n stack: request.stack,\n size: request.size ?? \"small\",\n ...(request.timeout_seconds != null && {\n timeout_seconds: request.timeout_seconds,\n }),\n ...(request.files != null && { files: request.files }),\n }\n\n if (!request.wallet) {\n throw new Error(\"compute.run: 'wallet' is required\")\n }\n\n const response = await request.wallet.fetch(_endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\")\n throw new Error(`Compute request failed (${response.status}): ${text}`)\n }\n\n return (await response.json()) as ComputeResponse\n },\n\n /** Returns the pricing table for all compute sizes. */\n pricing(): Record<Size, PricingTier> {\n return { ...PRICING }\n },\n\n /**\n * Override the compute endpoint URL.\n * Default: https://x402.auteng.ai/api/x402/compute\n */\n setEndpoint(url: string): void {\n _endpoint = url\n },\n}\n"],"mappings":";AAAA,SAAS,QAAAA,OAAM,WAAAC,gBAAe;;;ACA9B,SAAS,oBAAoB,2BAA2B;AAGjD,SAAS,gBAGd;AACA,QAAM,aAAa,mBAAmB;AACtC,QAAM,UAAU,oBAAoB,UAAU;AAC9C,SAAO,EAAE,YAAY,QAAQ;AAC/B;AAEO,SAAS,YAAY,YAE1B;AACA,QAAM,UAAU,oBAAoB,UAAU;AAC9C,SAAO,EAAE,QAAQ;AACnB;;;ACjBA,SAAS,WAAW,cAAc,eAAe,YAAY,aAAa,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AM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AAEA,UAAM,OAAO;AAAA,MACX,MAAM,QAAQ;AAAA,MACd,OAAO,QAAQ;AAAA,MACf,MAAM,QAAQ,QAAQ;AAAA,MACtB,GAAI,QAAQ,mBAAmB,QAAQ;AAAA,QACrC,iBAAiB,QAAQ;AAAA,MAC3B;AAAA,MACA,GAAI,QAAQ,SAAS,QAAQ,EAAE,OAAO,QAAQ,MAAM;AAAA,IACtD;AAEA,QAAI,CAAC,QAAQ,QAAQ;AACnB,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AAEA,UAAM,WAAW,MAAM,QAAQ,OAAO,MAAM,WAAW;AAAA,MACrD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,OAAO,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,EAAE;AACjD,YAAM,IAAI,MAAM,2BAA2B,SAAS,MAAM,MAAM,IAAI,EAAE;AAAA,IACxE;AAEA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAC9B;AAAA;AAAA,EAGA,UAAqC;AACnC,WAAO,EAAE,GAAG,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAY,KAAmB;AAC7B,gBAAY;AAAA,EACd;AACF;","names":["join","resolve","privateKeyToAccount","resolve","join"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auteng/agent-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Utility belt for autonomous AI agents — wallet, compute, and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,19 +19,22 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"dev": "tsup --watch",
|
|
22
|
-
"clean": "rimraf dist"
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest"
|
|
23
25
|
},
|
|
24
26
|
"dependencies": {
|
|
25
|
-
"viem": "^2.39.0",
|
|
26
27
|
"@x402/core": "^2.2.0",
|
|
27
28
|
"@x402/evm": "^2.2.0",
|
|
28
|
-
"@x402/fetch": "^2.2.0"
|
|
29
|
+
"@x402/fetch": "^2.2.0",
|
|
30
|
+
"viem": "^2.39.0"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
33
|
+
"@types/node": "^20.0.0",
|
|
34
|
+
"rimraf": "^5.0.10",
|
|
31
35
|
"tsup": "^8.0.0",
|
|
32
36
|
"typescript": "^5.4.5",
|
|
33
|
-
"
|
|
34
|
-
"@types/node": "^20.0.0"
|
|
37
|
+
"vitest": "^4.0.18"
|
|
35
38
|
},
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|