@bananalink-test/agent-wallet 0.1.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/dist/index.mjs +13 -21
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { createConnection, createServer } from "node:net";
|
|
6
|
-
import {
|
|
6
|
+
import { BananalinkAgent, ConnectionRejectedError, ConnectionTimeoutError, RequestRejectedError, RequestTimeoutError, SessionClosedError } from "@bananalink-test/agent";
|
|
7
7
|
import { parseUnits } from "viem";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
@@ -118,7 +118,7 @@ const SESSION_FILE = join(CONFIG_DIR, "session.json");
|
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/schemas/StoredSessionSchema.ts
|
|
120
120
|
const StoredSessionSchema = z.object({
|
|
121
|
-
|
|
121
|
+
agentId: z.string(),
|
|
122
122
|
accessToken: z.string().optional()
|
|
123
123
|
});
|
|
124
124
|
|
|
@@ -146,15 +146,10 @@ function saveSession(s) {
|
|
|
146
146
|
|
|
147
147
|
//#endregion
|
|
148
148
|
//#region src/daemon/runDaemon.ts
|
|
149
|
-
function
|
|
149
|
+
function makeAgent(agentId) {
|
|
150
150
|
return {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
dappStatement: "An AI agent wants to send transactions on your behalf.",
|
|
154
|
-
domain: "ai.agent",
|
|
155
|
-
uri: "ai://agent",
|
|
156
|
-
icons: [],
|
|
157
|
-
chainId: 1
|
|
151
|
+
agentId,
|
|
152
|
+
agentName: "AI Agent"
|
|
158
153
|
};
|
|
159
154
|
}
|
|
160
155
|
function serveSession(session) {
|
|
@@ -184,8 +179,7 @@ function serveSession(session) {
|
|
|
184
179
|
case "status":
|
|
185
180
|
response = {
|
|
186
181
|
ok: true,
|
|
187
|
-
connected: true
|
|
188
|
-
address: session.sessionClaims.address
|
|
182
|
+
connected: true
|
|
189
183
|
};
|
|
190
184
|
break;
|
|
191
185
|
case "send": {
|
|
@@ -212,7 +206,7 @@ function serveSession(session) {
|
|
|
212
206
|
}
|
|
213
207
|
case "disconnect": {
|
|
214
208
|
const stored = loadSession();
|
|
215
|
-
if (stored) saveSession({
|
|
209
|
+
if (stored) saveSession({ agentId: stored.agentId });
|
|
216
210
|
response = { ok: true };
|
|
217
211
|
socket.write(`${JSON.stringify(response)}\n`);
|
|
218
212
|
socket.end();
|
|
@@ -241,8 +235,8 @@ async function runDaemon() {
|
|
|
241
235
|
if (err.code !== "EPIPE") throw err;
|
|
242
236
|
});
|
|
243
237
|
const stored = loadSession();
|
|
244
|
-
const
|
|
245
|
-
const connection = await new
|
|
238
|
+
const agentId = stored?.agentId ?? crypto.randomUUID();
|
|
239
|
+
const connection = await new BananalinkAgent({ agent: makeAgent(agentId) }).connect(stored?.accessToken ? { accessToken: stored.accessToken } : void 0);
|
|
246
240
|
if (!stored?.accessToken) {
|
|
247
241
|
emit({
|
|
248
242
|
type: "pending",
|
|
@@ -252,7 +246,7 @@ async function runDaemon() {
|
|
|
252
246
|
}
|
|
253
247
|
const session = await connection.getSession();
|
|
254
248
|
saveSession({
|
|
255
|
-
|
|
249
|
+
agentId,
|
|
256
250
|
accessToken: session.sessionClaims.accessToken
|
|
257
251
|
});
|
|
258
252
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
@@ -261,8 +255,7 @@ async function runDaemon() {
|
|
|
261
255
|
writeFileSync(PID_FILE, String(process.pid), { mode: 384 });
|
|
262
256
|
emit({
|
|
263
257
|
type: "connected",
|
|
264
|
-
ok: true
|
|
265
|
-
address: session.sessionClaims.address
|
|
258
|
+
ok: true
|
|
266
259
|
});
|
|
267
260
|
}
|
|
268
261
|
|
|
@@ -297,8 +290,7 @@ const SendResponseSchema = z.object({
|
|
|
297
290
|
//#region src/schemas/StatusResponseSchema.ts
|
|
298
291
|
const StatusResponseSchema = z.object({
|
|
299
292
|
ok: z.literal(true),
|
|
300
|
-
connected: z.literal(true)
|
|
301
|
-
address: z.string()
|
|
293
|
+
connected: z.literal(true)
|
|
302
294
|
});
|
|
303
295
|
|
|
304
296
|
//#endregion
|
|
@@ -440,7 +432,7 @@ async function cmdDisconnect() {
|
|
|
440
432
|
if (isDaemonRunning()) await callDaemon({ cmd: "disconnect" });
|
|
441
433
|
else {
|
|
442
434
|
const stored = loadSession();
|
|
443
|
-
if (stored) saveSession({
|
|
435
|
+
if (stored) saveSession({ agentId: stored.agentId });
|
|
444
436
|
}
|
|
445
437
|
emit({ ok: true });
|
|
446
438
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananalink-test/agent-wallet",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "CLI tool that gives AI agents onchain transaction capabilities via a Bananalink wallet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"commander": "^14.0.3",
|
|
26
26
|
"viem": "^2.47.2",
|
|
27
27
|
"zod": "^4.3.6",
|
|
28
|
-
"@bananalink-test/
|
|
28
|
+
"@bananalink-test/agent": "1.0.1"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"start": "tsx src/index.ts",
|