@elizaos/plugin-tee 2.0.3-beta.5 → 2.0.3-beta.7

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.
Files changed (39) hide show
  1. package/dist/index.js +465 -0
  2. package/dist/index.js.map +19 -0
  3. package/dist/node/index.d.ts +9 -0
  4. package/dist/node/index.d.ts.map +1 -0
  5. package/dist/node/index.js +38 -0
  6. package/dist/node/providers/base.d.ts +8 -0
  7. package/dist/node/providers/base.d.ts.map +1 -0
  8. package/dist/node/providers/base.js +4 -0
  9. package/dist/node/providers/deriveKey.d.ts +24 -0
  10. package/dist/node/providers/deriveKey.d.ts.map +1 -0
  11. package/dist/node/providers/deriveKey.js +145 -0
  12. package/dist/node/providers/index.d.ts +4 -0
  13. package/dist/node/providers/index.d.ts.map +1 -0
  14. package/dist/node/providers/index.js +3 -0
  15. package/dist/node/providers/remoteAttestation.d.ts +10 -0
  16. package/dist/node/providers/remoteAttestation.d.ts.map +1 -0
  17. package/dist/node/providers/remoteAttestation.js +77 -0
  18. package/dist/node/services/index.d.ts +2 -0
  19. package/dist/node/services/index.d.ts.map +1 -0
  20. package/dist/node/services/index.js +1 -0
  21. package/dist/node/services/tee.d.ts +24 -0
  22. package/dist/node/services/tee.d.ts.map +1 -0
  23. package/dist/node/services/tee.js +42 -0
  24. package/dist/node/types/index.d.ts +59 -0
  25. package/dist/node/types/index.d.ts.map +1 -0
  26. package/dist/node/types/index.js +35 -0
  27. package/dist/node/utils/index.d.ts +9 -0
  28. package/dist/node/utils/index.d.ts.map +1 -0
  29. package/dist/node/utils/index.js +61 -0
  30. package/dist/node/vendors/index.d.ts +5 -0
  31. package/dist/node/vendors/index.d.ts.map +1 -0
  32. package/dist/node/vendors/index.js +14 -0
  33. package/dist/node/vendors/phala.d.ts +10 -0
  34. package/dist/node/vendors/phala.d.ts.map +1 -0
  35. package/dist/node/vendors/phala.js +17 -0
  36. package/dist/node/vendors/types.d.ts +13 -0
  37. package/dist/node/vendors/types.d.ts.map +1 -0
  38. package/dist/node/vendors/types.js +3 -0
  39. package/package.json +8 -8
@@ -0,0 +1,145 @@
1
+ import crypto from "node:crypto";
2
+ import { logger, } from "@elizaos/core";
3
+ import { TappdClient, } from "@phala/dstack-sdk";
4
+ import { Keypair } from "@solana/web3.js";
5
+ import { keccak256 } from "viem";
6
+ import { privateKeyToAccount } from "viem/accounts";
7
+ import { getTeeEndpoint } from "../utils";
8
+ import { DeriveKeyProvider } from "./base";
9
+ import { PhalaRemoteAttestationProvider } from "./remoteAttestation";
10
+ export class PhalaDeriveKeyProvider extends DeriveKeyProvider {
11
+ client;
12
+ raProvider;
13
+ constructor(teeMode) {
14
+ super();
15
+ const endpoint = getTeeEndpoint(teeMode);
16
+ logger.info(endpoint
17
+ ? `TEE: Connecting to key derivation service at ${endpoint}`
18
+ : "TEE: Running key derivation in production mode");
19
+ this.client = endpoint ? new TappdClient(endpoint) : new TappdClient();
20
+ this.raProvider = new PhalaRemoteAttestationProvider(teeMode);
21
+ }
22
+ async generateDeriveKeyAttestation(agentId, publicKey, subject) {
23
+ const deriveKeyData = {
24
+ agentId,
25
+ publicKey,
26
+ subject,
27
+ };
28
+ return this.raProvider.generateAttestation(JSON.stringify(deriveKeyData));
29
+ }
30
+ async rawDeriveKey(path, subject) {
31
+ if (!path || !subject) {
32
+ throw new Error("Path and subject are required for key derivation");
33
+ }
34
+ try {
35
+ const response = await this.client.deriveKey(path, subject);
36
+ return {
37
+ key: response.asUint8Array(),
38
+ certificateChain: [],
39
+ };
40
+ }
41
+ catch (error) {
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ logger.error(`Error deriving raw key: ${message}`);
44
+ throw error;
45
+ }
46
+ }
47
+ async rawDeriveKeyResponse(path, subject) {
48
+ if (!path || !subject) {
49
+ throw new Error("Path and subject are required for key derivation");
50
+ }
51
+ return this.client.deriveKey(path, subject);
52
+ }
53
+ async deriveEd25519Keypair(path, subject, agentId) {
54
+ if (!path || !subject) {
55
+ throw new Error("Path and subject are required for key derivation");
56
+ }
57
+ try {
58
+ const derivedKey = await this.client.deriveKey(path, subject);
59
+ const uint8ArrayDerivedKey = derivedKey.asUint8Array();
60
+ const hash = crypto.createHash("sha256");
61
+ hash.update(uint8ArrayDerivedKey);
62
+ const seed = new Uint8Array(hash.digest());
63
+ const keypair = Keypair.fromSeed(seed.slice(0, 32));
64
+ const attestation = await this.generateDeriveKeyAttestation(agentId, keypair.publicKey.toBase58(), subject);
65
+ return { keypair, attestation };
66
+ }
67
+ catch (error) {
68
+ const message = error instanceof Error ? error.message : String(error);
69
+ logger.error(`Error deriving Ed25519 key: ${message}`);
70
+ throw error;
71
+ }
72
+ }
73
+ async deriveEcdsaKeypair(path, subject, agentId) {
74
+ if (!path || !subject) {
75
+ throw new Error("Path and subject are required for key derivation");
76
+ }
77
+ try {
78
+ const derivedKey = await this.client.deriveKey(path, subject);
79
+ const hex = keccak256(derivedKey.asUint8Array());
80
+ const keypair = privateKeyToAccount(hex);
81
+ const attestation = await this.generateDeriveKeyAttestation(agentId, keypair.address, subject);
82
+ return { keypair, attestation };
83
+ }
84
+ catch (error) {
85
+ const message = error instanceof Error ? error.message : String(error);
86
+ logger.error(`Error deriving ECDSA key: ${message}`);
87
+ throw error;
88
+ }
89
+ }
90
+ }
91
+ export const phalaDeriveKeyProvider = {
92
+ name: "phala-derive-key",
93
+ dynamic: true,
94
+ contexts: ["secrets", "agent_internal"],
95
+ contextGate: { anyOf: ["secrets", "agent_internal"] },
96
+ cacheStable: false,
97
+ cacheScope: "turn",
98
+ get: async (runtime, _message) => {
99
+ const teeModeRaw = runtime.getSetting("TEE_MODE");
100
+ if (!teeModeRaw) {
101
+ return {
102
+ values: {},
103
+ text: "TEE_MODE is not configured",
104
+ };
105
+ }
106
+ const teeMode = typeof teeModeRaw === "string" ? teeModeRaw : String(teeModeRaw);
107
+ const secretSaltRaw = runtime.getSetting("WALLET_SECRET_SALT");
108
+ if (!secretSaltRaw) {
109
+ logger.error("WALLET_SECRET_SALT is not configured");
110
+ return {
111
+ values: {},
112
+ text: "WALLET_SECRET_SALT is not configured in settings",
113
+ };
114
+ }
115
+ const secretSalt = typeof secretSaltRaw === "string" ? secretSaltRaw : String(secretSaltRaw);
116
+ const provider = new PhalaDeriveKeyProvider(teeMode);
117
+ const agentId = runtime.agentId;
118
+ try {
119
+ const solanaKeypair = await provider.deriveEd25519Keypair(secretSalt, "solana", agentId);
120
+ const evmKeypair = await provider.deriveEcdsaKeypair(secretSalt, "evm", agentId);
121
+ const walletData = {
122
+ solana: solanaKeypair.keypair.publicKey.toBase58(),
123
+ evm: evmKeypair.keypair.address,
124
+ };
125
+ const values = {
126
+ solana_public_key: solanaKeypair.keypair.publicKey.toBase58(),
127
+ evm_address: evmKeypair.keypair.address,
128
+ };
129
+ const text = `Solana Public Key: ${values.solana_public_key}\nEVM Address: ${values.evm_address}`;
130
+ return {
131
+ data: walletData,
132
+ values,
133
+ text,
134
+ };
135
+ }
136
+ catch (error) {
137
+ const message = error instanceof Error ? error.message : String(error);
138
+ logger.error(`Error in derive key provider: ${message}`);
139
+ return {
140
+ values: {},
141
+ text: `Failed to derive keys: ${message}`,
142
+ };
143
+ }
144
+ },
145
+ };
@@ -0,0 +1,4 @@
1
+ export { DeriveKeyProvider, RemoteAttestationProvider } from "./base";
2
+ export { PhalaDeriveKeyProvider, phalaDeriveKeyProvider } from "./deriveKey";
3
+ export { PhalaRemoteAttestationProvider, phalaRemoteAttestationProvider, } from "./remoteAttestation";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { DeriveKeyProvider, RemoteAttestationProvider } from "./base";
2
+ export { PhalaDeriveKeyProvider, phalaDeriveKeyProvider } from "./deriveKey";
3
+ export { PhalaRemoteAttestationProvider, phalaRemoteAttestationProvider, } from "./remoteAttestation";
@@ -0,0 +1,10 @@
1
+ import { type Provider } from "@elizaos/core";
2
+ import type { RemoteAttestationQuote, TdxQuoteHashAlgorithm } from "../types";
3
+ import { RemoteAttestationProvider } from "./base";
4
+ export declare class PhalaRemoteAttestationProvider extends RemoteAttestationProvider {
5
+ private readonly client;
6
+ constructor(teeMode: string);
7
+ generateAttestation(reportData: string, hashAlgorithm?: TdxQuoteHashAlgorithm): Promise<RemoteAttestationQuote>;
8
+ }
9
+ export declare const phalaRemoteAttestationProvider: Provider;
10
+ //# sourceMappingURL=remoteAttestation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remoteAttestation.d.ts","sourceRoot":"","sources":["../../../src/providers/remoteAttestation.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AAMvB,OAAO,KAAK,EAEV,sBAAsB,EACtB,qBAAqB,EAEtB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACnD,qBAAa,8BAA+B,SAAQ,yBAAyB;IAC3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,OAAO,EAAE,MAAM;IAarB,mBAAmB,CACvB,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,qBAAqB,GACpC,OAAO,CAAC,sBAAsB,CAAC;CAiBnC;AAED,eAAO,MAAM,8BAA8B,EAAE,QAyD5C,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { logger, } from "@elizaos/core";
2
+ import { TappdClient, } from "@phala/dstack-sdk";
3
+ import { getTeeEndpoint } from "../utils";
4
+ import { RemoteAttestationProvider } from "./base";
5
+ export class PhalaRemoteAttestationProvider extends RemoteAttestationProvider {
6
+ client;
7
+ constructor(teeMode) {
8
+ super();
9
+ const endpoint = getTeeEndpoint(teeMode);
10
+ logger.info(endpoint
11
+ ? `TEE: Connecting to simulator at ${endpoint}`
12
+ : "TEE: Running in production mode without simulator");
13
+ this.client = endpoint ? new TappdClient(endpoint) : new TappdClient();
14
+ }
15
+ async generateAttestation(reportData, hashAlgorithm) {
16
+ try {
17
+ const tdxQuote = await this.client.tdxQuote(reportData, hashAlgorithm);
18
+ return {
19
+ quote: tdxQuote.quote,
20
+ timestamp: Date.now(),
21
+ };
22
+ }
23
+ catch (error) {
24
+ const message = error instanceof Error ? error.message : String(error);
25
+ logger.error(`Error generating remote attestation: ${message}`);
26
+ throw new Error(`Failed to generate TDX Quote: ${message}`);
27
+ }
28
+ }
29
+ }
30
+ export const phalaRemoteAttestationProvider = {
31
+ name: "phala-remote-attestation",
32
+ dynamic: true,
33
+ contexts: ["secrets", "agent_internal"],
34
+ contextGate: { anyOf: ["secrets", "agent_internal"] },
35
+ cacheStable: false,
36
+ cacheScope: "turn",
37
+ get: async (runtime, message) => {
38
+ const teeModeRaw = runtime.getSetting("TEE_MODE");
39
+ if (!teeModeRaw) {
40
+ return {
41
+ values: {},
42
+ text: "TEE_MODE is not configured",
43
+ };
44
+ }
45
+ const teeMode = typeof teeModeRaw === "string" ? teeModeRaw : String(teeModeRaw);
46
+ const provider = new PhalaRemoteAttestationProvider(teeMode);
47
+ const agentId = runtime.agentId;
48
+ try {
49
+ const attestationMessage = {
50
+ agentId,
51
+ timestamp: Date.now(),
52
+ message: {
53
+ entityId: message.entityId,
54
+ roomId: message.roomId,
55
+ content: message.content.text ?? "",
56
+ },
57
+ };
58
+ const attestation = await provider.generateAttestation(JSON.stringify(attestationMessage));
59
+ return {
60
+ data: {
61
+ quote: attestation.quote,
62
+ timestamp: attestation.timestamp.toString(),
63
+ },
64
+ values: {
65
+ quote: attestation.quote,
66
+ timestamp: attestation.timestamp.toString(),
67
+ },
68
+ text: `Remote attestation: ${attestation.quote.substring(0, 64)}...`,
69
+ };
70
+ }
71
+ catch (error) {
72
+ const message = error instanceof Error ? error.message : String(error);
73
+ logger.error(`Error in remote attestation provider: ${message}`);
74
+ throw new Error(`Failed to generate TDX Quote: ${message}`);
75
+ }
76
+ },
77
+ };
@@ -0,0 +1,2 @@
1
+ export { TEEService } from "./tee";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1 @@
1
+ export { TEEService } from "./tee";
@@ -0,0 +1,24 @@
1
+ import { type IAgentRuntime, type Metadata, Service, type UUID } from "@elizaos/core";
2
+ import type { GetTlsKeyResponse as DeriveKeyResponse } from "@phala/dstack-sdk";
3
+ import type { Keypair } from "@solana/web3.js";
4
+ import type { PrivateKeyAccount } from "viem";
5
+ import type { RemoteAttestationQuote, TeeServiceConfig } from "../types";
6
+ export declare class TEEService extends Service {
7
+ private provider;
8
+ static serviceType: "tee";
9
+ capabilityDescription: string;
10
+ config?: Metadata;
11
+ constructor(runtime?: IAgentRuntime, config?: Partial<TeeServiceConfig>);
12
+ static start(runtime: IAgentRuntime): Promise<TEEService>;
13
+ stop(): Promise<void>;
14
+ deriveEcdsaKeypair(path: string, subject: string, agentId: UUID): Promise<{
15
+ keypair: PrivateKeyAccount;
16
+ attestation: RemoteAttestationQuote;
17
+ }>;
18
+ deriveEd25519Keypair(path: string, subject: string, agentId: UUID): Promise<{
19
+ keypair: Keypair;
20
+ attestation: RemoteAttestationQuote;
21
+ }>;
22
+ rawDeriveKey(path: string, subject: string): Promise<DeriveKeyResponse>;
23
+ }
24
+ //# sourceMappingURL=tee.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tee.d.ts","sourceRoot":"","sources":["../../../src/services/tee.ts"],"names":[],"m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import { PhalaDeriveKeyProvider } from "../providers/deriveKey";
3
+ import { TeeMode, TeeVendor } from "../types";
4
+ export class TEEService extends Service {
5
+ provider;
6
+ static serviceType = ServiceType.TEE;
7
+ capabilityDescription = "Trusted Execution Environment for secure key management";
8
+ constructor(runtime, config) {
9
+ super(runtime);
10
+ const teeModeRaw = config?.mode ?? runtime?.getSetting("TEE_MODE") ?? TeeMode.LOCAL;
11
+ const teeMode = typeof teeModeRaw === "string" ? teeModeRaw : TeeMode.LOCAL;
12
+ const vendor = config?.vendor ?? TeeVendor.PHALA;
13
+ const secretSaltRaw = config?.secretSalt ?? runtime?.getSetting("WALLET_SECRET_SALT");
14
+ const secretSalt = typeof secretSaltRaw === "string" ? secretSaltRaw : undefined;
15
+ // Set config as Metadata-compatible object
16
+ this.config = {
17
+ mode: teeMode,
18
+ vendor,
19
+ ...(secretSalt ? { secretSalt } : {}),
20
+ };
21
+ this.provider = new PhalaDeriveKeyProvider(teeMode);
22
+ }
23
+ static async start(runtime) {
24
+ const teeModeRaw = runtime.getSetting("TEE_MODE") ?? TeeMode.LOCAL;
25
+ const teeMode = typeof teeModeRaw === "string" ? teeModeRaw : TeeMode.LOCAL;
26
+ logger.info(`Starting TEE service with mode: ${teeMode}`);
27
+ const service = new TEEService(runtime, { mode: teeMode });
28
+ return service;
29
+ }
30
+ async stop() {
31
+ logger.info("Stopping TEE service");
32
+ }
33
+ async deriveEcdsaKeypair(path, subject, agentId) {
34
+ return this.provider.deriveEcdsaKeypair(path, subject, agentId);
35
+ }
36
+ async deriveEd25519Keypair(path, subject, agentId) {
37
+ return this.provider.deriveEd25519Keypair(path, subject, agentId);
38
+ }
39
+ async rawDeriveKey(path, subject) {
40
+ return this.provider.rawDeriveKeyResponse(path, subject);
41
+ }
42
+ }
@@ -0,0 +1,59 @@
1
+ export declare enum TeeMode {
2
+ LOCAL = "LOCAL",
3
+ DOCKER = "DOCKER",
4
+ PRODUCTION = "PRODUCTION"
5
+ }
6
+ export declare enum TeeVendor {
7
+ PHALA = "phala"
8
+ }
9
+ export declare enum TeeType {
10
+ SGX_GRAMINE = "sgx_gramine",
11
+ TDX_DSTACK = "tdx_dstack"
12
+ }
13
+ export interface RemoteAttestationQuote {
14
+ readonly quote: string;
15
+ readonly timestamp: number;
16
+ }
17
+ export interface DeriveKeyAttestationData {
18
+ readonly agentId: string;
19
+ readonly publicKey: string;
20
+ readonly subject?: string;
21
+ }
22
+ export interface RemoteAttestationMessage {
23
+ readonly agentId: string;
24
+ readonly timestamp: number;
25
+ readonly message: {
26
+ readonly entityId: string;
27
+ readonly roomId: string;
28
+ readonly content: string;
29
+ };
30
+ }
31
+ export interface DeriveKeyResult {
32
+ readonly key: Uint8Array;
33
+ readonly certificateChain: string[];
34
+ }
35
+ export interface Ed25519KeypairResult {
36
+ readonly publicKey: string;
37
+ readonly secretKey: Uint8Array;
38
+ readonly attestation: RemoteAttestationQuote;
39
+ }
40
+ export interface EcdsaKeypairResult {
41
+ readonly address: string;
42
+ readonly privateKey: Uint8Array;
43
+ readonly attestation: RemoteAttestationQuote;
44
+ }
45
+ export interface TeeServiceConfig {
46
+ readonly mode: TeeMode;
47
+ readonly vendor: TeeVendor;
48
+ readonly secretSalt?: string;
49
+ }
50
+ export interface TeeProviderResult {
51
+ readonly data?: ProviderDataRecord;
52
+ readonly values: Record<string, ProviderValue>;
53
+ readonly text: string;
54
+ }
55
+ export type TdxQuoteHashAlgorithm = "sha256" | "sha384" | "sha512" | "raw";
56
+ export declare function parseTeeMode(mode: string): TeeMode;
57
+ export declare function parseTeeVendor(vendor: string): TeeVendor;
58
+ import type { ProviderDataRecord, ProviderValue } from "@elizaos/core";
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED,oBAAY,SAAS;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AAS,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAalD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAOxD;AAED,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,35 @@
1
+ export var TeeMode;
2
+ (function (TeeMode) {
3
+ TeeMode["LOCAL"] = "LOCAL";
4
+ TeeMode["DOCKER"] = "DOCKER";
5
+ TeeMode["PRODUCTION"] = "PRODUCTION";
6
+ })(TeeMode || (TeeMode = {}));
7
+ export var TeeVendor;
8
+ (function (TeeVendor) {
9
+ TeeVendor["PHALA"] = "phala";
10
+ })(TeeVendor || (TeeVendor = {}));
11
+ export var TeeType;
12
+ (function (TeeType) {
13
+ TeeType["SGX_GRAMINE"] = "sgx_gramine";
14
+ TeeType["TDX_DSTACK"] = "tdx_dstack";
15
+ })(TeeType || (TeeType = {}));
16
+ export function parseTeeMode(mode) {
17
+ switch (mode.toUpperCase()) {
18
+ case "LOCAL":
19
+ return TeeMode.LOCAL;
20
+ case "DOCKER":
21
+ return TeeMode.DOCKER;
22
+ case "PRODUCTION":
23
+ return TeeMode.PRODUCTION;
24
+ default:
25
+ throw new Error(`Invalid TEE_MODE: ${mode}. Must be one of: LOCAL, DOCKER, PRODUCTION`);
26
+ }
27
+ }
28
+ export function parseTeeVendor(vendor) {
29
+ switch (vendor.toLowerCase()) {
30
+ case "phala":
31
+ return TeeVendor.PHALA;
32
+ default:
33
+ throw new Error(`Invalid TEE_VENDOR: ${vendor}. Must be one of: phala`);
34
+ }
35
+ }
@@ -0,0 +1,9 @@
1
+ export declare function hexToUint8Array(hex: string): Uint8Array;
2
+ export declare function uint8ArrayToHex(bytes: Uint8Array): string;
3
+ export declare function calculateSHA256(input: string): Buffer;
4
+ export declare function sha256Bytes(input: Uint8Array): Uint8Array;
5
+ export declare function getTeeEndpoint(mode: string): string | undefined;
6
+ export declare function uploadAttestationQuote(data: Uint8Array): Promise<{
7
+ checksum: string;
8
+ }>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAkBvD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIzD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAIzD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa/D;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,GACf,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAmB/B"}
@@ -0,0 +1,61 @@
1
+ import { createHash } from "node:crypto";
2
+ export function hexToUint8Array(hex) {
3
+ const hexString = hex.trim().replace(/^0x/, "");
4
+ if (!hexString) {
5
+ throw new Error("Invalid hex string: empty after stripping prefix");
6
+ }
7
+ if (hexString.length % 2 !== 0) {
8
+ throw new Error("Invalid hex string: odd number of characters");
9
+ }
10
+ const array = new Uint8Array(hexString.length / 2);
11
+ for (let i = 0; i < hexString.length; i += 2) {
12
+ const byte = Number.parseInt(hexString.slice(i, i + 2), 16);
13
+ if (Number.isNaN(byte)) {
14
+ throw new Error(`Invalid hex string: invalid byte at position ${i}`);
15
+ }
16
+ array[i / 2] = byte;
17
+ }
18
+ return array;
19
+ }
20
+ export function uint8ArrayToHex(bytes) {
21
+ return Array.from(bytes)
22
+ .map((b) => b.toString(16).padStart(2, "0"))
23
+ .join("");
24
+ }
25
+ export function calculateSHA256(input) {
26
+ const hash = createHash("sha256");
27
+ hash.update(input);
28
+ return hash.digest();
29
+ }
30
+ export function sha256Bytes(input) {
31
+ const hash = createHash("sha256");
32
+ hash.update(input);
33
+ return new Uint8Array(hash.digest());
34
+ }
35
+ export function getTeeEndpoint(mode) {
36
+ switch (mode.toUpperCase()) {
37
+ case "LOCAL":
38
+ return "http://localhost:8090";
39
+ case "DOCKER":
40
+ return "http://host.docker.internal:8090";
41
+ case "PRODUCTION":
42
+ return undefined;
43
+ default:
44
+ throw new Error(`Invalid TEE_MODE: ${mode}. Must be one of: LOCAL, DOCKER, PRODUCTION`);
45
+ }
46
+ }
47
+ export async function uploadAttestationQuote(data) {
48
+ const blob = new Blob([data], {
49
+ type: "application/octet-stream",
50
+ });
51
+ const formData = new FormData();
52
+ formData.append("file", blob, "quote.bin");
53
+ const response = await fetch("https://proof.t16z.com/api/upload", {
54
+ method: "POST",
55
+ body: formData,
56
+ });
57
+ if (!response.ok) {
58
+ throw new Error(`Failed to upload attestation quote: ${response.statusText}`);
59
+ }
60
+ return response.json();
61
+ }
@@ -0,0 +1,5 @@
1
+ import { type TeeVendorInterface, type TeeVendorName } from "./types";
2
+ export declare function getVendor(type: TeeVendorName): TeeVendorInterface;
3
+ export { PhalaVendor } from "./phala";
4
+ export { type TeeVendorInterface, type TeeVendorName, TeeVendorNames, } from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vendors/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAMjB,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,kBAAkB,CAMjE;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,cAAc,GACf,MAAM,SAAS,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { PhalaVendor } from "./phala";
2
+ import { TeeVendorNames, } from "./types";
3
+ const vendors = {
4
+ [TeeVendorNames.PHALA]: new PhalaVendor(),
5
+ };
6
+ export function getVendor(type) {
7
+ const vendor = vendors[type];
8
+ if (!vendor) {
9
+ throw new Error(`Unsupported TEE vendor: ${type}`);
10
+ }
11
+ return vendor;
12
+ }
13
+ export { PhalaVendor } from "./phala";
14
+ export { TeeVendorNames, } from "./types";
@@ -0,0 +1,10 @@
1
+ import type { Action, Provider } from "@elizaos/core";
2
+ import { type TeeVendorInterface } from "./types";
3
+ export declare class PhalaVendor implements TeeVendorInterface {
4
+ readonly type: "phala";
5
+ getActions(): Action[];
6
+ getProviders(): Provider[];
7
+ getName(): string;
8
+ getDescription(): string;
9
+ }
10
+ //# sourceMappingURL=phala.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phala.d.ts","sourceRoot":"","sources":["../../../src/vendors/phala.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAElE,qBAAa,WAAY,YAAW,kBAAkB;IACpD,QAAQ,CAAC,IAAI,UAAwB;IAErC,UAAU,IAAI,MAAM,EAAE;IAItB,YAAY,IAAI,QAAQ,EAAE;IAI1B,OAAO,IAAI,MAAM;IAIjB,cAAc,IAAI,MAAM;CAGzB"}
@@ -0,0 +1,17 @@
1
+ import { phalaDeriveKeyProvider, phalaRemoteAttestationProvider, } from "../providers";
2
+ import { TeeVendorNames } from "./types";
3
+ export class PhalaVendor {
4
+ type = TeeVendorNames.PHALA;
5
+ getActions() {
6
+ return [];
7
+ }
8
+ getProviders() {
9
+ return [phalaDeriveKeyProvider, phalaRemoteAttestationProvider];
10
+ }
11
+ getName() {
12
+ return "phala-tee-plugin";
13
+ }
14
+ getDescription() {
15
+ return "Phala Network TEE for secure agent execution";
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { Action, Provider } from "@elizaos/core";
2
+ export declare const TeeVendorNames: {
3
+ readonly PHALA: "phala";
4
+ };
5
+ export type TeeVendorName = (typeof TeeVendorNames)[keyof typeof TeeVendorNames];
6
+ export interface TeeVendorInterface {
7
+ readonly type: TeeVendorName;
8
+ getActions(): Action[];
9
+ getProviders(): Provider[];
10
+ getName(): string;
11
+ getDescription(): string;
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/vendors/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEtD,eAAO,MAAM,cAAc;;CAEjB,CAAC;AAEX,MAAM,MAAM,aAAa,GACvB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,UAAU,IAAI,MAAM,EAAE,CAAC;IACvB,YAAY,IAAI,QAAQ,EAAE,CAAC;IAC3B,OAAO,IAAI,MAAM,CAAC;IAClB,cAAc,IAAI,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,3 @@
1
+ export const TeeVendorNames = {
2
+ PHALA: "phala",
3
+ };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-tee",
3
- "version": "2.0.3-beta.5",
3
+ "version": "2.0.3-beta.7",
4
4
  "type": "module",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/node/index.js",
7
- "types": "dist/index.d.ts",
7
+ "types": "dist/node/index.d.ts",
8
8
  "description": "Trusted Execution Environment (TEE) integration plugin for elizaOS - Multi-language support (TypeScript, Python, Rust)",
9
9
  "repository": {
10
10
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  "exports": {
14
14
  "./package.json": "./package.json",
15
15
  ".": {
16
- "types": "./dist/index.d.ts",
16
+ "types": "./dist/node/index.d.ts",
17
17
  "eliza-source": {
18
18
  "types": "./src/index.ts",
19
19
  "import": "./src/index.ts",
@@ -32,9 +32,9 @@
32
32
  },
33
33
  "./*.css": "./dist/*.css",
34
34
  "./*": {
35
- "types": "./dist/*.d.ts",
36
- "import": "./dist/*.js",
37
- "default": "./dist/*.js"
35
+ "types": "./dist/node/*.d.ts",
36
+ "import": "./dist/node/*.js",
37
+ "default": "./dist/node/*.js"
38
38
  }
39
39
  },
40
40
  "files": [
@@ -45,7 +45,7 @@
45
45
  ],
46
46
  "sideEffects": false,
47
47
  "dependencies": {
48
- "@elizaos/core": "2.0.3-beta.5",
48
+ "@elizaos/core": "2.0.3-beta.7",
49
49
  "@phala/dstack-sdk": "^0.5.7",
50
50
  "@solana/web3.js": "1.98.4",
51
51
  "viem": "^2.48.8"
@@ -74,7 +74,7 @@
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  },
77
- "gitHead": "ff6157011c9459670021cc28a6797592a78b8817",
77
+ "gitHead": "61094f10458d11055c75b3dd0bae374e3f66bac5",
78
78
  "agentConfig": {
79
79
  "pluginType": "elizaos:plugin:1.0.0",
80
80
  "pluginParameters": {