-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: RP for plugin-tee-verifiable-log-api #1260
Open
gene-zhan
wants to merge
19
commits into
elizaOS:develop
Choose a base branch
from
artela-network:ai16zPR/tee-verifiable-log-api-from-main
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,074
−0
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
464a87a
Update README.md
jinngit 710fc4e
Update README.md
jinngit f9d9f31
Merge branch 'ai16z:main' into main
gene-zhan 654bada
add tee-verifiable-log plugin
jinngit 85be88d
add tee-verifiable-log plugin
jinngit e74e390
add tee-verifiable-log plugin api
jinngit e4d995a
add tee-verifiable-log plugin api
jinngit be19cc0
Update package.json
gene-zhan a3c1417
Merge branch 'ai16z:main' into main
gene-zhan 2163be3
merge main
gene-sf 416e9b5
merge main
gene-sf b8a1e72
rollback main docs
gene-sf a127898
rollback main docs
gene-sf 5c0bd9a
rollback main docs
gene-sf edc830d
rollback main docs
gene-sf 7f057bc
rollback main docs
gene-sf 8286d6d
rollback main docs
gene-sf 0548d24
rollback main docs
gene-sf d401c99
rollback main docs
gene-sf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ import { settings } from "@ai16z/eliza"; | |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fail the api call |
||
this.app.use(apiLogRouter); | ||
|
||
// Define an interface that extends the Express Request interface | ||
interface CustomRequest extends ExpressRequest { | ||
file: File; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import express from "express"; | ||
import bodyParser from "body-parser"; | ||
import cors from "cors"; | ||
|
||
import { AgentRuntime, elizaLogger, ServiceType } from "@ai16z/eliza"; | ||
import { | ||
VerifiableLogService, | ||
VerifiableLogQuery, | ||
} from "@ai16z/plugin-tee-verifiable-log"; | ||
|
||
export function createVerifiableLogApiRouter( | ||
agents: Map<string, AgentRuntime>, | ||
directClient | ||
) { | ||
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<VerifiableLogService>( | ||
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<VerifiableLogService>( | ||
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<VerifiableLogService>( | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* | ||
|
||
!dist/** | ||
!package.json | ||
!readme.md | ||
!tsup.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="DOCKER" # LOCAL | DOCKER | PRODUCTION | ||
WALLET_SECRET_SALT= "<your-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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@ai16z/plugin-tee-verifiable-log", | ||
"version": "0.1.4-alpha.3", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@ai16z/eliza": "workspace:*", | ||
"@ai16z/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" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!
I think the easiest way to insert into documentation is to add this as a section called Enable Verifiable Logs for the Eliza in TEE Doc
docs/docs/advanced/eliza-in-tee.md
. Then add a reference to your discord or discord user to contact about the implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can work on this together for formatting & further enhancements/tutorials down the road. Separate into to two Plugin Sections:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, let's work on this together. that’s exactly the idea behind building this plugin.
Let me explain further:
@HashWarlock @odilitime