@elizaos/plugin-tee 0.1.7-alpha.2 → 0.1.8-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,51 @@
1
- # Plugin TEE
1
+ # @elizaos/plugin-tee
2
2
 
3
- A plugin for handling Trusted Execution Environment (TEE) operations.
3
+ A plugin for handling Trusted Execution Environment (TEE) operations, providing secure key derivation and remote attestation capabilities.
4
4
 
5
- ## Providers
5
+ ## Overview
6
6
 
7
- This plugin includes several providers for handling different TEE-related operations.
7
+ This plugin provides functionality to:
8
8
 
9
- ### DeriveKeyProvider
9
+ - Generate secure keys within a TEE environment
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
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @elizaos/plugin-tee
19
+ ```
10
20
 
11
- The `DeriveKeyProvider` allows for secure key derivation within a TEE environment. It supports deriving keys for both Solana (Ed25519) and Ethereum (ECDSA) chains.
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
+ ```
12
30
 
13
- #### Usage
31
+ ## Usage
32
+
33
+ Import and register the plugin in your Eliza configuration:
34
+
35
+ ```typescript
36
+ import { teePlugin } from "@elizaos/plugin-tee";
37
+
38
+ export default {
39
+ plugins: [teePlugin],
40
+ // ... other configuration
41
+ };
42
+ ```
43
+
44
+ ## Features
45
+
46
+ ### DeriveKeyProvider
47
+
48
+ The `DeriveKeyProvider` allows for secure key derivation within a TEE environment:
14
49
 
15
50
  ```typescript
16
51
  import { DeriveKeyProvider } from "@elizaos/plugin-tee";
@@ -19,59 +54,52 @@ import { DeriveKeyProvider } from "@elizaos/plugin-tee";
19
54
  const provider = new DeriveKeyProvider();
20
55
 
21
56
  // Derive a raw key
22
- try {
23
- const rawKey = await provider.rawDeriveKey(
24
- "/path/to/derive",
25
- "subject-identifier"
26
- );
27
- // rawKey is a DeriveKeyResponse that can be used for further processing
28
- // to get the uint8Array do the following
29
- const rawKeyArray = rawKey.asUint8Array();
30
- } catch (error) {
31
- console.error("Raw key derivation failed:", error);
32
- }
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();
33
63
 
34
64
  // Derive a Solana keypair (Ed25519)
35
- try {
36
- const solanaKeypair = await provider.deriveEd25519Keypair(
37
- "/path/to/derive",
38
- "subject-identifier"
39
- );
40
- // solanaKeypair can now be used for Solana operations
41
- } catch (error) {
42
- console.error("Solana key derivation failed:", error);
43
- }
65
+ const solanaKeypair = await provider.deriveEd25519Keypair(
66
+ "/path/to/derive",
67
+ "subject-identifier"
68
+ );
44
69
 
45
70
  // Derive an Ethereum keypair (ECDSA)
46
- try {
47
- const evmKeypair = await provider.deriveEcdsaKeypair(
48
- "/path/to/derive",
49
- "subject-identifier"
50
- );
51
- // evmKeypair can now be used for Ethereum operations
52
- } catch (error) {
53
- console.error("EVM key derivation failed:", error);
54
- }
71
+ const evmKeypair = await provider.deriveEcdsaKeypair(
72
+ "/path/to/derive",
73
+ "subject-identifier"
74
+ );
55
75
  ```
56
76
 
57
77
  ### RemoteAttestationProvider
58
78
 
59
- The `RemoteAttestationProvider` allows for generating a remote attestation within a TEE environment.
60
-
61
- #### Usage
79
+ The `RemoteAttestationProvider` generates remote attestations within a TEE environment:
62
80
 
63
81
  ```typescript
82
+ import { RemoteAttestationProvider } from "@elizaos/plugin-tee";
83
+
64
84
  const provider = new RemoteAttestationProvider();
85
+ const attestation = await provider.generateAttestation("your-report-data");
86
+ ```
65
87
 
66
- try {
67
- const attestation = await provider.generateAttestation("your-report-data");
68
- console.log("Attestation:", attestation);
69
- } catch (error) {
70
- console.error("Failed to generate attestation:", error);
71
- }
88
+ ## Development
89
+
90
+ ### Building
91
+
92
+ ```bash
93
+ npm run build
94
+ ```
95
+
96
+ ### Testing
97
+
98
+ ```bash
99
+ npm run test
72
100
  ```
