-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from artela-network/ai16zPR/tee-verifiable-l…
…og-api-from-develop feat: RP for plugin-tee-verifiable-log
- Loading branch information
Showing
23 changed files
with
1,968 additions
and
390 deletions.
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
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 |
---|---|---|
@@ -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<string, AgentRuntime> | ||
) { | ||
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 |
Oops, something went wrong.