@elizaos/plugin-tee 0.1.9 → 1.0.0-alpha.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/README.md +97 -191
- package/dist/{_esm-FVHF6KDD.js → _esm-L4OBJJWB.js} +5 -5
- package/dist/_esm-L4OBJJWB.js.map +1 -0
- package/dist/{ccip-MMGH6DXX.js → ccip-BIZHB2Z3.js} +3 -2
- package/dist/{chunk-NTU6R7BC.js → chunk-4HQ7LDIJ.js} +137 -191
- package/dist/chunk-4HQ7LDIJ.js.map +1 -0
- package/dist/chunk-672HY72Z.js +139 -0
- package/dist/chunk-672HY72Z.js.map +1 -0
- package/dist/{chunk-4L6P6TY5.js → chunk-LCSUOOZR.js} +54 -134
- package/dist/chunk-LCSUOOZR.js.map +1 -0
- package/dist/index.d.ts +67 -14
- package/dist/index.js +785 -399
- package/dist/index.js.map +1 -1
- package/dist/{secp256k1-QUTB2QC2.js → secp256k1-ARCYQQLX.js} +3 -2
- package/package.json +16 -30
- package/tsup.config.ts +28 -0
- package/dist/_esm-FVHF6KDD.js.map +0 -1
- package/dist/chunk-4L6P6TY5.js.map +0 -1
- package/dist/chunk-NTU6R7BC.js.map +0 -1
- /package/dist/{ccip-MMGH6DXX.js.map → ccip-BIZHB2Z3.js.map} +0 -0
- /package/dist/{secp256k1-QUTB2QC2.js.map → secp256k1-ARCYQQLX.js.map} +0 -0
package/README.md
CHANGED
|
@@ -1,230 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TEE Log Plugin for Eliza
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The TEE Log Plugin for Eliza is designed to enhance the logging capabilities of the Eliza by providing a structured way to generate, store and verify TEE (Trusted Execution Environment) logs for agents. This plugin ensures that all sensitive interactions are securely logged, providing a transparent and tamper-resistant record of all sensitive activities.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Background
|
|
6
6
|
|
|
7
|
-
This
|
|
7
|
+
As Eliza is a fully autonomous AI agent capable of running within a TEE, we need to demonstrate to the outside world that we are indeed operating within a TEE. This allows external parties to verify that our actions are protected by the TEE and that they are autonomously executed by Eliza, without any third-party interference. Therefore, it is necessary to leverage TEE's remote attestation and establish a TEE logging mechanism to prove that these operations are entirely and autonomously performed by Eliza within the TEE.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- Derive Ed25519 keypairs for Solana
|
|
11
|
-
- Derive ECDSA keypairs for Ethereum
|
|
12
|
-
- Generate remote attestation quotes
|
|
13
|
-
- Manage wallet interactions with TEE-derived keys
|
|
9
|
+
## Requirements
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
Since the TEE Logging is based on the TEE, it is necessary to have a TEE enabled environment. Currently, we support Intel SGX (Gramine) and Intel TDX (dstack).
|
|
12
|
+
- using Intel SGX (Gramine), you need to enable the plugin-sgx in the Eliza runtime, which is enabled in SGX env automatically.
|
|
13
|
+
- using Intel TDX (dstack), you need to enable the plugin-tee in the Eliza runtime.
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
npm install @elizaos/plugin-tee
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Configuration
|
|
22
|
-
|
|
23
|
-
The plugin requires the following environment variables:
|
|
24
|
-
|
|
25
|
-
```env
|
|
26
|
-
TEE_MODE=LOCAL|DOCKER|PRODUCTION
|
|
27
|
-
WALLET_SECRET_SALT=your_secret_salt # Required for single agent deployments
|
|
28
|
-
DSTACK_SIMULATOR_ENDPOINT=your-endpoint-url # Optional, for simulator purposes
|
|
29
|
-
```
|
|
15
|
+
## TEE Logging Mechanism
|
|
30
16
|
|
|
31
|
-
##
|
|
17
|
+
## TEE Logging Mechanism
|
|
32
18
|
|
|
33
|
-
|
|
19
|
+
1. **Key Pair Generation and Attestation**:
|
|
20
|
+
- During startup, each agent generates a key pair and creates a remote attestation for the public key. The private key is securely stored in the TEE's encrypted memory. The agent's relevant information, along with the public key and attestation, is recorded in a local database. A new key pair is generated each time the agent is updated or restarted to ensure key security.
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
2. **Log Recording**:
|
|
23
|
+
- For each log entry, basic information is recorded, including `agentId`, `roomId`, `userId`, `type`, `content`, and `timestamp`. This information is concatenated and signed using the agent's corresponding private key to ensure verifiability. The verification process follows this trust chain:
|
|
24
|
+
- Verify the attestation.
|
|
25
|
+
- Trust the public key contained in the attestation.
|
|
26
|
+
- Use the public key to verify the signature.
|
|
27
|
+
- Trust the complete log record.
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// ... other configuration
|
|
41
|
-
};
|
|
42
|
-
```
|
|
29
|
+
3. **Data Storage**:
|
|
30
|
+
- All log data must be stored in the TEE's encrypted file system in production environments. Storing data in plaintext is prohibited to prevent tampering.
|
|
43
31
|
|
|
44
|
-
|
|
32
|
+
4. **Log Extraction for Verification**:
|
|
33
|
+
- Third parties can extract TEE logs for verification purposes. Two types of information can be extracted:
|
|
34
|
+
- **Agent Information**: This includes the agent's metadata, public key, and attestation, which can be used to verify the agent's public key.
|
|
35
|
+
- **Log Information**: Required logs can be extracted, with the agent's attestation and public key used to verify the signature, ensuring that each record remains untampered.
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
5. **Integrity Protection**:
|
|
38
|
+
- When users extract TEE logs via the REST API, the results are hashed, and an attestation is generated. After extraction, users can verify the attestation by comparing the hash value contained within it to the extracted results, thereby ensuring the integrity of the data.
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { DeriveKeyProvider } from "@elizaos/plugin-tee";
|
|
52
|
-
|
|
53
|
-
// Initialize the provider
|
|
54
|
-
const provider = new DeriveKeyProvider();
|
|
55
|
-
|
|
56
|
-
// Derive a raw key
|
|
57
|
-
const rawKey = await provider.rawDeriveKey(
|
|
58
|
-
"/path/to/derive",
|
|
59
|
-
"subject-identifier"
|
|
60
|
-
);
|
|
61
|
-
// rawKey is a DeriveKeyResponse that can be used for further processing
|
|
62
|
-
const rawKeyArray = rawKey.asUint8Array();
|
|
63
|
-
|
|
64
|
-
// Derive a Solana keypair (Ed25519)
|
|
65
|
-
const solanaKeypair = await provider.deriveEd25519Keypair(
|
|
66
|
-
"/path/to/derive",
|
|
67
|
-
"subject-identifier"
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// Derive an Ethereum keypair (ECDSA)
|
|
71
|
-
const evmKeypair = await provider.deriveEcdsaKeypair(
|
|
72
|
-
"/path/to/derive",
|
|
73
|
-
"subject-identifier"
|
|
74
|
-
);
|
|
75
|
-
```
|
|
40
|
+
## Services
|
|
76
41
|
|
|
77
|
-
|
|
42
|
+
- **[TeeLogService]**: This service is responsible for generating and storing TEE logs for agents.
|
|
78
43
|
|
|
79
|
-
|
|
44
|
+
### Class: TeeLogService
|
|
80
45
|
|
|
81
|
-
|
|
82
|
-
import { RemoteAttestationProvider } from "@elizaos/plugin-tee";
|
|
46
|
+
The `TeeLogService` class implements the `ITeeLogService` interface and extends the `Service` class. It manages the logging of sensitive interactions within a Trusted Execution Environment (TEE).
|
|
83
47
|
|
|
84
|
-
|
|
85
|
-
const attestation = await provider.generateAttestation("your-report-data");
|
|
86
|
-
```
|
|
48
|
+
#### Methods
|
|
87
49
|
|
|
88
|
-
|
|
50
|
+
- **getInstance()**: `TeeLogService`
|
|
51
|
+
- Returns the singleton instance of the `TeeLogService`.
|
|
89
52
|
|
|
90
|
-
|
|
53
|
+
- **static get serviceType()**: `ServiceType`
|
|
54
|
+
- Returns the service type for TEE logging.
|
|
91
55
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```
|
|
56
|
+
- **async initialize(runtime: IAgentRuntime): Promise<void>**
|
|
57
|
+
- Initializes the TEE log service. It checks the runtime settings to configure the TEE type and enables logging if configured.
|
|
95
58
|
|
|
96
|
-
|
|
59
|
+
- **async log(agentId: string, roomId: string, userId: string, type: string, content: string): Promise<boolean>**
|
|
60
|
+
- Logs an interaction with the specified parameters. Returns `false` if TEE logging is not enabled.
|
|
97
61
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
```
|
|
62
|
+
- **async getAllAgents(): Promise<TeeAgent[]>**
|
|
63
|
+
- Retrieves all agents that have been logged. Returns an empty array if TEE logging is not enabled.
|
|
101
64
|
|
|
102
|
-
|
|
65
|
+
- **async getAgent(agentId: string): Promise<TeeAgent | undefined>**
|
|
66
|
+
- Retrieves the details of a specific agent by their ID. Returns `undefined` if TEE logging is not enabled.
|
|
103
67
|
|
|
104
|
-
|
|
68
|
+
- **async getLogs(query: TeeLogQuery, page: number, pageSize: number): Promise<PageQuery<TeeLog[]>>**
|
|
69
|
+
- Retrieves logs based on the provided query parameters. Returns an empty result if TEE logging is not enabled.
|
|
105
70
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
# by default the simulator is available in localhost:8090
|
|
109
|
-
docker run --rm -p 8090:8090 phalanetwork/tappd-simulator:latest
|
|
110
|
-
```
|
|
71
|
+
- **async generateAttestation(userReport: string): Promise<string>**
|
|
72
|
+
- Generates an attestation based on the provided user report.
|
|
111
73
|
|
|
112
|
-
|
|
74
|
+
### Storage
|
|
113
75
|
|
|
114
|
-
|
|
115
|
-
- `@solana/web3.js`: Solana blockchain interaction
|
|
116
|
-
- `viem`: Ethereum interaction library
|
|
117
|
-
- Other standard dependencies listed in package.json
|
|
76
|
+
The TEE logs are stored in a SQLite database, which is located at `./data/tee_log.sqlite`. The database is automatically created when the service is initialized.
|
|
118
77
|
|
|
119
|
-
|
|
78
|
+
Important: You need to use the encrypted file system to store the database file in production, otherwise the database will be compromised. Since TEE only protects memory-in-use, the disk is not protected by the TEE. However, Many TEE development tools support the encrypted file system, for example, you can refer to the [Gramine Encrypted files](https://gramine.readthedocs.io/en/latest/manifest-syntax.html#encrypted-files) documentation for more information.
|
|
120
79
|
|
|
121
|
-
###
|
|
80
|
+
### Usage
|
|
122
81
|
|
|
123
|
-
|
|
124
|
-
- `remoteAttestationProvider`: Handles generation of remote attestation quotes
|
|
125
|
-
- `walletProvider`: Manages wallet interactions with TEE-derived keys
|
|
82
|
+
To use the `TeeLogService`, ensure that the TEE environment is properly configured and initialized.
|
|
126
83
|
|
|
127
|
-
|
|
84
|
+
Enable the TEE logging in the Eliza .env file:
|
|
128
85
|
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
OFF = "OFF",
|
|
132
|
-
LOCAL = "LOCAL", // For local development with simulator
|
|
133
|
-
DOCKER = "DOCKER", // For docker development with simulator
|
|
134
|
-
PRODUCTION = "PRODUCTION", // For production without simulator
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
interface RemoteAttestationQuote {
|
|
138
|
-
quote: string;
|
|
139
|
-
timestamp: number;
|
|
140
|
-
}
|
|
86
|
+
```env
|
|
87
|
+
TEE_LOG_ENABLED=true
|
|
141
88
|
```
|
|
142
89
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
1. **Key Management**
|
|
146
|
-
|
|
147
|
-
- Advanced key derivation schemes
|
|
148
|
-
- Multi-party computation support
|
|
149
|
-
- Key rotation automation
|
|
150
|
-
- Backup and recovery systems
|
|
151
|
-
- Hardware security module integration
|
|
152
|
-
- Custom derivation paths
|
|
90
|
+
The logging isn't integrated for actions by default, you need to integrate the logging for the actions you want to log. For example, if you want to log the `Continue` action of plugin-bootstrap, you can do the following:
|
|
153
91
|
|
|
154
|
-
|
|
92
|
+
First, add plugin-tee-log to the dependencies of plugin-bootstrap:
|
|
155
93
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
- Policy management system
|
|
160
|
-
- Compliance reporting
|
|
161
|
-
- Audit trail generation
|
|
162
|
-
|
|
163
|
-
3. **Security Features**
|
|
164
|
-
|
|
165
|
-
- Memory encryption improvements
|
|
166
|
-
- Side-channel protection
|
|
167
|
-
- Secure state management
|
|
168
|
-
- Access control systems
|
|
169
|
-
- Threat detection
|
|
170
|
-
- Security monitoring
|
|
171
|
-
|
|
172
|
-
4. **Chain Integration**
|
|
173
|
-
|
|
174
|
-
- Multi-chain support expansion
|
|
175
|
-
- Cross-chain attestation
|
|
176
|
-
- Chain-specific optimizations
|
|
177
|
-
- Custom signing schemes
|
|
178
|
-
- Transaction privacy
|
|
179
|
-
- Bridge security
|
|
180
|
-
|
|
181
|
-
5. **Developer Tools**
|
|
182
|
-
|
|
183
|
-
- Enhanced debugging capabilities
|
|
184
|
-
- Testing framework
|
|
185
|
-
- Simulation environment
|
|
186
|
-
- Documentation generator
|
|
187
|
-
- Performance profiling
|
|
188
|
-
- Integration templates
|
|
189
|
-
|
|
190
|
-
6. **Performance Optimization**
|
|
191
|
-
- Parallel processing
|
|
192
|
-
- Caching mechanisms
|
|
193
|
-
- Resource management
|
|
194
|
-
- Latency reduction
|
|
195
|
-
- Throughput improvements
|
|
196
|
-
- Load balancing
|
|
197
|
-
|
|
198
|
-
We welcome community feedback and contributions to help prioritize these enhancements.
|
|
199
|
-
|
|
200
|
-
## Contributing
|
|
201
|
-
|
|
202
|
-
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
203
|
-
|
|
204
|
-
## Credits
|
|
205
|
-
|
|
206
|
-
This plugin integrates with and builds upon several key technologies:
|
|
207
|
-
|
|
208
|
-
- [Phala Network](https://phala.network/): Confidential smart contract platform
|
|
209
|
-
- [@phala/dstack-sdk](https://www.npmjs.com/package/@phala/dstack-sdk): Core TEE functionality
|
|
210
|
-
- [@solana/web3.js](https://www.npmjs.com/package/@solana/web3.js): Solana blockchain interaction
|
|
211
|
-
- [viem](https://www.npmjs.com/package/viem): Ethereum interaction library
|
|
212
|
-
- [Intel SGX](https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/overview.html): Trusted Execution Environment technology
|
|
213
|
-
|
|
214
|
-
Special thanks to:
|
|
215
|
-
|
|
216
|
-
- The Phala Network team for their TEE infrastructure
|
|
217
|
-
- The Intel SGX team for TEE technology
|
|
218
|
-
- The dStack SDK maintainers
|
|
219
|
-
- The Eliza community for their contributions and feedback
|
|
220
|
-
|
|
221
|
-
For more information about TEE capabilities:
|
|
94
|
+
```json
|
|
95
|
+
"@elizaos/plugin-tee-log": "workspace:*",
|
|
96
|
+
```
|
|
222
97
|
|
|
223
|
-
|
|
224
|
-
- [Intel SGX Documentation](https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/documentation.html)
|
|
225
|
-
- [TEE Security Best Practices](https://docs.phala.network/developers/phat-contract/security-notes)
|
|
226
|
-
- [dStack SDK Reference](https://docs.phala.network/developers/dstack-sdk)
|
|
98
|
+
Then, add the following code to the `Continue` action:
|
|
227
99
|
|
|
228
|
-
|
|
100
|
+
```typescript
|
|
101
|
+
import {
|
|
102
|
+
ServiceType,
|
|
103
|
+
ITeeLogService,
|
|
104
|
+
} from "@elizaos/core";
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// In the handler of the action
|
|
108
|
+
handler: async (
|
|
109
|
+
runtime: IAgentRuntime,
|
|
110
|
+
message: Memory,
|
|
111
|
+
state: State,
|
|
112
|
+
options: any,
|
|
113
|
+
callback: HandlerCallback
|
|
114
|
+
) => {
|
|
115
|
+
// Continue the action
|
|
116
|
+
|
|
117
|
+
// Log the action
|
|
118
|
+
const teeLogService = runtime
|
|
119
|
+
.getService<ITeeLogService>(ServiceType.TEE_LOG)
|
|
120
|
+
.getInstance();
|
|
121
|
+
if (teeLogService.log(
|
|
122
|
+
runtime.agentId,
|
|
123
|
+
message.roomId,
|
|
124
|
+
message.userId,
|
|
125
|
+
"The type of the log, for example, Action:CONTINUE",
|
|
126
|
+
"The content that you want to log"
|
|
127
|
+
)
|
|
128
|
+
) {
|
|
129
|
+
console.log("Logged TEE log successfully");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Continue the action
|
|
133
|
+
}
|
|
134
|
+
```
|
|
229
135
|
|
|
230
|
-
|
|
136
|
+
After configuring the logging for the action, you can run the Eliza and see the logs through the client-direct REST API. See more details in the [Client-Direct REST API](../client-direct/src/README.md) documentation.
|
|
@@ -840,9 +840,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
840
840
|
}
|
|
841
841
|
});
|
|
842
842
|
|
|
843
|
-
// ../../node_modules/
|
|
843
|
+
// ../../node_modules/utf-8-validate/fallback.js
|
|
844
844
|
var require_fallback2 = __commonJS({
|
|
845
|
-
"../../node_modules/
|
|
845
|
+
"../../node_modules/utf-8-validate/fallback.js"(exports, module) {
|
|
846
846
|
"use strict";
|
|
847
847
|
function isValidUTF8(buf) {
|
|
848
848
|
const len = buf.length;
|
|
@@ -877,9 +877,9 @@ var require_fallback2 = __commonJS({
|
|
|
877
877
|
}
|
|
878
878
|
});
|
|
879
879
|
|
|
880
|
-
// ../../node_modules/
|
|
880
|
+
// ../../node_modules/utf-8-validate/index.js
|
|
881
881
|
var require_utf_8_validate = __commonJS({
|
|
882
|
-
"../../node_modules/
|
|
882
|
+
"../../node_modules/utf-8-validate/index.js"(exports, module) {
|
|
883
883
|
"use strict";
|
|
884
884
|
try {
|
|
885
885
|
module.exports = require_node_gyp_build2()(__dirname);
|
|
@@ -3910,4 +3910,4 @@ var WebSocket3 = (() => {
|
|
|
3910
3910
|
export {
|
|
3911
3911
|
WebSocket3 as WebSocket
|
|
3912
3912
|
};
|
|
3913
|
-
//# sourceMappingURL=_esm-
|
|
3913
|
+
//# sourceMappingURL=_esm-L4OBJJWB.js.map
|