73
101
 
74
- ### Configuration
102
+ ## Local Development
75
103
 
76
104
  To get a TEE simulator for local testing, use the following commands:
77
105
 
@@ -81,9 +109,122 @@ docker pull phalanetwork/tappd-simulator:latest
81
109
  docker run --rm -p 8090:8090 phalanetwork/tappd-simulator:latest
82
110
  ```
83
111
 
84
- When using the provider through the runtime environment, ensure the following settings are configured:
112
+ ## Dependencies
85
113
 
86
- ```env
87
- DSTACK_SIMULATOR_ENDPOINT="your-endpoint-url" # Optional, for simulator purposes if testing on mac or windows
88
- WALLET_SECRET_SALT=your-secret-salt // Required to single agent deployments
114
+ - `@phala/dstack-sdk`: Core TEE functionality
115
+ - `@solana/web3.js`: Solana blockchain interaction
116
+ - `viem`: Ethereum interaction library
117
+ - Other standard dependencies listed in package.json
118
+
119
+ ## API Reference
120
+
121
+ ### Providers
122
+
123
+ - `deriveKeyProvider`: Manages secure key derivation within TEE
124
+ - `remoteAttestationProvider`: Handles generation of remote attestation quotes
125
+ - `walletProvider`: Manages wallet interactions with TEE-derived keys
126
+
127
+ ### Types
128
+
129
+ ```typescript
130
+ enum TEEMode {
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
+ }
89
141
  ```
142
+
143
+ ## Future Enhancements
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
153
+
154
+ 2. **Remote Attestation**
155
+
156
+ - Enhanced quote verification
157
+ - Multiple TEE provider support
158
+ - Automated attestation renewal
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:
222
+
223
+ - [Phala Documentation](https://docs.phala.network/)
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)
227
+
228
+ ## License
229
+
230
+ This plugin is part of the Eliza project. See the main project repository for license information.
package/package.json CHANGED
@@ -1,29 +1,41 @@
1
1
  {
2
- "name": "@elizaos/plugin-tee",
3
- "version": "0.1.7-alpha.2",
4
- "main": "dist/index.js",
5
- "type": "module",
6
- "types": "dist/index.d.ts",
7
- "dependencies": {
8
- "@elizaos/core": "0.1.7-alpha.2",
9
- "@phala/dstack-sdk": "0.1.6",
10
- "@solana/spl-token": "0.4.9",
11
- "@solana/web3.js": "1.95.8",
12
- "bignumber": "1.1.0",
13
- "bignumber.js": "9.1.2",
14
- "bs58": "6.0.0",
15
- "node-cache": "5.1.2",
16
- "pumpdotfun-sdk": "1.3.2",
17
- "tsup": "8.3.5",
18
- "viem": "2.21.53"
19
- },
20
- "scripts": {
21
- "build": "tsup --format esm --dts",
22
- "dev": "tsup --format esm --dts --watch",
23
- "lint": "eslint --fix --cache ."
24
- },
25
- "peerDependencies": {
26
- "whatwg-url": "7.1.0"
27
- },
28
- "gitHead": "256e6634696074cdb38f3f79bc383fed04376688"
2
+ "name": "@elizaos/plugin-tee",
3
+ "version": "0.1.8-alpha.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": {
12
+ "@elizaos/source": "./src/index.ts",
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "dependencies": {
22
+ "@elizaos/core": "0.1.8-alpha.1",
23
+ "@phala/dstack-sdk": "0.1.7",
24
+ "@solana/spl-token": "0.4.9",
25
+ "@solana/web3.js": "1.95.8",
26
+ "bignumber.js": "9.1.2",
27
+ "bs58": "6.0.0",
28
+ "node-cache": "5.1.2",
29
+ "pumpdotfun-sdk": "1.3.2",
30
+ "tsup": "8.3.5"
31
+ },
32
+ "scripts": {
33
+ "build": "tsup --format esm --dts",
34
+ "dev": "tsup --format esm --dts --watch",
35
+ "lint": "eslint --fix --cache ."
36
+ },
37
+ "peerDependencies": {
38
+ "whatwg-url": "7.1.0"
39
+ },
40
+ "gitHead": "d5f2924d866c21b54543637b694695bd1f410621"
29
41
  }
package/dist/index.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import { Plugin } from '@elizaos/core';
2
- import { Keypair } from '@solana/web3.js';
3
- import { DeriveKeyResponse } from '@phala/dstack-sdk';
4
- import { PrivateKeyAccount } from 'viem';
5
-
6
- declare enum TEEMode {
7
- OFF = "OFF",
8
- LOCAL = "LOCAL",// For local development with simulator
9
- DOCKER = "DOCKER",// For docker development with simulator
10
- PRODUCTION = "PRODUCTION"
11
- }
12
- interface RemoteAttestationQuote {
13
- quote: string;
14
- timestamp: number;
15
- }
16
-
17
- declare class DeriveKeyProvider {
18
- private client;
19
- private raProvider;
20
- constructor(teeMode?: string);
21
- private generateDeriveKeyAttestation;
22
- rawDeriveKey(path: string, subject: string): Promise<DeriveKeyResponse>;
23
- deriveEd25519Keypair(path: string, subject: string, agentId: string): Promise<{
24
- keypair: Keypair;
25
- attestation: RemoteAttestationQuote;
26
- }>;
27
- deriveEcdsaKeypair(path: string, subject: string, agentId: string): Promise<{
28
- keypair: PrivateKeyAccount;
29
- attestation: RemoteAttestationQuote;
30
- }>;
31
- }
32
-
33
- declare class RemoteAttestationProvider {
34
- private client;
35
- constructor(teeMode?: string);
36
- generateAttestation(reportData: string): Promise<RemoteAttestationQuote>;
37
- }
38
-
39
- declare const teePlugin: Plugin;
40
-
41
- export { DeriveKeyProvider, RemoteAttestationProvider, type RemoteAttestationQuote, TEEMode, teePlugin };
package/dist/index.js DELETED
@@ -1,265 +0,0 @@
1
- // src/providers/remoteAttestationProvider.ts
2
- import { TappdClient } from "@phala/dstack-sdk";
3
-
4
- // src/types/tee.ts
5
- var TEEMode = /* @__PURE__ */ ((TEEMode2) => {
6
- TEEMode2["OFF"] = "OFF";
7
- TEEMode2["LOCAL"] = "LOCAL";
8
- TEEMode2["DOCKER"] = "DOCKER";
9
- TEEMode2["PRODUCTION"] = "PRODUCTION";
10
- return TEEMode2;
11
- })(TEEMode || {});
12
-
13
- // src/providers/remoteAttestationProvider.ts
14
- var RemoteAttestationProvider = class {
15
- client;
16
- constructor(teeMode) {
17
- let endpoint;
18
- switch (teeMode) {
19
- case "LOCAL" /* LOCAL */:
20
- endpoint = "http://localhost:8090";
21
- console.log(
22
- "TEE: Connecting to local simulator at localhost:8090"
23
- );
24
- break;
25
- case "DOCKER" /* DOCKER */:
26
- endpoint = "http://host.docker.internal:8090";
27
- console.log(
28
- "TEE: Connecting to simulator via Docker at host.docker.internal:8090"
29
- );
30
- break;
31
- case "PRODUCTION" /* PRODUCTION */:
32
- endpoint = void 0;
33
- console.log(
34
- "TEE: Running in production mode without simulator"
35
- );
36
- break;
37
- default:
38
- throw new Error(
39
- `Invalid TEE_MODE: ${teeMode}. Must be one of: LOCAL, DOCKER, PRODUCTION`
40
- );
41
- }
42
- this.client = endpoint ? new TappdClient(endpoint) : new TappdClient();
43
- }
44
- async generateAttestation(reportData) {
45
- try {
46
- console.log("Generating attestation for: ", reportData);
47
- const tdxQuote = await this.client.tdxQuote(reportData);
48
- const rtmrs = tdxQuote.replayRtmrs();
49
- console.log(
50
- `rtmr0: ${rtmrs[0]}
51
- rtmr1: ${rtmrs[1]}
52
- rtmr2: ${rtmrs[2]}
53
- rtmr3: ${rtmrs[3]}f`
54
- );
55
- const quote = {
56
- quote: tdxQuote.quote,
57
- timestamp: Date.now()
58
- };
59
- console.log("Remote attestation quote: ", quote);
60
- return quote;
61
- } catch (error) {
62
- console.error("Error generating remote attestation:", error);
63
- throw new Error(
64
- `Failed to generate TDX Quote: ${error instanceof Error ? error.message : "Unknown error"}`
65
- );
66
- }
67
- }
68
- };
69
- var remoteAttestationProvider = {
70
- get: async (runtime, _message, _state) => {
71
- const teeMode = runtime.getSetting("TEE_MODE");
72
- const provider = new RemoteAttestationProvider(teeMode);
73
- const agentId = runtime.agentId;
74
- try {
75
- console.log("Generating attestation for: ", agentId);
76
- const attestation = await provider.generateAttestation(agentId);
77
- return `Your Agent's remote attestation is: ${JSON.stringify(attestation)}`;
78
- } catch (error) {
79
- console.error("Error in remote attestation provider:", error);
80
- throw new Error(
81
- `Failed to generate TDX Quote: ${error instanceof Error ? error.message : "Unknown error"}`
82
- );
83
- }
84
- }
85
- };
86
-
87
- // src/providers/deriveKeyProvider.ts
88
- import { Keypair } from "@solana/web3.js";
89
- import crypto from "crypto";
90
- import { TappdClient as TappdClient2 } from "@phala/dstack-sdk";
91
- import { privateKeyToAccount } from "viem/accounts";
92
- import { keccak256 } from "viem";
93
- var DeriveKeyProvider = class {
94
- client;
95
- raProvider;
96
- constructor(teeMode) {
97
- let endpoint;
98
- switch (teeMode) {
99
- case "LOCAL" /* LOCAL */:
100
- endpoint = "http://localhost:8090";
101
- console.log(
102
- "TEE: Connecting to local simulator at localhost:8090"
103
- );
104
- break;
105
- case "DOCKER" /* DOCKER */:
106
- endpoint = "http://host.docker.internal:8090";
107
- console.log(
108
- "TEE: Connecting to simulator via Docker at host.docker.internal:8090"
109
- );
110
- break;
111
- case "PRODUCTION" /* PRODUCTION */:
112
- endpoint = void 0;
113
- console.log(
114
- "TEE: Running in production mode without simulator"
115
- );
116
- break;
117
- default:
118
- throw new Error(
119
- `Invalid TEE_MODE: ${teeMode}. Must be one of: LOCAL, DOCKER, PRODUCTION`
120
- );
121
- }
122
- this.client = endpoint ? new TappdClient2(endpoint) : new TappdClient2();
123
- this.raProvider = new RemoteAttestationProvider(teeMode);
124
- }
125
- async generateDeriveKeyAttestation(agentId, publicKey) {
126
- const deriveKeyData = {
127
- agentId,
128
- publicKey
129
- };
130
- const reportdata = JSON.stringify(deriveKeyData);
131
- console.log("Generating Remote Attestation Quote for Derive Key...");
132
- const quote = await this.raProvider.generateAttestation(reportdata);
133
- console.log("Remote Attestation Quote generated successfully!");
134
- return quote;
135
- }
136
- async rawDeriveKey(path, subject) {
137
- try {
138
- if (!path || !subject) {
139
- console.error(
140
- "Path and Subject are required for key derivation"
141
- );
142
- }
143
- console.log("Deriving Raw Key in TEE...");
144
- const derivedKey = await this.client.deriveKey(path, subject);
145
- console.log("Raw Key Derived Successfully!");
146
- return derivedKey;
147
- } catch (error) {
148
- console.error("Error deriving raw key:", error);
149
- throw error;
150
- }
151
- }
152
- async deriveEd25519Keypair(path, subject, agentId) {
153
- try {
154
- if (!path || !subject) {
155
- console.error(
156
- "Path and Subject are required for key derivation"
157
- );
158
- }
159
- console.log("Deriving Key in TEE...");
160
- const derivedKey = await this.client.deriveKey(path, subject);
161
- const uint8ArrayDerivedKey = derivedKey.asUint8Array();
162
- const hash = crypto.createHash("sha256");
163
- hash.update(uint8ArrayDerivedKey);
164
- const seed = hash.digest();
165
- const seedArray = new Uint8Array(seed);
166
- const keypair = Keypair.fromSeed(seedArray.slice(0, 32));
167
- const attestation = await this.generateDeriveKeyAttestation(
168
- agentId,
169
- keypair.publicKey.toBase58()
170
- );
171
- console.log("Key Derived Successfully!");
172
- return { keypair, attestation };
173
- } catch (error) {
174
- console.error("Error deriving key:", error);
175
- throw error;
176
- }
177
- }
178
- async deriveEcdsaKeypair(path, subject, agentId) {
179
- try {
180
- if (!path || !subject) {
181
- console.error(
182
- "Path and Subject are required for key derivation"
183
- );
184
- }
185
- console.log("Deriving ECDSA Key in TEE...");
186
- const deriveKeyResponse = await this.client.deriveKey(path, subject);
187
- const hex = keccak256(deriveKeyResponse.asUint8Array());
188
- const keypair = privateKeyToAccount(hex);
189
- const attestation = await this.generateDeriveKeyAttestation(
190
- agentId,
191
- keypair.address
192
- );
193
- console.log("ECDSA Key Derived Successfully!");
194
- return { keypair, attestation };
195
- } catch (error) {
196
- console.error("Error deriving ecdsa key:", error);
197
- throw error;
198
- }
199
- }
200
- };
201
- var deriveKeyProvider = {
202
- get: async (runtime, _message, _state) => {
203
- const teeMode = runtime.getSetting("TEE_MODE");
204
- const provider = new DeriveKeyProvider(teeMode);
205
- const agentId = runtime.agentId;
206
- try {
207
- if (!runtime.getSetting("WALLET_SECRET_SALT")) {
208
- console.error(
209
- "Wallet secret salt is not configured in settings"
210
- );
211
- return "";
212
- }
213
- try {
214
- const secretSalt = runtime.getSetting("WALLET_SECRET_SALT") || "secret_salt";
215
- const solanaKeypair = await provider.deriveEd25519Keypair(
216
- "/",
217
- secretSalt,
218
- agentId
219
- );
220
- const evmKeypair = await provider.deriveEcdsaKeypair(
221
- "/",
222
- secretSalt,
223
- agentId
224
- );
225
- return JSON.stringify({
226
- solana: solanaKeypair.keypair.publicKey,
227
- evm: evmKeypair.keypair.address
228
- });
229
- } catch (error) {
230
- console.error("Error creating PublicKey:", error);
231
- return "";
232
- }
233
- } catch (error) {
234
- console.error("Error in derive key provider:", error.message);
235
- return `Failed to fetch derive key information: ${error instanceof Error ? error.message : "Unknown error"}`;
236
- }
237
- }
238
- };
239
-
240
- // src/index.ts
241
- var teePlugin = {
242
- name: "tee",
243
- description: "TEE plugin with actions to generate remote attestations and derive keys",
244
- actions: [
245
- /* custom actions */
246
- ],
247
- evaluators: [
248
- /* custom evaluators */
249
- ],
250
- providers: [
251
- /* custom providers */
252
- remoteAttestationProvider,
253
- deriveKeyProvider
254
- ],
255
- services: [
256
- /* custom services */
257
- ]
258
- };
259
- export {
260
- DeriveKeyProvider,
261
- RemoteAttestationProvider,
262
- TEEMode,
263
- teePlugin
264
- };
265
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/providers/remoteAttestationProvider.ts","../src/types/tee.ts","../src/providers/deriveKeyProvider.ts","../src/index.ts"],"sourcesContent":["import { IAgentRuntime, Memory, Provider, State } from \"@elizaos/core\";\nimport { TdxQuoteResponse, TappdClient } from \"@phala/dstack-sdk\";\nimport { RemoteAttestationQuote, TEEMode } from \"../types/tee\";\n\nclass RemoteAttestationProvider {\n private client: TappdClient;\n\n constructor(teeMode?: string) {\n let endpoint: string | undefined;\n\n // Both LOCAL and DOCKER modes use the simulator, just with different endpoints\n switch (teeMode) {\n case TEEMode.LOCAL:\n endpoint = \"http://localhost:8090\";\n console.log(\n \"TEE: Connecting to local simulator at localhost:8090\"\n );\n break;\n case TEEMode.DOCKER:\n endpoint = \"http://host.docker.internal:8090\";\n console.log(\n \"TEE: Connecting to simulator via Docker at host.docker.internal:8090\"\n );\n break;\n case TEEMode.PRODUCTION:\n endpoint = undefined;\n console.log(\n \"TEE: Running in production mode without simulator\"\n );\n break;\n default:\n throw new Error(\n `Invalid TEE_MODE: ${teeMode}. Must be one of: LOCAL, DOCKER, PRODUCTION`\n );\n }\n\n this.client = endpoint ? new TappdClient(endpoint) : new TappdClient();\n }\n\n async generateAttestation(\n reportData: string\n ): Promise<RemoteAttestationQuote> {\n try {\n console.log(\"Generating attestation for: \", reportData);\n const tdxQuote: TdxQuoteResponse =\n await this.client.tdxQuote(reportData);\n const rtmrs = tdxQuote.replayRtmrs();\n console.log(\n `rtmr0: ${rtmrs[0]}\\nrtmr1: ${rtmrs[1]}\\nrtmr2: ${rtmrs[2]}\\nrtmr3: ${rtmrs[3]}f`\n );\n const quote: RemoteAttestationQuote = {\n quote: tdxQuote.quote,\n timestamp: Date.now(),\n };\n console.log(\"Remote attestation quote: \", quote);\n return quote;\n } catch (error) {\n console.error(\"Error generating remote attestation:\", error);\n throw new Error(\n `Failed to generate TDX Quote: ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`\n );\n }\n }\n}\n\n// Keep the original provider for backwards compatibility\nconst remoteAttestationProvider: Provider = {\n get: async (runtime: IAgentRuntime, _message: Memory, _state?: State) => {\n const teeMode = runtime.getSetting(\"TEE_MODE\");\n const provider = new RemoteAttestationProvider(teeMode);\n const agentId = runtime.agentId;\n\n try {\n console.log(\"Generating attestation for: \", agentId);\n const attestation = await provider.generateAttestation(agentId);\n return `Your Agent's remote attestation is: ${JSON.stringify(attestation)}`;\n } catch (error) {\n console.error(\"Error in remote attestation provider:\", error);\n throw new Error(\n `Failed to generate TDX Quote: ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`\n );\n }\n },\n};\n\nexport { remoteAttestationProvider, RemoteAttestationProvider };\n","export enum TEEMode {\n OFF = \"OFF\",\n LOCAL = \"LOCAL\", // For local development with simulator\n DOCKER = \"DOCKER\", // For docker development with simulator\n PRODUCTION = \"PRODUCTION\" // For production without simulator\n}\n\nexport interface RemoteAttestationQuote {\n quote: string;\n timestamp: number;\n}","import { IAgentRuntime, Memory, Provider, State } from \"@elizaos/core\";\nimport { Keypair } from \"@solana/web3.js\";\nimport crypto from \"crypto\";\nimport { DeriveKeyResponse, TappdClient } from \"@phala/dstack-sdk\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport { PrivateKeyAccount, keccak256 } from \"viem\";\nimport { RemoteAttestationProvider } from \"./remoteAttestationProvider\";\nimport { TEEMode, RemoteAttestationQuote } from \"../types/tee\";\n\ninterface DeriveKeyAttestationData {\n agentId: string;\n publicKey: string;\n}\n\nclass DeriveKeyProvider {\n private client: TappdClient;\n private raProvider: RemoteAttestationProvider;\n\n constructor(teeMode?: string) {\n let endpoint: string | undefined;\n\n // Both LOCAL and DOCKER modes use the simulator, just with different endpoints\n switch (teeMode) {\n case TEEMode.LOCAL:\n endpoint = \"http://localhost:8090\";\n console.log(\n \"TEE: Connecting to local simulator at localhost:8090\"\n );\n break;\n case TEEMode.DOCKER:\n endpoint = \"http://host.docker.internal:8090\";\n console.log(\n \"TEE: Connecting to simulator via Docker at host.docker.internal:8090\"\n );\n break;\n case TEEMode.PRODUCTION:\n endpoint = undefined;\n console.log(\n \"TEE: Running in production mode without simulator\"\n );\n break;\n default:\n throw new Error(\n `Invalid TEE_MODE: ${teeMode}. Must be one of: LOCAL, DOCKER, PRODUCTION`\n );\n }\n\n this.client = endpoint ? new TappdClient(endpoint) : new TappdClient();\n this.raProvider = new RemoteAttestationProvider(teeMode);\n }\n\n private async generateDeriveKeyAttestation(\n agentId: string,\n publicKey: string\n ): Promise<RemoteAttestationQuote> {\n const deriveKeyData: DeriveKeyAttestationData = {\n agentId,\n publicKey,\n };\n const reportdata = JSON.stringify(deriveKeyData);\n console.log(\"Generating Remote Attestation Quote for Derive Key...\");\n const quote = await this.raProvider.generateAttestation(reportdata);\n console.log(\"Remote Attestation Quote generated successfully!\");\n return quote;\n }\n\n async rawDeriveKey(\n path: string,\n subject: string\n ): Promise<DeriveKeyResponse> {\n try {\n if (!path || !subject) {\n console.error(\n \"Path and Subject are required for key derivation\"\n );\n }\n\n console.log(\"Deriving Raw Key in TEE...\");\n const derivedKey = await this.client.deriveKey(path, subject);\n\n console.log(\"Raw Key Derived Successfully!\");\n return derivedKey;\n } catch (error) {\n console.error(\"Error deriving raw key:\", error);\n throw error;\n }\n }\n\n async deriveEd25519Keypair(\n path: string,\n subject: string,\n agentId: string\n ): Promise<{ keypair: Keypair; attestation: RemoteAttestationQuote }> {\n try {\n if (!path || !subject) {\n console.error(\n \"Path and Subject are required for key derivation\"\n );\n }\n\n console.log(\"Deriving Key in TEE...\");\n const derivedKey = await this.client.deriveKey(path, subject);\n const uint8ArrayDerivedKey = derivedKey.asUint8Array();\n\n const hash = crypto.createHash(\"sha256\");\n hash.update(uint8ArrayDerivedKey);\n const seed = hash.digest();\n const seedArray = new Uint8Array(seed);\n const keypair = Keypair.fromSeed(seedArray.slice(0, 32));\n\n // Generate an attestation for the derived key data for public to verify\n const attestation = await this.generateDeriveKeyAttestation(\n agentId,\n keypair.publicKey.toBase58()\n );\n console.log(\"Key Derived Successfully!\");\n\n return { keypair, attestation };\n } catch (error) {\n console.error(\"Error deriving key:\", error);\n throw error;\n }\n }\n\n async deriveEcdsaKeypair(\n path: string,\n subject: string,\n agentId: string\n ): Promise<{\n keypair: PrivateKeyAccount;\n attestation: RemoteAttestationQuote;\n }> {\n try {\n if (!path || !subject) {\n console.error(\n \"Path and Subject are required for key derivation\"\n );\n }\n\n console.log(\"Deriving ECDSA Key in TEE...\");\n const deriveKeyResponse: DeriveKeyResponse =\n await this.client.deriveKey(path, subject);\n const hex = keccak256(deriveKeyResponse.asUint8Array());\n const keypair: PrivateKeyAccount = privateKeyToAccount(hex);\n\n // Generate an attestation for the derived key data for public to verify\n const attestation = await this.generateDeriveKeyAttestation(\n agentId,\n keypair.address\n );\n console.log(\"ECDSA Key Derived Successfully!\");\n\n return { keypair, attestation };\n } catch (error) {\n console.error(\"Error deriving ecdsa key:\", error);\n throw error;\n }\n }\n}\n\nconst deriveKeyProvider: Provider = {\n get: async (runtime: IAgentRuntime, _message?: Memory, _state?: State) => {\n const teeMode = runtime.getSetting(\"TEE_MODE\");\n const provider = new DeriveKeyProvider(teeMode);\n const agentId = runtime.agentId;\n try {\n // Validate wallet configuration\n if (!runtime.getSetting(\"WALLET_SECRET_SALT\")) {\n console.error(\n \"Wallet secret salt is not configured in settings\"\n );\n return \"\";\n }\n\n try {\n const secretSalt =\n runtime.getSetting(\"WALLET_SECRET_SALT\") || \"secret_salt\";\n const solanaKeypair = await provider.deriveEd25519Keypair(\n \"/\",\n secretSalt,\n agentId\n );\n const evmKeypair = await provider.deriveEcdsaKeypair(\n \"/\",\n secretSalt,\n agentId\n );\n return JSON.stringify({\n solana: solanaKeypair.keypair.publicKey,\n evm: evmKeypair.keypair.address,\n });\n } catch (error) {\n console.error(\"Error creating PublicKey:\", error);\n return \"\";\n }\n } catch (error) {\n console.error(\"Error in derive key provider:\", error.message);\n return `Failed to fetch derive key information: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n },\n};\n\nexport { deriveKeyProvider, DeriveKeyProvider };\n","import { Plugin } from \"@elizaos/core\";\nimport { remoteAttestationProvider } from \"./providers/remoteAttestationProvider\";\nimport { deriveKeyProvider } from \"./providers/deriveKeyProvider\";\n\nexport { DeriveKeyProvider } from \"./providers/deriveKeyProvider\";\nexport { RemoteAttestationProvider } from \"./providers/remoteAttestationProvider\";\nexport { RemoteAttestationQuote, TEEMode } from \"./types/tee\";\n\nexport const teePlugin: Plugin = {\n name: \"tee\",\n description:\n \"TEE plugin with actions to generate remote attestations and derive keys\",\n actions: [\n /* custom actions */\n ],\n evaluators: [\n /* custom evaluators */\n ],\n providers: [\n /* custom providers */\n remoteAttestationProvider,\n deriveKeyProvider,\n ],\n services: [\n /* custom services */\n ],\n};\n"],"mappings":";AACA,SAA2B,mBAAmB;;;ACDvC,IAAK,UAAL,kBAAKA,aAAL;AACH,EAAAA,SAAA,SAAM;AACN,EAAAA,SAAA,WAAQ;AACR,EAAAA,SAAA,YAAS;AACT,EAAAA,SAAA,gBAAa;AAJL,SAAAA;AAAA,GAAA;;;ADIZ,IAAM,4BAAN,MAAgC;AAAA,EACpB;AAAA,EAER,YAAY,SAAkB;AAC1B,QAAI;AAGJ,YAAQ,SAAS;AAAA,MACb;AACI,mBAAW;AACX,gBAAQ;AAAA,UACJ;AAAA,QACJ;AACA;AAAA,MACJ;AACI,mBAAW;AACX,gBAAQ;AAAA,UACJ;AAAA,QACJ;AACA;AAAA,MACJ;AACI,mBAAW;AACX,gBAAQ;AAAA,UACJ;AAAA,QACJ;AACA;AAAA,MACJ;AACI,cAAM,IAAI;AAAA,UACN,qBAAqB,OAAO;AAAA,QAChC;AAAA,IACR;AAEA,SAAK,SAAS,WAAW,IAAI,YAAY,QAAQ,IAAI,IAAI,YAAY;AAAA,EACzE;AAAA,EAEA,MAAM,oBACF,YAC+B;AAC/B,QAAI;AACA,cAAQ,IAAI,gCAAgC,UAAU;AACtD,YAAM,WACF,MAAM,KAAK,OAAO,SAAS,UAAU;AACzC,YAAM,QAAQ,SAAS,YAAY;AACnC,cAAQ;AAAA,QACJ,UAAU,MAAM,CAAC,CAAC;AAAA,SAA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A,UACA;AAAA,UACA;AAAA,QACJ;AACA,cAAM,aAAa,MAAM,SAAS;AAAA,UAC9B;AAAA,UACA;AAAA,UACA;AAAA,QACJ;AACA,eAAO,KAAK,UAAU;AAAA,UAClB,QAAQ,cAAc,QAAQ;AAAA,UAC9B,KAAK,WAAW,QAAQ;AAAA,QAC5B,CAAC;AAAA,MACL,SAAS,OAAO;AACZ,gBAAQ,MAAM,6BAA6B,KAAK;AAChD,eAAO;AAAA,MACX;AAAA,IACJ,SAAS,OAAO;AACZ,cAAQ,MAAM,iCAAiC,MAAM,OAAO;AAC5D,aAAO,2CAA2C,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,IAC9G;AAAA,EACJ;AACJ;;;AChMO,IAAM,YAAoB;AAAA,EAC7B,MAAM;AAAA,EACN,aACI;AAAA,EACJ,SAAS;AAAA;AAAA,EAET;AAAA,EACA,YAAY;AAAA;AAAA,EAEZ;AAAA,EACA,WAAW;AAAA;AAAA,IAEP;AAAA,IACA;AAAA,EACJ;AAAA,EACA,UAAU;AAAA;AAAA,EAEV;AACJ;","names":["TEEMode","TappdClient","TappdClient"]}
package/tsup.config.ts DELETED
@@ -1,28 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- outDir: "dist",
6
- sourcemap: true,
7
- clean: true,
8
- format: ["esm"], // Ensure you're targeting CommonJS
9
- external: [
10
- "dotenv", // Externalize dotenv to prevent bundling
11
- "fs", // Externalize fs to use Node.js built-in module
12
- "path", // Externalize other built-ins if necessary
13
- "@reflink/reflink",
14
- "@node-llama-cpp",
15
- "https",
16
- "http",
17
- "agentkeepalive",
18
- // Add other modules you want to externalize
19
- "@phala/dstack-sdk",
20
- "safe-buffer",
21
- "base-x",
22
- "bs58",
23
- "borsh",
24
- "@solana/buffer-layout",
25
- "stream",
26
- "buffer",
27
- ],
28
- });