From 0bc127e260e512a8f4f53fe025608d5200c5645d Mon Sep 17 00:00:00 2001 From: gene-sf Date: Sun, 22 Dec 2024 17:20:29 +0800 Subject: [PATCH 1/9] feat: add tee verifiable log plugin and apis --- .env.example | 4 + agent/package.json | 1 + agent/src/index.ts | 4 + characters/trump.character.json | 2 +- packages/client-direct/package.json | 57 ++--- packages/client-direct/src/README.md | 128 +++++++++++ packages/client-direct/src/index.ts | 6 + .../client-direct/src/verifiable-log-api.ts | 119 ++++++++++ packages/core/src/types.ts | 1 + packages/plugin-tee-verifiable-log/.npmignore | 6 + packages/plugin-tee-verifiable-log/README.md | 35 +++ .../eslint.config.mjs | 3 + .../plugin-tee-verifiable-log/package.json | 31 +++ .../src/adapters/sqliteVerifiableDAO.ts | 209 ++++++++++++++++++ .../plugin-tee-verifiable-log/src/index.ts | 107 +++++++++ .../src/providers/verifiableLogProvider.ts | 113 ++++++++++ .../src/test/providers.test.ts | 160 ++++++++++++++ .../src/types/logTypes.ts | 126 +++++++++++ .../plugin-tee-verifiable-log/tsconfig.json | 10 + .../plugin-tee-verifiable-log/tsup.config.ts | 10 + pnpm-lock.yaml | 103 +++++++-- turbo.json | 4 + 22 files changed, 1189 insertions(+), 50 deletions(-) create mode 100644 packages/client-direct/src/verifiable-log-api.ts create mode 100644 packages/plugin-tee-verifiable-log/.npmignore create mode 100644 packages/plugin-tee-verifiable-log/README.md create mode 100644 packages/plugin-tee-verifiable-log/eslint.config.mjs create mode 100644 packages/plugin-tee-verifiable-log/package.json create mode 100644 packages/plugin-tee-verifiable-log/src/adapters/sqliteVerifiableDAO.ts create mode 100644 packages/plugin-tee-verifiable-log/src/index.ts create mode 100644 packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts create mode 100644 packages/plugin-tee-verifiable-log/src/test/providers.test.ts create mode 100644 packages/plugin-tee-verifiable-log/src/types/logTypes.ts create mode 100644 packages/plugin-tee-verifiable-log/tsconfig.json create mode 100644 packages/plugin-tee-verifiable-log/tsup.config.ts diff --git a/.env.example b/.env.example index b1f05998b7..7bf811f3aa 100644 --- a/.env.example +++ b/.env.example @@ -244,6 +244,10 @@ ZEROG_FLOW_ADDRESS= TEE_MODE=OFF # LOCAL | DOCKER | PRODUCTION WALLET_SECRET_SALT= # ONLY define if you want to use TEE Plugin, otherwise it will throw errors + +# TEE Verifiable Log Configuration +VLOG= # true/false; if you want to use TEE Verifiable Log, set this to "true" + # Galadriel Configuration GALADRIEL_API_KEY=gal-* # Get from https://dashboard.galadriel.com/ diff --git a/agent/package.json b/agent/package.json index 91a900d600..f34d0bbf69 100644 --- a/agent/package.json +++ b/agent/package.json @@ -51,6 +51,7 @@ "@elizaos/plugin-multiversx": "workspace:*", "@elizaos/plugin-near": "workspace:*", "@elizaos/plugin-zksync-era": "workspace:*", + "@elizaos/plugin-tee-verifiable-log": "workspace:*", "readline": "1.3.0", "ws": "8.18.0", "yargs": "17.7.2" diff --git a/agent/src/index.ts b/agent/src/index.ts index 1e49bae84f..4194c4dc07 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -55,6 +55,7 @@ import { suiPlugin } from "@elizaos/plugin-sui"; import { TEEMode, teePlugin } from "@elizaos/plugin-tee"; import { tonPlugin } from "@elizaos/plugin-ton"; import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era"; +import { verifiableLogPlugin } from "@elizaos/plugin-tee-verifiable-log"; import Database from "better-sqlite3"; import fs from "fs"; import path from "path"; @@ -571,6 +572,9 @@ export async function createAgent( getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null, getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null, getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null, + (teeMode !== TEEMode.OFF && walletSecretSalt &&getSecret(character,"VLOG") + ? verifiableLogPlugin + : null) ].filter(Boolean), providers: [], actions: [], diff --git a/characters/trump.character.json b/characters/trump.character.json index 66329e2d7c..80b93e4ecf 100644 --- a/characters/trump.character.json +++ b/characters/trump.character.json @@ -1,7 +1,7 @@ { "name": "trump", "clients": [], - "modelProvider": "openai", + "modelProvider": "ollama", "settings": { "secrets": {}, "voice": { diff --git a/packages/client-direct/package.json b/packages/client-direct/package.json index fe3f4c7afb..35061fc285 100644 --- a/packages/client-direct/package.json +++ b/packages/client-direct/package.json @@ -1,30 +1,31 @@ { - "name": "@elizaos/client-direct", - "version": "0.1.7-alpha.1", - "main": "dist/index.js", - "type": "module", - "types": "dist/index.d.ts", - "dependencies": { - "@elizaos/core": "workspace:*", - "@elizaos/plugin-image-generation": "workspace:*", - "@types/body-parser": "1.19.5", - "@types/cors": "2.8.17", - "@types/express": "5.0.0", - "body-parser": "1.20.3", - "cors": "2.8.5", - "discord.js": "14.16.3", - "express": "4.21.1", - "multer": "1.4.5-lts.1" - }, - "devDependencies": { - "tsup": "8.3.5" - }, - "scripts": { - "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch", - "lint": "eslint --fix --cache ." - }, - "peerDependencies": { - "whatwg-url": "7.1.0" - } + "name": "@elizaos/client-direct", + "version": "0.1.7-alpha.1", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@elizaos/core": "workspace:*", + "@elizaos/plugin-image-generation": "workspace:*", + "@elizaos/plugin-tee-verifiable-log": "workspace:*", + "@types/body-parser": "1.19.5", + "@types/cors": "2.8.17", + "@types/express": "5.0.0", + "body-parser": "1.20.3", + "cors": "2.8.5", + "discord.js": "14.16.3", + "express": "4.21.1", + "multer": "1.4.5-lts.1" + }, + "devDependencies": { + "tsup": "8.3.5" + }, + "scripts": { + "build": "tsup --format esm --dts", + "dev": "tsup --format esm --dts --watch", + "lint": "eslint --fix --cache ." + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } } diff --git a/packages/client-direct/src/README.md b/packages/client-direct/src/README.md index 7377eab6f3..6e4bf1e1c8 100644 --- a/packages/client-direct/src/README.md +++ b/packages/client-direct/src/README.md @@ -43,3 +43,131 @@ curl -X GET "http://localhost:3000/fine-tune/8566c47a-ada8-441c-95bc-7bb07656c4c -H "Content-Type: application/json" \ -H "Authorization: Bearer jvBpxrTNqGqhnfQhSEqCdsG6aTSP8IBL". ``` + + + +## Verifiable Attestations + +This function relies on [plugin-tee-verifiable-log](../../plugin-tee-verifiable-log/README.md) + +Enable Verifiable Logs, Configuration variables in .env +```shell +TEE_MODE="DOCKER" # LOCAL | DOCKER | PRODUCTION +WALLET_SECRET_SALT= "" # ONLY define if you want to use TEE Plugin, otherwise it will throw errors +VLOG="true" +``` +### APIs +### 1. Get verifiable agents +```shell +curl -X GET --location "http://localhost:3000/verifiable/agents" +``` +* Response success result +```shell +{ + "success": true, + "message": "Successfully get Agents", + "data": [ + { + "id": "c4598810-61a2-4ac8-ab85-b746402692c4", + "created_at": 1734526797906, + "agent_id": "9c321604-e69e-0e4c-ab84-bec6fd6baf92", + "agent_name": "Capila", + "agent_keypair_path": "/keys/verifiable_key", + "agent_keypair_vlog_pk": "0x045b51a28c3b071104f3094b1934343eb831b8d56f16fc6..." + } + ] +} +``` +* Response failure result +```shell +{ + "error": "failed to get agents registered ", + "details": "Cannot read properties of undefined (reading 'getService')", + "stack": "TypeError: Cannot read ..." +} +``` + +### 2.Query verifiable logs +```bash + +curl -X POST --location "http://localhost:3000/verifiable/logs" \ + -H "Content-Type: application/json" \ + -d '{ + "query": { + "contLike": "Twinkletwinkle" + }, + "page": 1, + "pageSize": 10 + }' +``` +The query body that can be queried are: +>* idEq: string; +>* agentIdEq: string; +>* roomIdEq: string; +>* userIdEq: string; +>* typeEq: string; +>* contLike: string; +>* signatureEq: string; + +* Response success result +```shell +{ + "success": true, + "message": "Successfully retrieved logs", + "data": { + "page": 1, + "pageSize": 10, + "total": 1, + "data": [ + { + "id": "b9ac4b2f-ecb5-4c5c-a981-d282b831e878", + "created_at": 1734526805664, + "agent_id": "9c321604-e69e-0e4c-ab84-bec6fd6baf92", + "room_id": "8c54580d-2c56-01e8-81e4-4160a02f3ee5", + "user_id": "9c321604-e69e-0e4c-ab84-bec6fd6baf92", + "type": "post tweet", + "content": "{\"text\":\"Twinkletwinkle, it's time to unlock your artistic values!\\n\\n My NFTs are here to bring the chill vibes to Web3.\\n\\n Let's wagmi and make this a day to remember!\",\"url\":\"https://twitter.com/....\"}", + "signature": "0x9ac77cfef9374bff3b41f96d0b0a8d61bfcf88e3a01f7bc20653494145ff31ef118a2a3cd94437481000a13500c6ed6714d8802bf2572a7da4de2e81a688d0b41c" + } + ] + } +} +``` +* Response failure result +```shell + +{ + "error": "Failed to Get Verifiable Logs", + "details": "Cannot read properties of undefined (reading 'getService')", + "stack": "TypeError: Cannot read ..." +} +``` + + +### 3.Get Tee Attestation +```shell +curl -X POST --location "http://localhost:3000/verifiable/attestation" \ + -H "Content-Type: application/json" \ + -d '{ + "agentId": "9c321604-e69e-0e4c-ab84-bec6fd6baf92", + "publicKey": "0x045b51a28c3b071104f3094b1934343eb831b8d56f16fc6e9a3304e9f051b24e584d806b20769b05eeade3a6c792db96f57b26cc38037907dd920e9be9f41f6184" + }' +``` +* Response success result +```shell +{ + "success": true, + "message": "Successfully get Attestation", + "data": "{\"quote\":\"0x04000300810000000e934d64208ed62112d13060cf062a398f78a9516b9f884ee7ad145e875b59592b09598ce02e4d4983ae4decab71f5147acd16a26326e01075a8d5b709727224bba449c9cd7fc2b490ea23d9e01cd932221d8b86a0a8a7be25c25571bceef0427131860fe0cb295b0d25e5ed1488d9a122c24ba4c1494c2a2578535c556752850c6bbd60c2482b5bb10b5157fe5f42b637457262fd4d8a92575b307f5453c1982a841b46cd60858a3f8ced7ca2ba1c02cf9fec3f23b30bbe8e30378e116bea58b4068bf0379964b6adcb2f680f4646b26a21bed6f8ac06f468cc356db0b2769638a02a7d6e0b69ae297304c62a1fd800703e8bfd340901b6ad412d9433eee04b67ab86311ebb4ee2f3a758ea3fda0e89f45c7ec9ca28e2d525fab6d3e62c3e2b6788dd9dec6e367975c0ac5f6c2aad436e14c75dd99a94c51d882efc0ea44ca8c251e3384b24a88af39ab070b65387ee5e0fd11212852663248c6f24a646c163273348ea03f99d028022b08e09b0b992d9b49c61246b298c3ec827af4973a57bc017a35e0f22750922f2cae660ed70797695c5c65104339f912e1da35a7c625e5fa470764228efe80309762e33ea295b8fd6bae7ef9e7f9a4210deaac322d26acf4e003aded3099c90d6f5c1caa6fb9d84e4f70da3ea1fbfd76c2c7bb544375f566a5182e142da67718a4db7b373ff7e8b4e14bf5a752c5cf88002555020a2a4938978849c1774810456a8fe89769a595676eb0fdadda83540d353efdd40a3efcfb80283abc942e9348d3fe04109fd9999ed6fae17b5d8de88dcd80e5d57cd576ffb7a21780bd6064b4e61f83d1ff1088e836f2a8aa4cdee685aa02303cb809a6e45997532d372b5b519d3ae03f08cb162020000f5672ea83d7b1e145824622fea621381d7b6a110b1b0fdda4e4e2c3565431d099e74829267a01345a2780d0387173419e23bdb72ea57294c696e14ac8198e0967e30dc93a361465d109c1a54f47c117adcba95fdc2cecbd2b35ba3fc7443d80f56e16499d4a85ae2970428848487f963c9366898b34ebbb349dc162d2127f2800000dc010000149f9a1f60ae565575037121aac4f9a10cf6d6e884df2aac1c2bb83f8cad17d0d27f7d4264bdb78a9fe056aba38ff666b22642a9471f351f04afa7ad727f80a1ecab742174c46b33f034fc43cdef08afde65b93aeb94db20b705b379407e50a648db3a3f5958ac29f9bcc32a46a3ea36be27bc049a1409e8543467926afce68eed7488c7120ff3bd6d79c61078111d285e13fc365c82da04469a77101e067bc24f0c4fd27c361430292b8af92f07ac2687532e36377a9c67fa65a17a1dedba2aabac079d3ee691fcdf3e10bf7a479ee58e27085f5ac700a2252899cd88ba13ab00b1cf12cbfca3bcdacaf870e904191bdf2e7426c86b092380fbb523086c294aaf64f3931c96ec7292e4a0aee03f4b0f0eb757d1dc96c7fd07dcad6d51622060e5db55cae0c45aab399caa785665302fff467b1caa98e4ef2bac9a02911388a44b69cf7f21bf3c2ce2da95f323ea3717eddfe97f486beb90dc7ff88377211dd8a89d2b77d044fae1423904839ad8b4662d8df7a414c9aec2c234c0df878093fc31714d2fee3c400cfbee9df0ee82df7d7361d53a7ce91b01e80d3dc9702eebb8dafa1cb3e2a5032fd64ded06e5f1bacd9c275604cedabbea82cec2cfa32384790a000000000000000000000078c50a00000000000000000000000000\",\"timestamp\":1734626127589}" +} +``` + +* Response failure result +```shell + +{ + "error": "Failed to Get Verifiable Logs", + "details": "Cannot read properties of undefined (reading 'getService')", + "stack": "TypeError: Cannot read ..." +} +``` diff --git a/packages/client-direct/src/index.ts b/packages/client-direct/src/index.ts index 11ee361568..7a2f1222ca 100644 --- a/packages/client-direct/src/index.ts +++ b/packages/client-direct/src/index.ts @@ -19,6 +19,8 @@ import { settings } from "@elizaos/core"; import { createApiRouter } from "./api.ts"; import * as fs from "fs"; import * as path from "path"; +import { createVerifiableLogApiRouter } from "./verifiable-log-api.ts"; + const upload = multer({ storage: multer.memoryStorage() }); export const messageHandlerTemplate = @@ -69,6 +71,10 @@ export class DirectClient { const apiRouter = createApiRouter(this.agents, this); this.app.use(apiRouter); + + const apiLogRouter = createVerifiableLogApiRouter(this.agents, this); + this.app.use(apiLogRouter); + // Define an interface that extends the Express Request interface interface CustomRequest extends ExpressRequest { file: File; diff --git a/packages/client-direct/src/verifiable-log-api.ts b/packages/client-direct/src/verifiable-log-api.ts new file mode 100644 index 0000000000..dd0054029f --- /dev/null +++ b/packages/client-direct/src/verifiable-log-api.ts @@ -0,0 +1,119 @@ +import express from "express"; +import bodyParser from "body-parser"; +import cors from "cors"; + +import { AgentRuntime, elizaLogger, ServiceType } from "@elizaos/core"; +import { + VerifiableLogService, + VerifiableLogQuery, +} from "@elizaos/plugin-tee-verifiable-log"; + +export function createVerifiableLogApiRouter( + agents: Map +) { + const router = express.Router(); + router.use(cors()); + router.use(bodyParser.json()); + router.use(bodyParser.urlencoded({ extended: true })); + + router.get( + "/verifiable/agents", + async (req: express.Request, res: express.Response) => { + try { + // call the listAgent method + const agentRuntime: AgentRuntime | undefined = agents.values().next().value; + const pageQuery = await agentRuntime + .getService( + ServiceType.VERIFIABLE_LOGGING + ) + .listAgent(); + + res.json({ + success: true, + message: "Successfully get Agents", + data: pageQuery, + }); + } catch (error) { + elizaLogger.error("Detailed error:", error); + res.status(500).json({ + error: "failed to get agents registered ", + details: error.message, + stack: error.stack, + }); + } + } + ); + router.post( + "/verifiable/attestation", + async (req: express.Request, res: express.Response) => { + try { + const query = req.body || {}; + + const verifiableLogQuery = { + agentId: query.agentId || "", + publicKey: query.publicKey || "", + }; + const agentRuntime: AgentRuntime | undefined = agents.values().next().value; + const pageQuery = await agentRuntime + .getService( + ServiceType.VERIFIABLE_LOGGING + ) + .generateAttestation(verifiableLogQuery); + + res.json({ + success: true, + message: "Successfully get Attestation", + data: pageQuery, + }); + } catch (error) { + elizaLogger.error("Detailed error:", error); + res.status(500).json({ + error: "Failed to Get Attestation", + details: error.message, + stack: error.stack, + }); + } + } + ); + router.post( + "/verifiable/logs", + async (req: express.Request, res: express.Response) => { + try { + const query = req.body.query || {}; + const page = parseInt(req.body.page) || 1; + const pageSize = parseInt(req.body.pageSize) || 10; + + const verifiableLogQuery: VerifiableLogQuery = { + idEq: query.idEq || "", + agentIdEq: query.agentIdEq || "", + roomIdEq: query.roomIdEq || "", + userIdEq: query.userIdEq || "", + typeEq: query.typeEq || "", + contLike: query.contLike || "", + signatureEq: query.signatureEq || "", + }; + const agentRuntime: AgentRuntime | undefined = agents.values().next().value; + const pageQuery = await agentRuntime + .getService( + ServiceType.VERIFIABLE_LOGGING + ) + .pageQueryLogs(verifiableLogQuery, page, pageSize); + + res.json({ + success: true, + message: "Successfully retrieved logs", + data: pageQuery, + }); + } catch (error) { + elizaLogger.error("Detailed error:", error); + res.status(500).json({ + error: "Failed to Get Verifiable Logs", + details: error.message, + stack: error.stack, + }); + } + } + ); + + return router; +} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 8bb331e897..e7b42711e7 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1220,6 +1220,7 @@ export enum ServiceType { AWS_S3 = "aws_s3", BUTTPLUG = "buttplug", SLACK = "slack", + VERIFIABLE_LOGGING = "verifiable_logging", } export enum LoggingLevel { diff --git a/packages/plugin-tee-verifiable-log/.npmignore b/packages/plugin-tee-verifiable-log/.npmignore new file mode 100644 index 0000000000..078562ecea --- /dev/null +++ b/packages/plugin-tee-verifiable-log/.npmignore @@ -0,0 +1,6 @@ +* + +!dist/** +!package.json +!readme.md +!tsup.config.ts \ No newline at end of file diff --git a/packages/plugin-tee-verifiable-log/README.md b/packages/plugin-tee-verifiable-log/README.md new file mode 100644 index 0000000000..a94e6be1db --- /dev/null +++ b/packages/plugin-tee-verifiable-log/README.md @@ -0,0 +1,35 @@ +## Build +Execute the following command to build the code. +``` +pnpm clean +pnpm install or pnpm install --no-frozen-lockfile +pnpm build +``` + +## Configuration +This plugin depends on plugin-tee. +To get a TEE simulator for local testing, use the following commands: +```shell +docker pull phalanetwork/tappd-simulator:latest +# by default the simulator is available in localhost:8090 +docker run --rm -p 8090:8090 phalanetwork/tappd-simulator:latest +``` + +When using the provider through the runtime environment, ensure the following settings are configured: +```shell + # Optional, for simulator purposes if testing on mac or windows. Leave empty for Linux x86 machines. +TEE_MODE="LOCAL" # LOCAL | DOCKER | PRODUCTION +WALLET_SECRET_SALT= "" # ONLY define if you want to use TEE Plugin, otherwise it will throw errors + +VLOG="true" +``` +For detailed configuration of plugin-tee, see the documentation.[docs/docs/advanced/eliza-in-tee.md](/docs/docs/advanced/eliza-in-tee.md) + +## Test + +Test files are located in the `test` folder. To run the tests, execute the following command: + +```shell +pnpm test + +``` diff --git a/packages/plugin-tee-verifiable-log/eslint.config.mjs b/packages/plugin-tee-verifiable-log/eslint.config.mjs new file mode 100644 index 0000000000..92fe5bbebe --- /dev/null +++ b/packages/plugin-tee-verifiable-log/eslint.config.mjs @@ -0,0 +1,3 @@ +import eslintGlobalConfig from "../../eslint.config.mjs"; + +export default [...eslintGlobalConfig]; diff --git a/packages/plugin-tee-verifiable-log/package.json b/packages/plugin-tee-verifiable-log/package.json new file mode 100644 index 0000000000..006363bfb1 --- /dev/null +++ b/packages/plugin-tee-verifiable-log/package.json @@ -0,0 +1,31 @@ +{ + "name": "@elizaos/plugin-tee-verifiable-log", + "version": "0.1.7-alpha.1", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@elizaos/core": "workspace:*", + "@elizaos/plugin-tee": "workspace:*", + "dompurify": "3.2.2", + "elliptic": "^6.6.1", + "ethereum-cryptography": "^3.0.0", + "tsup": "8.3.5", + "uuid": "11.0.3", + "vitest": "2.1.5" + }, + "scripts": { + "build": "tsup --format esm --dts", + "test": "vitest run", + "test:watch": "vitest", + "lint": "eslint . --fix" + }, + "devDependencies": { + "@types/dompurify": "3.2.0", + "ts-node": "^10.9.2" + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } +} + diff --git a/packages/plugin-tee-verifiable-log/src/adapters/sqliteVerifiableDAO.ts b/packages/plugin-tee-verifiable-log/src/adapters/sqliteVerifiableDAO.ts new file mode 100644 index 0000000000..0002b97dfc --- /dev/null +++ b/packages/plugin-tee-verifiable-log/src/adapters/sqliteVerifiableDAO.ts @@ -0,0 +1,209 @@ +import { Database } from "better-sqlite3"; +import { v4 as uuidv4 } from "uuid"; +import { + VerifiableLog, + VerifiableAgent, + VerifiableDAO, + VerifiableLogQuery, + PageQuery, +} from "../types/logTypes.ts"; + +export class SQLite3VerifiableDAO extends VerifiableDAO { + constructor(db: Database) { + super(); + this.db = db; + // load(db); + // check if the tables exist, if not create them + const tables = db + .prepare( + "SELECT name FROM sqlite_master WHERE type='table' AND name IN ('verifiable-logs', 'verifiable-agents');" + ) + .all(); + if (tables.length !== 2) { + this.initializeSchema(); + } + } + + async initializeSchema(): Promise { + this.db.exec(` + CREATE TABLE IF NOT EXISTS "tee_verifiable_logs" + ( + "id" TEXT PRIMARY KEY, + "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + "agent_id" TEXT NOT NULL, + "room_id" TEXT NOT NULL, + "user_id" TEXT, + "type" TEXT, + "content" TEXT NOT NULL, + "signature" TEXT NOT NULL + ); + `); + + this.db.exec(` + CREATE TABLE IF NOT EXISTS "tee_verifiable_agents" + ( + "id" TEXT PRIMARY KEY, + "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + "agent_id" TEXT NOT NULL, + "agent_name" TEXT, + "agent_keypair_path" TEXT NOT NULL, + "agent_keypair_vlog_pk" TEXT NOT NULL, + UNIQUE ("agent_id") + ); + `); + } + + async addLog(log: VerifiableLog): Promise { + const sql = ` + INSERT INTO "tee_verifiable_logs" ("id", "created_at", "agent_id", "room_id", "user_id", "type", "content", + "signature") + VALUES (?, ?, ?, ?, ?, ?, ?, ?); + `; + try { + this.db + .prepare(sql) + .run( + log.id || uuidv4(), + log.created_at || new Date().getTime(), + log.agent_id, + log.room_id, + log.user_id, + log.type, + log.content, + log.signature + ); + return true; + } catch (error) { + console.error("SQLite3 Error adding log:", error); + return false; + } + } + + async pageQueryLogs( + query: VerifiableLogQuery, + page: number, + pageSize: number + ): Promise> { + const conditions: string[] = []; + const params: any[] = []; + + if (query.idEq) { + conditions.push(`id = ?`); + params.push(query.idEq); + } + if (query.agentIdEq) { + conditions.push(`agent_id = ?`); + params.push(query.agentIdEq); + } + if (query.roomIdEq) { + conditions.push(`room_id = ?`); + params.push(query.roomIdEq); + } + if (query.userIdEq) { + conditions.push(`user_id = ?`); + params.push(query.userIdEq); + } + if (query.typeEq) { + conditions.push(`type = ?`); + params.push(query.typeEq); + } + if (query.contLike) { + conditions.push(`content LIKE ?`); + params.push(`%${query.contLike}%`); + } + if (query.signatureEq) { + conditions.push(`signature = ?`); + params.push(query.signatureEq); + } + + const whereClause = + conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : ""; + + if (page < 1) { + page = 1; + } + const offset = (page - 1) * pageSize; + const limit = pageSize; + + + try { + const totalQuery = `SELECT COUNT(*) AS total + FROM tee_verifiable_logs ${whereClause}`; + const stmt = this.db.prepare(totalQuery); + const totalResult = stmt.get(params); + const total = totalResult.total; + + const dataQuery = ` + SELECT * + FROM tee_verifiable_logs ${whereClause} + ORDER BY created_at DESC + LIMIT ? OFFSET ? + `; + const dataResult = this.db + .prepare(dataQuery) + .all(...params, limit, offset); + + return { + page: page, + pageSize: pageSize, + total: total, + data: dataResult, + } as PageQuery; + } catch (error) { + console.error("Error querying tee_verifiable_logs:", error); + throw error; + } + } + + async addAgent(agent: VerifiableAgent): Promise { + const sql = ` + INSERT INTO "tee_verifiable_agents" ("id", "created_at", "agent_id","agent_name","agent_keypair_path", "agent_keypair_vlog_pk") + VALUES (?, ?, ?, ?, ?,?); + `; + try { + this.db + .prepare(sql) + .run( + agent.id || uuidv4(), + agent.created_at || new Date().getTime(), + agent.agent_id, + agent.agent_name||"agent bot", + agent.agent_keypair_path, + agent.agent_keypair_vlog_pk + ); + return true; + } catch (error) { + console.error("SQLite3 Error adding agent:", error); + return false; + } + } + + async getAgent(agentId: string): Promise { + const sql = `SELECT * + FROM "tee_verifiable_agents" + WHERE agent_id = ?`; + try { + const agent = this.db.prepare(sql).get(agentId); + if (agent) { + return agent as VerifiableAgent; + } else { + return null; + } + } catch (error) { + console.error("SQLite3 Error getting agent:", error); + throw error; + } + } + + async listAgent(): Promise { + const sql = `SELECT * + FROM "tee_verifiable_agents"`; + try { + const agents = this.db.prepare(sql).all(); + return agents as VerifiableAgent[]; + } catch (error) { + console.error("SQLite3 Error listing agent:", error); + throw error; + } + } +} diff --git a/packages/plugin-tee-verifiable-log/src/index.ts b/packages/plugin-tee-verifiable-log/src/index.ts new file mode 100644 index 0000000000..5e7b0395dd --- /dev/null +++ b/packages/plugin-tee-verifiable-log/src/index.ts @@ -0,0 +1,107 @@ +import { IAgentRuntime, type Plugin, Service, ServiceType } from "@elizaos/core"; +import { VerifiableLogProvider } from "./providers/verifiableLogProvider.ts"; +import { SQLite3VerifiableDAO } from "./adapters/sqliteVerifiableDAO.ts"; +import { + PageQuery, + VerifiableAgent, + VerifiableDAO, + VerifiableLog, + VerifiableLogQuery, +} from "./types/logTypes.ts"; + +export { PageQuery, VerifiableAgent, VerifiableLog, VerifiableLogQuery }; + +export class VerifiableLogService extends Service { + getInstance(): VerifiableLogService { + return this; + } + + static get serviceType(): ServiceType { + return ServiceType.VERIFIABLE_LOGGING; + } + + private verifiableLogProvider: VerifiableLogProvider; + private verifiableDAO: VerifiableDAO; + + private teeMode: string; + private vlogOpen: boolean = false; + + // Add abstract initialize method that must be implemented by derived classes + async initialize(runtime: IAgentRuntime): Promise { + if (runtime.databaseAdapter.db === null) { + throw new Error("Database adapter is not initialized."); + } + if (runtime.getSetting("TEE_MODE") === null) { + throw new Error("TEE_MODE is not set."); + } + if (runtime.getSetting("WALLET_SECRET_SALT") === null) { + throw new Error("WALLET_SECRET_SALT is not set."); + } + this.teeMode = runtime.getSetting("TEE_MODE"); + const value = runtime.getSetting("VLOG"); + const truthyValues = ["yes", "true", "YES", "TRUE", "Yes", "True", "1"]; + this.vlogOpen = truthyValues.includes(value.toLowerCase()); + this.verifiableDAO = new SQLite3VerifiableDAO( + runtime.databaseAdapter.db + ); + this.verifiableLogProvider = new VerifiableLogProvider( + this.verifiableDAO, + this.teeMode + ); + const isOK = await this.verifiableLogProvider.registerAgent( + { agentId: runtime?.agentId, agentName: runtime?.character?.name }, + this.teeMode + ); + if (!isOK) { + throw new Error(`Failed to register agent.${runtime.agentId}`); + } + return; + } + + async log(params: { + agentId: string; + roomId: string; + userId: string; + type: string; + content: string; + }): Promise { + if (this.vlogOpen) { + return this.verifiableLogProvider.log(params, this.teeMode); + } + return false; + } + + async generateAttestation(params: { + agentId: string; + publicKey: string; + }): Promise { + if (this.vlogOpen) { + return this.verifiableLogProvider.generateAttestation( + params, + ); + } + return ""; + } + + async listAgent(): Promise { + return this.verifiableDAO.listAgent(); + } + + async pageQueryLogs( + query: VerifiableLogQuery, + page: number, + pageSize: number + ): Promise> { + return this.verifiableDAO.pageQueryLogs(query, page, pageSize); + } +} + +export const verifiableLogPlugin: Plugin = { + name: "TeeVerifiableLog", + description: + "While Eliza operates within the TEE, it uses a derived key pair to sign its actions, ensuring that these actions are definitively executed by Eliza. Third-party users can remotely verify Eliza's public key to validate these actions", + actions: [], + evaluators: [], + providers: [], + services: [new VerifiableLogService()], +}; diff --git a/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts new file mode 100644 index 0000000000..153482b499 --- /dev/null +++ b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts @@ -0,0 +1,113 @@ +import { + IVerifiableLogProvider, + VerifiableAgent, + VerifiableDAO, + VerifiableLog, +} from "../types/logTypes.ts"; +import { + DeriveKeyProvider, + RemoteAttestationProvider, + RemoteAttestationQuote, +} from "@elizaos/plugin-tee"; + +export class VerifiableLogProvider implements IVerifiableLogProvider { + private dao: VerifiableDAO; + private keyPath: string = "/keys/verifiable_key"; + private remoteAttestationProvider: RemoteAttestationProvider; + private provider: DeriveKeyProvider; + + constructor(dao: VerifiableDAO, teeMode: string) { + this.dao = dao; + this.remoteAttestationProvider = new RemoteAttestationProvider(teeMode); + this.provider = new DeriveKeyProvider(teeMode); + } + + async log( + params: { + agentId: string; + roomId: string; + userId: string; + type: string; + content: string; + }, + subject: string + ): Promise { + let singed: string = ""; + + try { + const evmKeypair = await this.provider.deriveEcdsaKeypair( + this.keyPath, + subject, + params.agentId + ); + const signature = await evmKeypair.keypair.signMessage({ + message: params.content, + }); + singed = signature.toString(); + + // evmKeypair can now be used for Ethereum operations + } catch (error) { + console.error("EVM key derivation failed:", error); + } + return this.dao.addLog({ + agent_id: params.agentId, + room_id: params.roomId, + user_id: params.userId, + type: params.type, + content: params.content, + signature: singed, + }); + } + + async registerAgent( + params: { + agentId: string; + agentName: string; + }, + subject: string + ): Promise { + if (params.agentId === undefined) { + throw new Error("agentId is required"); + } + + const agent = await this.dao.getAgent(params.agentId); + if (agent !== null) { + return true; + } + const evmKeypair = await this.provider.deriveEcdsaKeypair( + this.keyPath, + subject, + params.agentId + ); + + const publicKey = evmKeypair.keypair.publicKey; + + return this.dao.addAgent({ + agent_id: params.agentId, + agent_name: params.agentName, + agent_keypair_path: this.keyPath, + agent_keypair_vlog_pk: publicKey, + }); + } + + async generateAttestation( + params: { + agentId: string; + publicKey: string; + } + ): Promise { + if (params.agentId === undefined || params.publicKey === undefined) { + throw new Error("agentId and publicKey are required"); + } + try { + // Generate 32-byte report data (reportData) containing the hash value of the public key. + const reportData = JSON.stringify(params); + // Call the remote attestation interface. + const quote: RemoteAttestationQuote = await this.remoteAttestationProvider.generateAttestation(reportData); + return JSON.stringify(quote); + } catch (error) { + console.error("Failed to generate attestation quote:", error); + throw error; + } + } +} diff --git a/packages/plugin-tee-verifiable-log/src/test/providers.test.ts b/packages/plugin-tee-verifiable-log/src/test/providers.test.ts new file mode 100644 index 0000000000..9219a053b0 --- /dev/null +++ b/packages/plugin-tee-verifiable-log/src/test/providers.test.ts @@ -0,0 +1,160 @@ +import { describe, it, expect, beforeEach, assert } from "vitest"; +import { SQLite3VerifiableDAO } from "../adapters/sqliteVerifiableDAO.ts"; +import Database from "better-sqlite3"; +import type { Database as DatabaseType } from "better-sqlite3"; +import { v4 as uuidv4 } from "uuid"; +import os from "os"; +import path from "path"; +import { + VerifiableAgent, + VerifiableLog, + VerifiableLogQuery, +} from "../types/logTypes.ts"; +import { VerifiableLogProvider } from "../providers/verifiableLogProvider.ts"; + +describe("SQLite3VerifiableDAO", () => { + let db: DatabaseType; + let sqLite3VerifiableDAO: SQLite3VerifiableDAO; + + let verifiableLogProvider: VerifiableLogProvider; + + const teeEndpoint = "LOCAL"; + beforeEach(() => { + const tempDir = os.tmpdir(); + const filePath = path.join(tempDir, "test2-db.sqlite"); + db = new Database(filePath); + sqLite3VerifiableDAO = new SQLite3VerifiableDAO(db); + verifiableLogProvider = new VerifiableLogProvider(sqLite3VerifiableDAO,"LOCAL"); + }); + describe("VerifiableLogProvider Management", () => { + it("should verifiableLogProvider.log when available", async () => { + let uid = uuidv4(); + await verifiableLogProvider.log( + { + agentId: uid, + roomId: "roomId", + userId: "userId", + type: "type1", + content: "body1", + }, + teeEndpoint + ); + + const pageResult1 = await sqLite3VerifiableDAO.pageQueryLogs( + { + agentIdEq: uid, + }, + 1, + 2 + ); + console.log("pageResult1:", pageResult1); + expect(pageResult1).not.toBeNull(); + assert.equal(pageResult1.data.length, 1); + }); + + it("should registerAgent and getAgent when available", async () => { + const testAgentId = uuidv4(); + await verifiableLogProvider.registerAgent( + { agentId: testAgentId, agentName: "test bot" }, + teeEndpoint + ); + console.log("testAgentId:", testAgentId); + const agentList = await sqLite3VerifiableDAO.listAgent(); + console.log("agentList:", agentList); + + const pageResult1 = await sqLite3VerifiableDAO.getAgent(testAgentId); + console.log("pageResult1:", pageResult1); + expect(pageResult1).not.toBeNull(); + + const stringPromise =await verifiableLogProvider.generateAttestation({ agentId: testAgentId ,publicKey: pageResult1.agent_keypair_vlog_pk}); + console.log("stringPromise:", stringPromise); + expect(stringPromise).not.toBeNull(); + }); + + }); + + describe("SQLite3VerifiableDAO Management", () => { + it("should addLog and pageQueryLogs when available", async () => { + let testId = uuidv4(); + await sqLite3VerifiableDAO.addLog({ + id: testId, + agent_id: "dddd", + room_id: "roomId", + user_id: "userId", + type: "type1", + content: "body1", + signature: "signed1", + }); + + const pageResult1 = await sqLite3VerifiableDAO.pageQueryLogs( + { + idEq: testId, + }, + 1, + 2 + ); + console.log("pageResult1:", pageResult1); + assert.equal(pageResult1.data.length, 1); + + const pageResult2 = await sqLite3VerifiableDAO.pageQueryLogs( + { + roomIdEq: "roomId", + userIdEq: "userId", + typeEq: "type1", + signatureEq: "signed1", + }, + 1, + 10 + ); + expect(pageResult2).not.toBeNull(); + + const pageResult3 = await sqLite3VerifiableDAO.pageQueryLogs( + { + contLike: "ddd", + }, + 1, + 10 + ); + expect(pageResult3.data).not.toBeNull(); + + const pageResult4 = await sqLite3VerifiableDAO.pageQueryLogs( + { + contLike: "body", + }, + 1, + 10 + ); + expect(pageResult4).not.toBeNull(); + }); + }); + + describe("Agent Management", () => { + it("should add agent when available", async () => { + const agentId = uuidv4(); + await sqLite3VerifiableDAO.addAgent({ + agent_id: agentId, + agent_name:"test bot", + agent_keypair_path: "/secretKey/path/", + agent_keypair_vlog_pk: "dddd的的的", + }); + var agent = await sqLite3VerifiableDAO.getAgent(agentId); + expect(agent).not.toBeNull(); + + console.log("get agent:", agent); + }); + + it("should list agent when available", async () => { + const agentId = uuidv4(); + await sqLite3VerifiableDAO.addAgent({ + agent_id: agentId, + agent_name:"test bot", + agent_keypair_path: "/secretKey/path/", + agent_keypair_vlog_pk: "dddd的的的", + }); + const agentList = await sqLite3VerifiableDAO.listAgent(); + // determine if agentlist data is not empty + expect(agentList).not.toBeNull(); + console.log("get agent:", agentList); + }); + }); +}); diff --git a/packages/plugin-tee-verifiable-log/src/types/logTypes.ts b/packages/plugin-tee-verifiable-log/src/types/logTypes.ts new file mode 100644 index 0000000000..32414b0385 --- /dev/null +++ b/packages/plugin-tee-verifiable-log/src/types/logTypes.ts @@ -0,0 +1,126 @@ + +export interface VerifiableLog { + id: string; // Primary Key UUID + created_at?: Date; // Default value: CURRENT_TIMESTAMP + agent_id: string; // Not null + room_id: string; // Not null + user_id: string; // Not null + type: string; // Not null + content: string; // Not null + signature: string; // Not null +} +export interface VerifiableLogQuery { + idEq: string; + agentIdEq: string; + roomIdEq: string; + userIdEq: string; + typeEq: string; + contLike: string; + signatureEq: string; +} + +export interface VerifiableAgent { + id: string; // Primary Key + created_at?: Date; // Default value: CURRENT_TIMESTAMP + agent_id: string; // Not null + agent_name: string; // Not null + agent_keypair_path: string; // Not null + agent_keypair_vlog_pk: string; // Not null +} + +export interface PageQuery { + page: number; + pageSize: number; + total?: number; + data?: Result; +} + +export abstract class VerifiableDAO { + protected constructor() {} + + /** + * The database instance. + */ + db: DB; + + /** + * Optional initialization method for the database adapter. + * @returns A Promise that resolves when initialization is complete. + */ + abstract initializeSchema(): Promise; + + /** + * insert log to table + * @param log + */ + abstract addLog(log: VerifiableLog): Promise; + + /** + * Performs a paginated query for VerifiableLogs based on the given criteria. + * + * @param agentQuery - The query parameters to filter the logs. + * @param page - The page number to retrieve (1-based). + * @param pageSize - The number of items per page. + * @returns A Promise that resolves to a PageQuery object containing an array of VerifiableLogs. + */ + abstract pageQueryLogs( + agentQuery: VerifiableLogQuery, + page: number, + pageSize: number + ): Promise>; + + /** + * insert Verifiable Agent info to table + * @param agent + */ + abstract addAgent(agent: VerifiableAgent): Promise; + + /** + * Retrieves a VerifiableAgent by its agentId. + * + * @param agentId - The unique identifier of the agent to retrieve. + * @returns A Promise that resolves to a VerifiableAgent object. + */ + abstract getAgent(agentId: string): Promise; + + /** + * Retrieves a list of all VerifiableAgents. + * + * @returns A Promise that resolves to an array of VerifiableAgent objects. + */ + abstract listAgent(): Promise; +} + +export interface IVerifiableLogProvider { + /** + * Logs a message with the given parameters. + * + * @param params - The parameters for the log message. + * @param endpoint - Tee endpoint. + * @returns A Promise that resolves to a boolean indicating whether the log was successful. + */ + log( + params: { + agentId: string; + roomId: string; + userId: string; + type: string; + content: string; + }, + endpoint: string + ): Promise; + + /** + * Registers a new agent with the given parameters. + * + * @param params - The parameters for the agent registration. + * @param endpoint - Tee endpoint. + * @returns A Promise that resolves to a boolean indicating whether the registration was successful. + */ + registerAgent( + params: { + agentId: string; + }, + endpoint: string + ): Promise; +} diff --git a/packages/plugin-tee-verifiable-log/tsconfig.json b/packages/plugin-tee-verifiable-log/tsconfig.json new file mode 100644 index 0000000000..73993deaaf --- /dev/null +++ b/packages/plugin-tee-verifiable-log/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../core/tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + }, + "include": [ + "src/**/*.ts" + ] +} \ No newline at end of file diff --git a/packages/plugin-tee-verifiable-log/tsup.config.ts b/packages/plugin-tee-verifiable-log/tsup.config.ts new file mode 100644 index 0000000000..1a55f7a745 --- /dev/null +++ b/packages/plugin-tee-verifiable-log/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + outDir: "dist", + sourcemap: true, + clean: true, + format: ["esm"], // Ensure you're targeting CommonJS + external: [], +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f0e904aa4..c91de3fe7f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,6 +195,9 @@ importers: '@elizaos/plugin-tee': specifier: workspace:* version: link:../packages/plugin-tee + '@elizaos/plugin-tee-verifiable-log': + specifier: workspace:* + version: link:../packages/plugin-tee-verifiable-log '@elizaos/plugin-ton': specifier: workspace:* version: link:../packages/plugin-ton @@ -507,6 +510,9 @@ importers: '@elizaos/plugin-image-generation': specifier: workspace:* version: link:../plugin-image-generation + '@elizaos/plugin-tee-verifiable-log': + specifier: workspace:* + version: link:../plugin-tee-verifiable-log '@types/body-parser': specifier: 1.19.5 version: 1.19.5 @@ -541,12 +547,6 @@ importers: packages/client-discord: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core - '@elizaos/plugin-node': - specifier: workspace:* - version: link:../plugin-node '@discordjs/opus': specifier: github:discordjs/opus version: https://codeload.github.com/discordjs/opus/tar.gz/31da49d8d2cc6c5a2ab1bfd332033ff7d5f9fb02(encoding@0.1.13) @@ -556,6 +556,12 @@ importers: '@discordjs/voice': specifier: 0.17.0 version: 0.17.0(@discordjs/opus@https://codeload.github.com/discordjs/opus/tar.gz/31da49d8d2cc6c5a2ab1bfd332033ff7d5f9fb02(encoding@0.1.13))(bufferutil@4.0.8)(ffmpeg-static@5.2.0)(utf-8-validate@5.0.10) + '@elizaos/core': + specifier: workspace:* + version: link:../core + '@elizaos/plugin-node': + specifier: workspace:* + version: link:../plugin-node discord.js: specifier: 14.16.3 version: 14.16.3(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -943,12 +949,12 @@ importers: packages/plugin-aptos: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@aptos-labs/ts-sdk': specifier: ^1.26.0 version: 1.33.1 + '@elizaos/core': + specifier: workspace:* + version: link:../core bignumber: specifier: 1.1.0 version: 1.1.0 @@ -1134,9 +1140,6 @@ importers: packages/plugin-icp: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@dfinity/agent': specifier: 2.1.3 version: 2.1.3(@dfinity/candid@2.1.3(@dfinity/principal@2.1.3))(@dfinity/principal@2.1.3) @@ -1149,6 +1152,9 @@ importers: '@dfinity/principal': specifier: 2.1.3 version: 2.1.3 + '@elizaos/core': + specifier: workspace:* + version: link:../core devDependencies: '@types/jest': specifier: 29.5.14 @@ -1297,9 +1303,6 @@ importers: packages/plugin-node: dependencies: - '@elizaos/core': - specifier: workspace:* - version: link:../core '@aws-sdk/client-s3': specifier: ^3.705.0 version: 3.713.0 @@ -1318,6 +1321,9 @@ importers: '@echogarden/speex-resampler-wasm': specifier: 0.2.1 version: 0.2.1 + '@elizaos/core': + specifier: workspace:* + version: link:../core '@huggingface/transformers': specifier: 3.0.2 version: 3.0.2 @@ -1475,6 +1481,9 @@ importers: packages/plugin-solana: dependencies: + '@coral-xyz/anchor': + specifier: 0.30.1 + version: 0.30.1(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10) '@elizaos/core': specifier: workspace:* version: link:../core @@ -1484,9 +1493,6 @@ importers: '@elizaos/plugin-trustdb': specifier: workspace:* version: link:../plugin-trustdb - '@coral-xyz/anchor': - specifier: 0.30.1 - version: 0.30.1(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10) '@solana/spl-token': specifier: 0.4.9 version: 0.4.9(@solana/web3.js@1.95.8(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(encoding@0.1.13)(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.6.3)(utf-8-validate@5.0.10) @@ -1526,15 +1532,15 @@ importers: packages/plugin-starknet: dependencies: + '@avnu/avnu-sdk': + specifier: 2.1.1 + version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.1)(starknet@6.18.0(encoding@0.1.13)) '@elizaos/core': specifier: workspace:* version: link:../core '@elizaos/plugin-trustdb': specifier: workspace:* version: link:../plugin-trustdb - '@avnu/avnu-sdk': - specifier: 2.1.1 - version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.1)(starknet@6.18.0(encoding@0.1.13)) '@uniswap/sdk-core': specifier: 6.0.0 version: 6.0.0 @@ -1654,6 +1660,43 @@ importers: specifier: 7.1.0 version: 7.1.0 + packages/plugin-tee-verifiable-log: + dependencies: + '@elizaos/core': + specifier: workspace:* + version: link:../core + '@elizaos/plugin-tee': + specifier: workspace:* + version: link:../plugin-tee + dompurify: + specifier: 3.2.2 + version: 3.2.2 + elliptic: + specifier: ^6.6.1 + version: 6.6.1 + ethereum-cryptography: + specifier: ^3.0.0 + version: 3.0.0 + tsup: + specifier: 8.3.5 + version: 8.3.5(@swc/core@1.10.1(@swc/helpers@0.5.15))(jiti@2.4.2)(postcss@8.4.49)(typescript@5.6.3)(yaml@2.6.1) + uuid: + specifier: 11.0.3 + version: 11.0.3 + vitest: + specifier: 2.1.5 + version: 2.1.5(@types/node@22.10.2)(jsdom@25.0.1(bufferutil@4.0.8)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@5.0.10))(terser@5.37.0) + whatwg-url: + specifier: 7.1.0 + version: 7.1.0 + devDependencies: + '@types/dompurify': + specifier: 3.2.0 + version: 3.2.0 + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@swc/core@1.10.1(@swc/helpers@0.5.15))(@types/node@22.10.2)(typescript@5.6.3) + packages/plugin-ton: dependencies: '@elizaos/core': @@ -5078,6 +5121,10 @@ packages: resolution: {integrity: sha512-ZOOqgXZgmilmVuZ5jx5kAIQQtA5N3HE5vqKi2Ojpid715sRqHwSoJjd1kqZbCI3CPwsSie56CYWK6R3ggQ6NBA==} engines: {node: '>=19.9.0'} + '@noble/ciphers@1.0.0': + resolution: {integrity: sha512-wH5EHOmLi0rEazphPbecAzmjd12I6/Yv/SiHdkA9LSycsQk7RuuTp7am5/o62qYr0RScE7Pc9icXGBbsr6cesA==} + engines: {node: ^14.21.3 || >=16} + '@noble/curves@1.2.0': resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} @@ -10925,6 +10972,10 @@ packages: ethereum-cryptography@2.2.1: resolution: {integrity: sha512-r/W8lkHSiTLxUxW8Rf3u4HGB0xQweG2RyETjywylKZSzLWoWAijRz8WCuOtJ6wah+avllXBqZuk29HCCvhEIRg==} + ethereum-cryptography@3.0.0: + resolution: {integrity: sha512-Ij7U9OgVZc4MAui8BttPCEaWUrAXy+eo2IbVfIxZyfzfFxMQrbIWXRUbrsRBqRrIhJ75T8P+KQRKpKTaG0Du8Q==} + engines: {node: ^14.21.3 || >=16, npm: '>=9'} + ethereumjs-abi@0.6.8: resolution: {integrity: sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA==} deprecated: This library has been deprecated and usage is discouraged. @@ -24404,6 +24455,8 @@ snapshots: - utf-8-validate - zod + '@noble/ciphers@1.0.0': {} + '@noble/curves@1.2.0': dependencies: '@noble/hashes': 1.3.2 @@ -32082,6 +32135,14 @@ snapshots: '@scure/bip32': 1.4.0 '@scure/bip39': 1.3.0 + ethereum-cryptography@3.0.0: + dependencies: + '@noble/ciphers': 1.0.0 + '@noble/curves': 1.6.0 + '@noble/hashes': 1.5.0 + '@scure/bip32': 1.5.0 + '@scure/bip39': 1.4.0 + ethereumjs-abi@0.6.8: dependencies: bn.js: 4.12.1 diff --git a/turbo.json b/turbo.json index 2f404476cb..3fb37aa32c 100644 --- a/turbo.json +++ b/turbo.json @@ -22,6 +22,10 @@ "outputs": ["dist/**"], "dependsOn": ["@elizaos/plugin-node#build"] }, + "@ai16z/client-direct#build": { + "outputs": ["dist/**"], + "dependsOn": ["@ai16z/plugin-tee-verifiable-log#build"] + }, "eliza-docs#build": { "outputs": ["build/**"] }, From 4614e0e2df5172a8d9ffb7ee8af81eea59f7562e Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Sun, 22 Dec 2024 17:34:23 +0800 Subject: [PATCH 2/9] feat: rollback --- characters/trump.character.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/characters/trump.character.json b/characters/trump.character.json index 80b93e4ecf..66329e2d7c 100644 --- a/characters/trump.character.json +++ b/characters/trump.character.json @@ -1,7 +1,7 @@ { "name": "trump", "clients": [], - "modelProvider": "ollama", + "modelProvider": "openai", "settings": { "secrets": {}, "voice": { From 7ead94facf5d20c243c73228171a6939f55239dd Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Sun, 22 Dec 2024 17:37:19 +0800 Subject: [PATCH 3/9] fix: rollback format --- packages/client-direct/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client-direct/package.json b/packages/client-direct/package.json index 35061fc285..ead78fcce8 100644 --- a/packages/client-direct/package.json +++ b/packages/client-direct/package.json @@ -28,4 +28,4 @@ "peerDependencies": { "whatwg-url": "7.1.0" } -} +}, From 50f8639b77444497e8a02e082926b9b963b1e68e Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Sun, 22 Dec 2024 17:40:16 +0800 Subject: [PATCH 4/9] fix: rollback format --- packages/client-direct/package.json | 60 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/client-direct/package.json b/packages/client-direct/package.json index ead78fcce8..ae1f0b34bf 100644 --- a/packages/client-direct/package.json +++ b/packages/client-direct/package.json @@ -1,31 +1,31 @@ { - "name": "@elizaos/client-direct", - "version": "0.1.7-alpha.1", - "main": "dist/index.js", - "type": "module", - "types": "dist/index.d.ts", - "dependencies": { - "@elizaos/core": "workspace:*", - "@elizaos/plugin-image-generation": "workspace:*", - "@elizaos/plugin-tee-verifiable-log": "workspace:*", - "@types/body-parser": "1.19.5", - "@types/cors": "2.8.17", - "@types/express": "5.0.0", - "body-parser": "1.20.3", - "cors": "2.8.5", - "discord.js": "14.16.3", - "express": "4.21.1", - "multer": "1.4.5-lts.1" - }, - "devDependencies": { - "tsup": "8.3.5" - }, - "scripts": { - "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch", - "lint": "eslint --fix --cache ." - }, - "peerDependencies": { - "whatwg-url": "7.1.0" - } -}, + "name": "@elizaos/client-direct", + "version": "0.1.7-alpha.1", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@elizaos/core": "workspace:*", + "@elizaos/plugin-image-generation": "workspace:*", + "@elizaos/plugin-tee-verifiable-log": "workspace:*", + "@types/body-parser": "1.19.5", + "@types/cors": "2.8.17", + "@types/express": "5.0.0", + "body-parser": "1.20.3", + "cors": "2.8.5", + "discord.js": "14.16.3", + "express": "4.21.1", + "multer": "1.4.5-lts.1" + }, + "devDependencies": { + "tsup": "8.3.5" + }, + "scripts": { + "build": "tsup --format esm --dts", + "dev": "tsup --format esm --dts --watch", + "lint": "eslint --fix --cache ." + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } +} From 1851c04c7489cfdc51b5ab65a4cc501597471324 Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Mon, 23 Dec 2024 19:24:44 +0800 Subject: [PATCH 5/9] fix: rollback format --- .../src/providers/verifiableLogProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts index 153482b499..6248bd1d57 100644 --- a/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts +++ b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts @@ -48,6 +48,7 @@ export class VerifiableLogProvider implements IVerifiableLogProvider { // evmKeypair can now be used for Ethereum operations } catch (error) { console.error("EVM key derivation failed:", error); + return false; } return this.dao.addLog({ agent_id: params.agentId, From 73f543710923a7fa8edfe6fd5ad904f538616fca Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Mon, 23 Dec 2024 19:25:55 +0800 Subject: [PATCH 6/9] fix: catch error return false; --- .../src/providers/verifiableLogProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts index 6248bd1d57..e53e7031e2 100644 --- a/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts +++ b/packages/plugin-tee-verifiable-log/src/providers/verifiableLogProvider.ts @@ -48,6 +48,7 @@ export class VerifiableLogProvider implements IVerifiableLogProvider { // evmKeypair can now be used for Ethereum operations } catch (error) { console.error("EVM key derivation failed:", error); + return false; } return this.dao.addLog({ From aaf78505fc75f71bf52fb204b8b29c035d858373 Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Tue, 24 Dec 2024 10:43:00 +0800 Subject: [PATCH 7/9] fix: PR conflict --- agent/package.json | 122 ++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/agent/package.json b/agent/package.json index f34d0bbf69..afe17a8478 100644 --- a/agent/package.json +++ b/agent/package.json @@ -1,63 +1,63 @@ { - "name": "@elizaos/agent", - "version": "0.1.7-alpha.1", - "main": "src/index.ts", - "type": "module", - "scripts": { - "start": "node --loader ts-node/esm src/index.ts", - "dev": "node --loader ts-node/esm src/index.ts", - "check-types": "tsc --noEmit" - }, - "nodemonConfig": { - "watch": [ - "src", - "../core/dist" - ], - "ext": "ts,json", - "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" - }, - "dependencies": { - "@elizaos/adapter-postgres": "workspace:*", - "@elizaos/adapter-redis": "workspace:*", - "@elizaos/adapter-sqlite": "workspace:*", - "@elizaos/client-auto": "workspace:*", - "@elizaos/client-direct": "workspace:*", - "@elizaos/client-discord": "workspace:*", - "@elizaos/client-farcaster": "workspace:*", - "@elizaos/client-lens": "workspace:*", - "@elizaos/client-telegram": "workspace:*", - "@elizaos/client-twitter": "workspace:*", - "@elizaos/client-slack": "workspace:*", - "@elizaos/core": "workspace:*", - "@elizaos/plugin-0g": "workspace:*", - "@elizaos/plugin-aptos": "workspace:*", - "@elizaos/plugin-bootstrap": "workspace:*", - "@elizaos/plugin-intiface": "workspace:*", - "@elizaos/plugin-coinbase": "workspace:*", - "@elizaos/plugin-conflux": "workspace:*", - "@elizaos/plugin-evm": "workspace:*", - "@elizaos/plugin-flow": "workspace:*", - "@elizaos/plugin-story": "workspace:*", - "@elizaos/plugin-goat": "workspace:*", - "@elizaos/plugin-icp": "workspace:*", - "@elizaos/plugin-image-generation": "workspace:*", - "@elizaos/plugin-nft-generation": "workspace:*", - "@elizaos/plugin-node": "workspace:*", - "@elizaos/plugin-solana": "workspace:*", - "@elizaos/plugin-starknet": "workspace:*", - "@elizaos/plugin-ton": "workspace:*", - "@elizaos/plugin-sui": "workspace:*", - "@elizaos/plugin-tee": "workspace:*", - "@elizaos/plugin-multiversx": "workspace:*", - "@elizaos/plugin-near": "workspace:*", - "@elizaos/plugin-zksync-era": "workspace:*", - "@elizaos/plugin-tee-verifiable-log": "workspace:*", - "readline": "1.3.0", - "ws": "8.18.0", - "yargs": "17.7.2" - }, - "devDependencies": { - "ts-node": "10.9.2", - "tsup": "8.3.5" - } + "name": "@elizaos/agent", + "version": "0.1.7-alpha.1", + "main": "src/index.ts", + "type": "module", + "scripts": { + "start": "node --loader ts-node/esm src/index.ts", + "dev": "node --loader ts-node/esm src/index.ts", + "check-types": "tsc --noEmit" + }, + "nodemonConfig": { + "watch": [ + "src", + "../core/dist" + ], + "ext": "ts,json", + "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" + }, + "dependencies": { + "@elizaos/adapter-postgres": "workspace:*", + "@elizaos/adapter-redis": "workspace:*", + "@elizaos/adapter-sqlite": "workspace:*", + "@elizaos/client-auto": "workspace:*", + "@elizaos/client-direct": "workspace:*", + "@elizaos/client-discord": "workspace:*", + "@elizaos/client-farcaster": "workspace:*", + "@elizaos/client-lens": "workspace:*", + "@elizaos/client-telegram": "workspace:*", + "@elizaos/client-twitter": "workspace:*", + "@elizaos/client-slack": "workspace:*", + "@elizaos/core": "workspace:*", + "@elizaos/plugin-0g": "workspace:*", + "@elizaos/plugin-aptos": "workspace:*", + "@elizaos/plugin-bootstrap": "workspace:*", + "@elizaos/plugin-intiface": "workspace:*", + "@elizaos/plugin-coinbase": "workspace:*", + "@elizaos/plugin-conflux": "workspace:*", + "@elizaos/plugin-evm": "workspace:*", + "@elizaos/plugin-flow": "workspace:*", + "@elizaos/plugin-story": "workspace:*", + "@elizaos/plugin-goat": "workspace:*", + "@elizaos/plugin-icp": "workspace:*", + "@elizaos/plugin-image-generation": "workspace:*", + "@elizaos/plugin-nft-generation": "workspace:*", + "@elizaos/plugin-node": "workspace:*", + "@elizaos/plugin-solana": "workspace:*", + "@elizaos/plugin-starknet": "workspace:*", + "@elizaos/plugin-ton": "workspace:*", + "@elizaos/plugin-sui": "workspace:*", + "@elizaos/plugin-tee": "workspace:*", + "@elizaos/plugin-multiversx": "workspace:*", + "@elizaos/plugin-near": "workspace:*", + "@elizaos/plugin-zksync-era": "workspace:*", + "@elizaos/plugin-tee-verifiable-log": "workspace:*", + "readline": "1.3.0", + "ws": "8.18.0", + "yargs": "17.7.2" + }, + "devDependencies": { + "ts-node": "10.9.2", + "tsup": "8.3.5" + } } From 38fcc69f4e793067e27134773d47457e1e1bc038 Mon Sep 17 00:00:00 2001 From: Gene <125658572+gene-zhan@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:52:19 +0800 Subject: [PATCH 8/9] Update package.json fix conflict From e1a3c29b18dc0c70c5b1e57d5a5991b85640c50f Mon Sep 17 00:00:00 2001 From: gene-zhan Date: Tue, 24 Dec 2024 11:10:08 +0800 Subject: [PATCH 9/9] fix: PR conflict --- packages/client-direct/package.json | 58 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/client-direct/package.json b/packages/client-direct/package.json index ae1f0b34bf..35061fc285 100644 --- a/packages/client-direct/package.json +++ b/packages/client-direct/package.json @@ -1,31 +1,31 @@ { - "name": "@elizaos/client-direct", - "version": "0.1.7-alpha.1", - "main": "dist/index.js", - "type": "module", - "types": "dist/index.d.ts", - "dependencies": { - "@elizaos/core": "workspace:*", - "@elizaos/plugin-image-generation": "workspace:*", - "@elizaos/plugin-tee-verifiable-log": "workspace:*", - "@types/body-parser": "1.19.5", - "@types/cors": "2.8.17", - "@types/express": "5.0.0", - "body-parser": "1.20.3", - "cors": "2.8.5", - "discord.js": "14.16.3", - "express": "4.21.1", - "multer": "1.4.5-lts.1" - }, - "devDependencies": { - "tsup": "8.3.5" - }, - "scripts": { - "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch", - "lint": "eslint --fix --cache ." - }, - "peerDependencies": { - "whatwg-url": "7.1.0" - } + "name": "@elizaos/client-direct", + "version": "0.1.7-alpha.1", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@elizaos/core": "workspace:*", + "@elizaos/plugin-image-generation": "workspace:*", + "@elizaos/plugin-tee-verifiable-log": "workspace:*", + "@types/body-parser": "1.19.5", + "@types/cors": "2.8.17", + "@types/express": "5.0.0", + "body-parser": "1.20.3", + "cors": "2.8.5", + "discord.js": "14.16.3", + "express": "4.21.1", + "multer": "1.4.5-lts.1" + }, + "devDependencies": { + "tsup": "8.3.5" + }, + "scripts": { + "build": "tsup --format esm --dts", + "dev": "tsup --format esm --dts --watch", + "lint": "eslint --fix --cache ." + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } }