@auteng/agent-utils 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/dist/index.d.mts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +273 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +245 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
type Network = "base" | "base-sepolia";
|
|
2
|
+
interface WalletConfig {
|
|
3
|
+
/** Path to store the wallet keypair. Default: `.auteng/wallet.json` */
|
|
4
|
+
keyPath?: string;
|
|
5
|
+
/** Network to use. Default: `base` */
|
|
6
|
+
network?: Network;
|
|
7
|
+
/** Custom RPC endpoint. Default: public Base RPC */
|
|
8
|
+
rpcUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
interface WaitForFundingOptions {
|
|
11
|
+
/** Poll interval in milliseconds. Default: 10000 (10s) */
|
|
12
|
+
pollInterval?: number;
|
|
13
|
+
/** Timeout in milliseconds. Default: none (waits forever) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const wallet: {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new EVM wallet or load an existing one from disk.
|
|
20
|
+
* Idempotent: if the wallet file already exists, loads it.
|
|
21
|
+
*/
|
|
22
|
+
create(opts?: WalletConfig): Promise<void>;
|
|
23
|
+
/** The wallet's public address. Throws if not created. */
|
|
24
|
+
readonly address: `0x${string}`;
|
|
25
|
+
/** Check USDC balance on Base. Returns balance in minor units (6 decimals). */
|
|
26
|
+
checkBalance(): Promise<bigint>;
|
|
27
|
+
/**
|
|
28
|
+
* Poll until USDC balance >= minAmount.
|
|
29
|
+
* @param minAmount - minimum USDC balance in minor units (6 decimals)
|
|
30
|
+
*/
|
|
31
|
+
waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Drop-in `fetch()` replacement that handles x402 payments automatically.
|
|
34
|
+
* If the server returns 402, the library signs an EIP-3009 authorization
|
|
35
|
+
* and retries the request with payment headers.
|
|
36
|
+
*/
|
|
37
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type Stack = "python" | "node";
|
|
41
|
+
type Size = "small" | "med" | "large";
|
|
42
|
+
interface ComputeRequest {
|
|
43
|
+
/** The code to execute */
|
|
44
|
+
code: string;
|
|
45
|
+
/** Runtime stack: 'python' (3.14) or 'node' (24 LTS) */
|
|
46
|
+
stack: Stack;
|
|
47
|
+
/** Sandbox size. Default: 'small' */
|
|
48
|
+
size?: Size;
|
|
49
|
+
/** Execution timeout in seconds. Default: per-size default */
|
|
50
|
+
timeout_seconds?: number;
|
|
51
|
+
/** Optional files to include: filename → base64 content */
|
|
52
|
+
files?: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
interface ComputeResponse {
|
|
55
|
+
stdout: string;
|
|
56
|
+
stderr: string;
|
|
57
|
+
exit_code: number;
|
|
58
|
+
execution_time_ms: number;
|
|
59
|
+
}
|
|
60
|
+
interface PricingTier {
|
|
61
|
+
vcpu: number;
|
|
62
|
+
ram_gb: number;
|
|
63
|
+
default_timeout_s: number;
|
|
64
|
+
max_timeout_s: number;
|
|
65
|
+
base_price_usd: number;
|
|
66
|
+
per_second_usd: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare const compute: {
|
|
70
|
+
/**
|
|
71
|
+
* Execute sandboxed code via AutEng's x402 compute endpoint.
|
|
72
|
+
* Payment is handled automatically via the wallet's x402 layer.
|
|
73
|
+
*/
|
|
74
|
+
run(request: ComputeRequest): Promise<ComputeResponse>;
|
|
75
|
+
/** Returns the pricing table for all compute sizes. */
|
|
76
|
+
pricing(): Record<Size, PricingTier>;
|
|
77
|
+
/**
|
|
78
|
+
* Override the compute endpoint URL.
|
|
79
|
+
* Default: https://x402.auteng.ai/api/x402/compute
|
|
80
|
+
*/
|
|
81
|
+
setEndpoint(url: string): void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { type ComputeRequest, type ComputeResponse, type Network, type PricingTier, type Size, type Stack, type WaitForFundingOptions, type WalletConfig, compute, wallet };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
type Network = "base" | "base-sepolia";
|
|
2
|
+
interface WalletConfig {
|
|
3
|
+
/** Path to store the wallet keypair. Default: `.auteng/wallet.json` */
|
|
4
|
+
keyPath?: string;
|
|
5
|
+
/** Network to use. Default: `base` */
|
|
6
|
+
network?: Network;
|
|
7
|
+
/** Custom RPC endpoint. Default: public Base RPC */
|
|
8
|
+
rpcUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
interface WaitForFundingOptions {
|
|
11
|
+
/** Poll interval in milliseconds. Default: 10000 (10s) */
|
|
12
|
+
pollInterval?: number;
|
|
13
|
+
/** Timeout in milliseconds. Default: none (waits forever) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const wallet: {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new EVM wallet or load an existing one from disk.
|
|
20
|
+
* Idempotent: if the wallet file already exists, loads it.
|
|
21
|
+
*/
|
|
22
|
+
create(opts?: WalletConfig): Promise<void>;
|
|
23
|
+
/** The wallet's public address. Throws if not created. */
|
|
24
|
+
readonly address: `0x${string}`;
|
|
25
|
+
/** Check USDC balance on Base. Returns balance in minor units (6 decimals). */
|
|
26
|
+
checkBalance(): Promise<bigint>;
|
|
27
|
+
/**
|
|
28
|
+
* Poll until USDC balance >= minAmount.
|
|
29
|
+
* @param minAmount - minimum USDC balance in minor units (6 decimals)
|
|
30
|
+
*/
|
|
31
|
+
waitForFunding(minAmount: bigint, opts?: WaitForFundingOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Drop-in `fetch()` replacement that handles x402 payments automatically.
|
|
34
|
+
* If the server returns 402, the library signs an EIP-3009 authorization
|
|
35
|
+
* and retries the request with payment headers.
|
|
36
|
+
*/
|
|
37
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type Stack = "python" | "node";
|
|
41
|
+
type Size = "small" | "med" | "large";
|
|
42
|
+
interface ComputeRequest {
|
|
43
|
+
/** The code to execute */
|
|
44
|
+
code: string;
|
|
45
|
+
/** Runtime stack: 'python' (3.14) or 'node' (24 LTS) */
|
|
46
|
+
stack: Stack;
|
|
47
|
+
/** Sandbox size. Default: 'small' */
|
|
48
|
+
size?: Size;
|
|
49
|
+
/** Execution timeout in seconds. Default: per-size default */
|
|
50
|
+
timeout_seconds?: number;
|
|
51
|
+
/** Optional files to include: filename → base64 content */
|
|
52
|
+
files?: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
interface ComputeResponse {
|
|
55
|
+
stdout: string;
|
|
56
|
+
stderr: string;
|
|
57
|
+
exit_code: number;
|
|
58
|
+
execution_time_ms: number;
|
|
59
|
+
}
|
|
60
|
+
interface PricingTier {
|
|
61
|
+
vcpu: number;
|
|
62
|
+
ram_gb: number;
|
|
63
|
+
default_timeout_s: number;
|
|
64
|
+
max_timeout_s: number;
|
|
65
|
+
base_price_usd: number;
|
|
66
|
+
per_second_usd: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare const compute: {
|
|
70
|
+
/**
|
|
71
|
+
* Execute sandboxed code via AutEng's x402 compute endpoint.
|
|
72
|
+
* Payment is handled automatically via the wallet's x402 layer.
|
|
73
|
+
*/
|
|
74
|
+
run(request: ComputeRequest): Promise<ComputeResponse>;
|
|
75
|
+
/** Returns the pricing table for all compute sizes. */
|
|
76
|
+
pricing(): Record<Size, PricingTier>;
|
|
77
|
+
/**
|
|
78
|
+
* Override the compute endpoint URL.
|
|
79
|
+
* Default: https://x402.auteng.ai/api/x402/compute
|
|
80
|
+
*/
|
|
81
|
+
setEndpoint(url: string): void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { type ComputeRequest, type ComputeResponse, type Network, type PricingTier, type Size, type Stack, type WaitForFundingOptions, type WalletConfig, compute, wallet };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
compute: () => compute,
|
|
24
|
+
wallet: () => wallet
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/wallet/index.ts
|
|
29
|
+
var import_node_path2 = require("path");
|
|
30
|
+
|
|
31
|
+
// src/wallet/keypair.ts
|
|
32
|
+
var import_accounts = require("viem/accounts");
|
|
33
|
+
function createKeypair() {
|
|
34
|
+
const privateKey = (0, import_accounts.generatePrivateKey)();
|
|
35
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
36
|
+
return { privateKey, account };
|
|
37
|
+
}
|
|
38
|
+
function loadKeypair(privateKey) {
|
|
39
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
40
|
+
return { account };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/wallet/storage.ts
|
|
44
|
+
var import_node_fs = require("fs");
|
|
45
|
+
var import_node_path = require("path");
|
|
46
|
+
function readWalletFile(path) {
|
|
47
|
+
if (!(0, import_node_fs.existsSync)(path)) return null;
|
|
48
|
+
const raw = (0, import_node_fs.readFileSync)(path, "utf-8");
|
|
49
|
+
return JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
function writeWalletFile(path, data) {
|
|
52
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(path), { recursive: true });
|
|
53
|
+
(0, import_node_fs.writeFileSync)(path, JSON.stringify(data, null, 2) + "\n", {
|
|
54
|
+
mode: 384
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/wallet/types.ts
|
|
59
|
+
var NETWORK_CONFIG = {
|
|
60
|
+
base: {
|
|
61
|
+
chainId: 8453,
|
|
62
|
+
usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
63
|
+
rpcUrl: "https://mainnet.base.org"
|
|
64
|
+
},
|
|
65
|
+
"base-sepolia": {
|
|
66
|
+
chainId: 84532,
|
|
67
|
+
usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
68
|
+
rpcUrl: "https://sepolia.base.org"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/wallet/balance.ts
|
|
73
|
+
async function getUsdcBalance(address, network, rpcUrl) {
|
|
74
|
+
const config = NETWORK_CONFIG[network];
|
|
75
|
+
const url = rpcUrl ?? config.rpcUrl;
|
|
76
|
+
const paddedAddress = address.slice(2).toLowerCase().padStart(64, "0");
|
|
77
|
+
const data = `0x70a08231${paddedAddress}`;
|
|
78
|
+
const res = await fetch(url, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: { "Content-Type": "application/json" },
|
|
81
|
+
body: JSON.stringify({
|
|
82
|
+
jsonrpc: "2.0",
|
|
83
|
+
id: 1,
|
|
84
|
+
method: "eth_call",
|
|
85
|
+
params: [{ to: config.usdcAddress, data }, "latest"]
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
const json = await res.json();
|
|
89
|
+
if (json.error) {
|
|
90
|
+
throw new Error(`RPC error: ${JSON.stringify(json.error)}`);
|
|
91
|
+
}
|
|
92
|
+
return BigInt(json.result ?? "0x0");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/x402/index.ts
|
|
96
|
+
var import_client = require("@x402/core/client");
|
|
97
|
+
var import_client2 = require("@x402/evm/exact/client");
|
|
98
|
+
var import_evm = require("@x402/evm");
|
|
99
|
+
var import_fetch = require("@x402/fetch");
|
|
100
|
+
var import_accounts2 = require("viem/accounts");
|
|
101
|
+
var import_viem = require("viem");
|
|
102
|
+
var import_chains = require("viem/chains");
|
|
103
|
+
function createPaymentFetch(privateKey, network = "base", rpcUrl) {
|
|
104
|
+
const account = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
105
|
+
const chain = network === "base" ? import_chains.base : import_chains.baseSepolia;
|
|
106
|
+
const publicClient = (0, import_viem.createPublicClient)({
|
|
107
|
+
chain,
|
|
108
|
+
transport: (0, import_viem.http)(rpcUrl)
|
|
109
|
+
});
|
|
110
|
+
const signer = (0, import_evm.toClientEvmSigner)(account, publicClient);
|
|
111
|
+
const client = new import_client.x402Client();
|
|
112
|
+
(0, import_client2.registerExactEvmScheme)(client, { signer });
|
|
113
|
+
return (0, import_fetch.wrapFetchWithPayment)(fetch, client);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/wallet/index.ts
|
|
117
|
+
var _account = null;
|
|
118
|
+
var _privateKey = null;
|
|
119
|
+
var _network = "base";
|
|
120
|
+
var _rpcUrl;
|
|
121
|
+
var _paymentFetch = null;
|
|
122
|
+
function ensureCreated() {
|
|
123
|
+
if (!_account) {
|
|
124
|
+
throw new Error("Wallet not initialized. Call wallet.create() first.");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
var wallet = {
|
|
128
|
+
/**
|
|
129
|
+
* Create a new EVM wallet or load an existing one from disk.
|
|
130
|
+
* Idempotent: if the wallet file already exists, loads it.
|
|
131
|
+
*/
|
|
132
|
+
async create(opts) {
|
|
133
|
+
const keyPath = (0, import_node_path2.resolve)(opts?.keyPath ?? ".auteng/wallet.json");
|
|
134
|
+
_network = opts?.network ?? "base";
|
|
135
|
+
_rpcUrl = opts?.rpcUrl;
|
|
136
|
+
const existing = readWalletFile(keyPath);
|
|
137
|
+
if (existing) {
|
|
138
|
+
_privateKey = existing.privateKey;
|
|
139
|
+
const { account } = loadKeypair(existing.privateKey);
|
|
140
|
+
_account = account;
|
|
141
|
+
_network = existing.network;
|
|
142
|
+
} else {
|
|
143
|
+
const { privateKey, account } = createKeypair();
|
|
144
|
+
_privateKey = privateKey;
|
|
145
|
+
_account = account;
|
|
146
|
+
writeWalletFile(keyPath, {
|
|
147
|
+
privateKey,
|
|
148
|
+
address: account.address,
|
|
149
|
+
network: _network
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
_paymentFetch = createPaymentFetch(_privateKey, _network, _rpcUrl);
|
|
153
|
+
},
|
|
154
|
+
/** The wallet's public address. Throws if not created. */
|
|
155
|
+
get address() {
|
|
156
|
+
ensureCreated();
|
|
157
|
+
return _account.address;
|
|
158
|
+
},
|
|
159
|
+
/** Check USDC balance on Base. Returns balance in minor units (6 decimals). */
|
|
160
|
+
async checkBalance() {
|
|
161
|
+
ensureCreated();
|
|
162
|
+
return getUsdcBalance(_account.address, _network, _rpcUrl);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Poll until USDC balance >= minAmount.
|
|
166
|
+
* @param minAmount - minimum USDC balance in minor units (6 decimals)
|
|
167
|
+
*/
|
|
168
|
+
async waitForFunding(minAmount, opts) {
|
|
169
|
+
ensureCreated();
|
|
170
|
+
const interval = opts?.pollInterval ?? 1e4;
|
|
171
|
+
const deadline = opts?.timeout ? Date.now() + opts.timeout : null;
|
|
172
|
+
while (true) {
|
|
173
|
+
const balance = await getUsdcBalance(_account.address, _network, _rpcUrl);
|
|
174
|
+
if (balance >= minAmount) return;
|
|
175
|
+
if (deadline && Date.now() >= deadline) {
|
|
176
|
+
throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`);
|
|
177
|
+
}
|
|
178
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Drop-in `fetch()` replacement that handles x402 payments automatically.
|
|
183
|
+
* If the server returns 402, the library signs an EIP-3009 authorization
|
|
184
|
+
* and retries the request with payment headers.
|
|
185
|
+
*/
|
|
186
|
+
async fetch(input, init) {
|
|
187
|
+
ensureCreated();
|
|
188
|
+
if (!_paymentFetch) {
|
|
189
|
+
throw new Error("Payment layer not initialized");
|
|
190
|
+
}
|
|
191
|
+
return _paymentFetch(input, init);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/compute/index.ts
|
|
196
|
+
var DEFAULT_ENDPOINT = "https://x402.auteng.ai/api/x402/compute";
|
|
197
|
+
var _endpoint = DEFAULT_ENDPOINT;
|
|
198
|
+
var PRICING = {
|
|
199
|
+
small: {
|
|
200
|
+
vcpu: 2,
|
|
201
|
+
ram_gb: 1,
|
|
202
|
+
default_timeout_s: 30,
|
|
203
|
+
max_timeout_s: 300,
|
|
204
|
+
base_price_usd: 2e-3,
|
|
205
|
+
per_second_usd: 5e-5
|
|
206
|
+
},
|
|
207
|
+
med: {
|
|
208
|
+
vcpu: 4,
|
|
209
|
+
ram_gb: 4,
|
|
210
|
+
default_timeout_s: 60,
|
|
211
|
+
max_timeout_s: 600,
|
|
212
|
+
base_price_usd: 8e-3,
|
|
213
|
+
per_second_usd: 12e-5
|
|
214
|
+
},
|
|
215
|
+
large: {
|
|
216
|
+
vcpu: 8,
|
|
217
|
+
ram_gb: 16,
|
|
218
|
+
default_timeout_s: 120,
|
|
219
|
+
max_timeout_s: 3600,
|
|
220
|
+
base_price_usd: 0.03,
|
|
221
|
+
per_second_usd: 25e-5
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var compute = {
|
|
225
|
+
/**
|
|
226
|
+
* Execute sandboxed code via AutEng's x402 compute endpoint.
|
|
227
|
+
* Payment is handled automatically via the wallet's x402 layer.
|
|
228
|
+
*/
|
|
229
|
+
async run(request) {
|
|
230
|
+
if (!request.code) {
|
|
231
|
+
throw new Error("compute.run: 'code' is required");
|
|
232
|
+
}
|
|
233
|
+
if (!request.stack) {
|
|
234
|
+
throw new Error("compute.run: 'stack' is required");
|
|
235
|
+
}
|
|
236
|
+
const body = {
|
|
237
|
+
code: request.code,
|
|
238
|
+
stack: request.stack,
|
|
239
|
+
size: request.size ?? "small",
|
|
240
|
+
...request.timeout_seconds != null && {
|
|
241
|
+
timeout_seconds: request.timeout_seconds
|
|
242
|
+
},
|
|
243
|
+
...request.files != null && { files: request.files }
|
|
244
|
+
};
|
|
245
|
+
const response = await wallet.fetch(_endpoint, {
|
|
246
|
+
method: "POST",
|
|
247
|
+
headers: { "Content-Type": "application/json" },
|
|
248
|
+
body: JSON.stringify(body)
|
|
249
|
+
});
|
|
250
|
+
if (!response.ok) {
|
|
251
|
+
const text = await response.text().catch(() => "");
|
|
252
|
+
throw new Error(`Compute request failed (${response.status}): ${text}`);
|
|
253
|
+
}
|
|
254
|
+
return await response.json();
|
|
255
|
+
},
|
|
256
|
+
/** Returns the pricing table for all compute sizes. */
|
|
257
|
+
pricing() {
|
|
258
|
+
return { ...PRICING };
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* Override the compute endpoint URL.
|
|
262
|
+
* Default: https://x402.auteng.ai/api/x402/compute
|
|
263
|
+
*/
|
|
264
|
+
setEndpoint(url) {
|
|
265
|
+
_endpoint = url;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
compute,
|
|
271
|
+
wallet
|
|
272
|
+
});
|
|
273
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/x402/index.ts","../src/compute/index.ts"],"sourcesContent":["export { wallet } from \"./wallet/index.js\"\nexport { compute } from \"./compute/index.js\"\n\nexport type { WalletConfig, WaitForFundingOptions, Network } from \"./wallet/types.js\"\nexport type { ComputeRequest, ComputeResponse, PricingTier, Stack, Size } from \"./compute/types.js\"\n","import { resolve } from \"node:path\"\nimport type { PrivateKeyAccount } from \"viem\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile } from \"./storage.js\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport type { Network, WalletConfig, WaitForFundingOptions } from \"./types.js\"\n\n// --- Internal state ---\n\nlet _account: PrivateKeyAccount | null = null\nlet _privateKey: `0x${string}` | null = null\nlet _network: Network = \"base\"\nlet _rpcUrl: string | undefined\nlet _paymentFetch: typeof globalThis.fetch | null = null\n\nfunction ensureCreated(): void {\n if (!_account) {\n throw new Error(\"Wallet not initialized. Call wallet.create() first.\")\n }\n}\n\n// --- Public API ---\n\nexport const wallet = {\n /**\n * Create a new EVM wallet or load an existing one from disk.\n * Idempotent: if the wallet file already exists, loads it.\n */\n async create(opts?: WalletConfig): Promise<void> {\n const keyPath = resolve(opts?.keyPath ?? \".auteng/wallet.json\")\n _network = opts?.network ?? \"base\"\n _rpcUrl = opts?.rpcUrl\n\n const existing = readWalletFile(keyPath)\n if (existing) {\n _privateKey = existing.privateKey\n const { account } = loadKeypair(existing.privateKey)\n _account = account\n _network = existing.network\n } else {\n const { privateKey, account } = createKeypair()\n _privateKey = privateKey\n _account = account\n writeWalletFile(keyPath, {\n privateKey,\n address: account.address,\n network: _network,\n })\n }\n\n _paymentFetch = createPaymentFetch(_privateKey!, _network, _rpcUrl)\n },\n\n /** The wallet's public address. Throws if not created. */\n get address(): `0x${string}` {\n ensureCreated()\n return _account!.address\n },\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n ensureCreated()\n return getUsdcBalance(_account!.address, _network, _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 ensureCreated()\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(_account!.address, _network, _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 ensureCreated()\n if (!_paymentFetch) {\n throw new Error(\"Payment layer not initialized\")\n }\n return _paymentFetch(input, init)\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 } from \"node:fs\"\nimport { dirname } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\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","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface WalletConfig {\n /** Path to store the wallet keypair. Default: `.auteng/wallet.json` */\n keyPath?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n}\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 { 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","import { wallet } from \"../wallet/index.js\"\nimport 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 const response = await 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;;;ACAA,IAAAA,oBAAwB;;;ACAxB,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;AAC9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from "path";
|
|
3
|
+
|
|
4
|
+
// src/wallet/keypair.ts
|
|
5
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
6
|
+
function createKeypair() {
|
|
7
|
+
const privateKey = generatePrivateKey();
|
|
8
|
+
const account = privateKeyToAccount(privateKey);
|
|
9
|
+
return { privateKey, account };
|
|
10
|
+
}
|
|
11
|
+
function loadKeypair(privateKey) {
|
|
12
|
+
const account = privateKeyToAccount(privateKey);
|
|
13
|
+
return { account };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/wallet/storage.ts
|
|
17
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from "fs";
|
|
18
|
+
import { dirname } from "path";
|
|
19
|
+
function readWalletFile(path) {
|
|
20
|
+
if (!existsSync(path)) return null;
|
|
21
|
+
const raw = readFileSync(path, "utf-8");
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
function writeWalletFile(path, data) {
|
|
25
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
26
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", {
|
|
27
|
+
mode: 384
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/wallet/types.ts
|
|
32
|
+
var NETWORK_CONFIG = {
|
|
33
|
+
base: {
|
|
34
|
+
chainId: 8453,
|
|
35
|
+
usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
36
|
+
rpcUrl: "https://mainnet.base.org"
|
|
37
|
+
},
|
|
38
|
+
"base-sepolia": {
|
|
39
|
+
chainId: 84532,
|
|
40
|
+
usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
41
|
+
rpcUrl: "https://sepolia.base.org"
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/wallet/balance.ts
|
|
46
|
+
async function getUsdcBalance(address, network, rpcUrl) {
|
|
47
|
+
const config = NETWORK_CONFIG[network];
|
|
48
|
+
const url = rpcUrl ?? config.rpcUrl;
|
|
49
|
+
const paddedAddress = address.slice(2).toLowerCase().padStart(64, "0");
|
|
50
|
+
const data = `0x70a08231${paddedAddress}`;
|
|
51
|
+
const res = await fetch(url, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
jsonrpc: "2.0",
|
|
56
|
+
id: 1,
|
|
57
|
+
method: "eth_call",
|
|
58
|
+
params: [{ to: config.usdcAddress, data }, "latest"]
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
const json = await res.json();
|
|
62
|
+
if (json.error) {
|
|
63
|
+
throw new Error(`RPC error: ${JSON.stringify(json.error)}`);
|
|
64
|
+
}
|
|
65
|
+
return BigInt(json.result ?? "0x0");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/x402/index.ts
|
|
69
|
+
import { x402Client } from "@x402/core/client";
|
|
70
|
+
import { registerExactEvmScheme } from "@x402/evm/exact/client";
|
|
71
|
+
import { toClientEvmSigner } from "@x402/evm";
|
|
72
|
+
import { wrapFetchWithPayment } from "@x402/fetch";
|
|
73
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
74
|
+
import { createPublicClient, http } from "viem";
|
|
75
|
+
import { base, baseSepolia } from "viem/chains";
|
|
76
|
+
function createPaymentFetch(privateKey, network = "base", rpcUrl) {
|
|
77
|
+
const account = privateKeyToAccount2(privateKey);
|
|
78
|
+
const chain = network === "base" ? base : baseSepolia;
|
|
79
|
+
const publicClient = createPublicClient({
|
|
80
|
+
chain,
|
|
81
|
+
transport: http(rpcUrl)
|
|
82
|
+
});
|
|
83
|
+
const signer = toClientEvmSigner(account, publicClient);
|
|
84
|
+
const client = new x402Client();
|
|
85
|
+
registerExactEvmScheme(client, { signer });
|
|
86
|
+
return wrapFetchWithPayment(fetch, client);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/wallet/index.ts
|
|
90
|
+
var _account = null;
|
|
91
|
+
var _privateKey = null;
|
|
92
|
+
var _network = "base";
|
|
93
|
+
var _rpcUrl;
|
|
94
|
+
var _paymentFetch = null;
|
|
95
|
+
function ensureCreated() {
|
|
96
|
+
if (!_account) {
|
|
97
|
+
throw new Error("Wallet not initialized. Call wallet.create() first.");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
var wallet = {
|
|
101
|
+
/**
|
|
102
|
+
* Create a new EVM wallet or load an existing one from disk.
|
|
103
|
+
* Idempotent: if the wallet file already exists, loads it.
|
|
104
|
+
*/
|
|
105
|
+
async create(opts) {
|
|
106
|
+
const keyPath = resolve(opts?.keyPath ?? ".auteng/wallet.json");
|
|
107
|
+
_network = opts?.network ?? "base";
|
|
108
|
+
_rpcUrl = opts?.rpcUrl;
|
|
109
|
+
const existing = readWalletFile(keyPath);
|
|
110
|
+
if (existing) {
|
|
111
|
+
_privateKey = existing.privateKey;
|
|
112
|
+
const { account } = loadKeypair(existing.privateKey);
|
|
113
|
+
_account = account;
|
|
114
|
+
_network = existing.network;
|
|
115
|
+
} else {
|
|
116
|
+
const { privateKey, account } = createKeypair();
|
|
117
|
+
_privateKey = privateKey;
|
|
118
|
+
_account = account;
|
|
119
|
+
writeWalletFile(keyPath, {
|
|
120
|
+
privateKey,
|
|
121
|
+
address: account.address,
|
|
122
|
+
network: _network
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
_paymentFetch = createPaymentFetch(_privateKey, _network, _rpcUrl);
|
|
126
|
+
},
|
|
127
|
+
/** The wallet's public address. Throws if not created. */
|
|
128
|
+
get address() {
|
|
129
|
+
ensureCreated();
|
|
130
|
+
return _account.address;
|
|
131
|
+
},
|
|
132
|
+
/** Check USDC balance on Base. Returns balance in minor units (6 decimals). */
|
|
133
|
+
async checkBalance() {
|
|
134
|
+
ensureCreated();
|
|
135
|
+
return getUsdcBalance(_account.address, _network, _rpcUrl);
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* Poll until USDC balance >= minAmount.
|
|
139
|
+
* @param minAmount - minimum USDC balance in minor units (6 decimals)
|
|
140
|
+
*/
|
|
141
|
+
async waitForFunding(minAmount, opts) {
|
|
142
|
+
ensureCreated();
|
|
143
|
+
const interval = opts?.pollInterval ?? 1e4;
|
|
144
|
+
const deadline = opts?.timeout ? Date.now() + opts.timeout : null;
|
|
145
|
+
while (true) {
|
|
146
|
+
const balance = await getUsdcBalance(_account.address, _network, _rpcUrl);
|
|
147
|
+
if (balance >= minAmount) return;
|
|
148
|
+
if (deadline && Date.now() >= deadline) {
|
|
149
|
+
throw new Error(`Funding timeout: balance ${balance} < required ${minAmount}`);
|
|
150
|
+
}
|
|
151
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Drop-in `fetch()` replacement that handles x402 payments automatically.
|
|
156
|
+
* If the server returns 402, the library signs an EIP-3009 authorization
|
|
157
|
+
* and retries the request with payment headers.
|
|
158
|
+
*/
|
|
159
|
+
async fetch(input, init) {
|
|
160
|
+
ensureCreated();
|
|
161
|
+
if (!_paymentFetch) {
|
|
162
|
+
throw new Error("Payment layer not initialized");
|
|
163
|
+
}
|
|
164
|
+
return _paymentFetch(input, init);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/compute/index.ts
|
|
169
|
+
var DEFAULT_ENDPOINT = "https://x402.auteng.ai/api/x402/compute";
|
|
170
|
+
var _endpoint = DEFAULT_ENDPOINT;
|
|
171
|
+
var PRICING = {
|
|
172
|
+
small: {
|
|
173
|
+
vcpu: 2,
|
|
174
|
+
ram_gb: 1,
|
|
175
|
+
default_timeout_s: 30,
|
|
176
|
+
max_timeout_s: 300,
|
|
177
|
+
base_price_usd: 2e-3,
|
|
178
|
+
per_second_usd: 5e-5
|
|
179
|
+
},
|
|
180
|
+
med: {
|
|
181
|
+
vcpu: 4,
|
|
182
|
+
ram_gb: 4,
|
|
183
|
+
default_timeout_s: 60,
|
|
184
|
+
max_timeout_s: 600,
|
|
185
|
+
base_price_usd: 8e-3,
|
|
186
|
+
per_second_usd: 12e-5
|
|
187
|
+
},
|
|
188
|
+
large: {
|
|
189
|
+
vcpu: 8,
|
|
190
|
+
ram_gb: 16,
|
|
191
|
+
default_timeout_s: 120,
|
|
192
|
+
max_timeout_s: 3600,
|
|
193
|
+
base_price_usd: 0.03,
|
|
194
|
+
per_second_usd: 25e-5
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var compute = {
|
|
198
|
+
/**
|
|
199
|
+
* Execute sandboxed code via AutEng's x402 compute endpoint.
|
|
200
|
+
* Payment is handled automatically via the wallet's x402 layer.
|
|
201
|
+
*/
|
|
202
|
+
async run(request) {
|
|
203
|
+
if (!request.code) {
|
|
204
|
+
throw new Error("compute.run: 'code' is required");
|
|
205
|
+
}
|
|
206
|
+
if (!request.stack) {
|
|
207
|
+
throw new Error("compute.run: 'stack' is required");
|
|
208
|
+
}
|
|
209
|
+
const body = {
|
|
210
|
+
code: request.code,
|
|
211
|
+
stack: request.stack,
|
|
212
|
+
size: request.size ?? "small",
|
|
213
|
+
...request.timeout_seconds != null && {
|
|
214
|
+
timeout_seconds: request.timeout_seconds
|
|
215
|
+
},
|
|
216
|
+
...request.files != null && { files: request.files }
|
|
217
|
+
};
|
|
218
|
+
const response = await wallet.fetch(_endpoint, {
|
|
219
|
+
method: "POST",
|
|
220
|
+
headers: { "Content-Type": "application/json" },
|
|
221
|
+
body: JSON.stringify(body)
|
|
222
|
+
});
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
const text = await response.text().catch(() => "");
|
|
225
|
+
throw new Error(`Compute request failed (${response.status}): ${text}`);
|
|
226
|
+
}
|
|
227
|
+
return await response.json();
|
|
228
|
+
},
|
|
229
|
+
/** Returns the pricing table for all compute sizes. */
|
|
230
|
+
pricing() {
|
|
231
|
+
return { ...PRICING };
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Override the compute endpoint URL.
|
|
235
|
+
* Default: https://x402.auteng.ai/api/x402/compute
|
|
236
|
+
*/
|
|
237
|
+
setEndpoint(url) {
|
|
238
|
+
_endpoint = url;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
export {
|
|
242
|
+
compute,
|
|
243
|
+
wallet
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/wallet/index.ts","../src/wallet/keypair.ts","../src/wallet/storage.ts","../src/wallet/types.ts","../src/wallet/balance.ts","../src/x402/index.ts","../src/compute/index.ts"],"sourcesContent":["import { resolve } from \"node:path\"\nimport type { PrivateKeyAccount } from \"viem\"\nimport { createKeypair, loadKeypair } from \"./keypair.js\"\nimport { readWalletFile, writeWalletFile } from \"./storage.js\"\nimport { getUsdcBalance } from \"./balance.js\"\nimport { createPaymentFetch } from \"../x402/index.js\"\nimport type { Network, WalletConfig, WaitForFundingOptions } from \"./types.js\"\n\n// --- Internal state ---\n\nlet _account: PrivateKeyAccount | null = null\nlet _privateKey: `0x${string}` | null = null\nlet _network: Network = \"base\"\nlet _rpcUrl: string | undefined\nlet _paymentFetch: typeof globalThis.fetch | null = null\n\nfunction ensureCreated(): void {\n if (!_account) {\n throw new Error(\"Wallet not initialized. Call wallet.create() first.\")\n }\n}\n\n// --- Public API ---\n\nexport const wallet = {\n /**\n * Create a new EVM wallet or load an existing one from disk.\n * Idempotent: if the wallet file already exists, loads it.\n */\n async create(opts?: WalletConfig): Promise<void> {\n const keyPath = resolve(opts?.keyPath ?? \".auteng/wallet.json\")\n _network = opts?.network ?? \"base\"\n _rpcUrl = opts?.rpcUrl\n\n const existing = readWalletFile(keyPath)\n if (existing) {\n _privateKey = existing.privateKey\n const { account } = loadKeypair(existing.privateKey)\n _account = account\n _network = existing.network\n } else {\n const { privateKey, account } = createKeypair()\n _privateKey = privateKey\n _account = account\n writeWalletFile(keyPath, {\n privateKey,\n address: account.address,\n network: _network,\n })\n }\n\n _paymentFetch = createPaymentFetch(_privateKey!, _network, _rpcUrl)\n },\n\n /** The wallet's public address. Throws if not created. */\n get address(): `0x${string}` {\n ensureCreated()\n return _account!.address\n },\n\n /** Check USDC balance on Base. Returns balance in minor units (6 decimals). */\n async checkBalance(): Promise<bigint> {\n ensureCreated()\n return getUsdcBalance(_account!.address, _network, _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 ensureCreated()\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(_account!.address, _network, _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 ensureCreated()\n if (!_paymentFetch) {\n throw new Error(\"Payment layer not initialized\")\n }\n return _paymentFetch(input, init)\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 } from \"node:fs\"\nimport { dirname } from \"node:path\"\nimport type { WalletFile } from \"./types.js\"\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","export type Network = \"base\" | \"base-sepolia\"\n\nexport interface WalletConfig {\n /** Path to store the wallet keypair. Default: `.auteng/wallet.json` */\n keyPath?: string\n /** Network to use. Default: `base` */\n network?: Network\n /** Custom RPC endpoint. Default: public Base RPC */\n rpcUrl?: string\n}\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 { 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","import { wallet } from \"../wallet/index.js\"\nimport 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 const response = await 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,eAAe;;;ACAxB,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,kBAAkB;AACnE,SAAS,eAAe;AAGjB,SAAS,eAAe,MAAiC;AAC9D,MAAI,CAAC,WAAW,IAAI,EAAG,QAAO;AAC9B,QAAM,MAAM,aAAa,MAAM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O,IAAM,UAAU;AAAA;AAAA;AAAA;AAAA;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,UAAM,WAAW,MAAM,OAAO,MAAM,WAAW;AAAA,MAC7C,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":["privateKeyToAccount"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@auteng/agent-utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Utility belt for autonomous AI agents — wallet, compute, and more",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"clean": "rimraf dist"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"viem": "^2.39.0",
|
|
25
|
+
"@x402/core": "^2.2.0",
|
|
26
|
+
"@x402/evm": "^2.2.0",
|
|
27
|
+
"@x402/fetch": "^2.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.4.5",
|
|
32
|
+
"rimraf": "^5.0.10",
|
|
33
|
+
"@types/node": "^20.0.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
}
|