Skip to content

Commit 16cebb6

Browse files
committed
chore: update Readme.md and remove commented code
1 parent 7736ec0 commit 16cebb6

File tree

2 files changed

+6
-149
lines changed

2 files changed

+6
-149
lines changed

packages/plugin-cosmos-tee/README.md

+5-16
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ This plugin includes several providers for handling different TEE-related operat
88

99
### DeriveKeyProvider
1010

11-
The `DeriveKeyProvider` allows for secure key derivation within a TEE environment. It supports deriving keys for both Solana (Ed25519) and Ethereum (ECDSA) chains.
11+
The `DeriveKeyProvider` allows for secure key derivation within a TEE environment. It supports deriving keys for cosmos chain.
1212

1313
#### Usage
1414

1515
```typescript
16-
import { DeriveKeyProvider } from "@elizaos/plugin-tee";
16+
import { DeriveKeyProvider } from "@elizaos/plugincosmos-tee";
1717

1818
// Initialize the provider
1919
const provider = new DeriveKeyProvider();
@@ -31,27 +31,16 @@ try {
3131
console.error("Raw key derivation failed:", error);
3232
}
3333

34-
// Derive a Solana keypair (Ed25519)
34+
// Derive a cosmos keypair (secp256k1)
3535
try {
36-
const solanaKeypair = await provider.deriveEd25519Keypair(
36+
const solanaKeypair = await provider.deriveSecp256k1KeypairForCosmos(
3737
"/path/to/derive",
3838
"subject-identifier"
3939
);
40-
// solanaKeypair can now be used for Solana operations
40+
// cosmosKeypair can now be used for cosmos operations
4141
} catch (error) {
4242
console.error("Solana key derivation failed:", error);
4343
}
44-
45-
// 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-
}
5544
```
5645

5746
### RemoteAttestationProvider

packages/plugin-cosmos-tee/src/providers/deriveKeyProvider.ts

+1-133
Original file line numberDiff line numberDiff line change
@@ -91,116 +91,6 @@ class DeriveKeyProvider {
9191
throw error;
9292
}
9393
}
94-
95-
// async deriveEd25519Keypair(
96-
// path: string,
97-
// subject: string,
98-
// agentId: string
99-
// ): Promise<{ keypair: Keypair; attestation: RemoteAttestationQuote }> {
100-
// try {
101-
// if (!path || !subject) {
102-
// console.error(
103-
// "Path and Subject are required for key derivation"
104-
// );
105-
// }
106-
107-
// console.log("Deriving Key in TEE...");
108-
// const derivedKey = await this.client.deriveKey(path, subject);
109-
// const uint8ArrayDerivedKey = derivedKey.asUint8Array();
110-
111-
// const hash = crypto.createHash("sha256");
112-
// hash.update(uint8ArrayDerivedKey);
113-
// const seed = hash.digest();
114-
// const seedArray = new Uint8Array(seed);
115-
// const keypair = Keypair.fromSeed(seedArray.slice(0, 32));
116-
117-
// const attestation = await this.generateDeriveKeyAttestation(
118-
// agentId,
119-
// keypair.publicKey.toBase58()
120-
// );
121-
// console.log("Key Derived Successfully!");
122-
123-
// return { keypair, attestation };
124-
// } catch (error) {
125-
// console.error("Error deriving key:", error);
126-
// throw error;
127-
// }
128-
// }
129-
130-
// async deriveEcdsaKeypair(
131-
// path: string,
132-
// subject: string,
133-
// agentId: string
134-
// ): Promise<{
135-
// keypair: PrivateKeyAccount;
136-
// attestation: RemoteAttestationQuote;
137-
// }> {
138-
// try {
139-
// if (!path || !subject) {
140-
// console.error(
141-
// "Path and Subject are required for key derivation"
142-
// );
143-
// }
144-
145-
// console.log("Deriving ECDSA Key in TEE...");
146-
// const deriveKeyResponse: DeriveKeyResponse =
147-
// await this.client.deriveKey(path, subject);
148-
// const hex = keccak256(deriveKeyResponse.asUint8Array());
149-
// const keypair: PrivateKeyAccount = privateKeyToAccount(hex);
150-
151-
// const attestation = await this.generateDeriveKeyAttestation(
152-
// agentId,
153-
// keypair.address
154-
// );
155-
// console.log("ECDSA Key Derived Successfully!");
156-
157-
// return { keypair, attestation };
158-
// } catch (error) {
159-
// console.error("Error deriving ecdsa key:", error);
160-
// throw error;
161-
// }
162-
// }
163-
164-
// async deriveSecp256k1Keypair(
165-
// path: string,
166-
// subject: string,
167-
// agentId: string
168-
// ): Promise<{
169-
// keypair: { privateKey: string; publicKey: string };
170-
// attestation: RemoteAttestationQuote;
171-
// }> {
172-
// try {
173-
// if (!path || !subject) {
174-
// console.error(
175-
// "Path and Subject are required for key derivation"
176-
// );
177-
// }
178-
179-
// console.log("Deriving Secp256k1 Key in TEE...");
180-
// const derivedKey = await this.client.deriveKey(path, subject);
181-
// const uint8ArrayDerivedKey = derivedKey.asUint8Array();
182-
183-
// const privateKey = uint8ArrayDerivedKey.slice(0, 32);
184-
// const publicKey = secp256k1.publicKeyCreate(privateKey, false);
185-
186-
// const attestation = await this.generateDeriveKeyAttestation(
187-
// agentId,
188-
// Buffer.from(publicKey).toString("hex")
189-
// );
190-
// console.log("Secp256k1 Key Derived Successfully!");
191-
192-
// return {
193-
// keypair: {
194-
// privateKey: Buffer.from(privateKey).toString("hex"),
195-
// publicKey: Buffer.from(publicKey).toString("hex"),
196-
// },
197-
// attestation,
198-
// };
199-
// } catch (error) {
200-
// console.error("Error deriving Secp256k1 key:", error);
201-
// throw error;
202-
// }
203-
// }
20494
async deriveSecp256k1KeypairForCosmos(
20595
path: string,
20696
subject: string,
@@ -241,11 +131,10 @@ class DeriveKeyProvider {
241131

242132
// Step 3: Encode the result in Bech32
243133
const cosmosAddress = bech32.encode(
244-
"osmo",
134+
"osmo", // change this to your specified prefix
245135
bech32.toWords(ripemd160) // Use the 20-byte hash from RIPEMD160
246136
);
247137

248-
console.log("cosmosAddress>>>>>>>>>.", cosmosAddress);
249138
const attestation = await this.generateDeriveKeyAttestation(
250139
agentId,
251140
Buffer.from(publicKey).toString("hex")
@@ -283,34 +172,13 @@ const deriveKeyProvider: Provider = {
283172
try {
284173
const secretSalt =
285174
runtime.getSetting("WALLET_SECRET_SALT") || "secret_salt";
286-
// const solanaKeypair = await provider.deriveEd25519Keypair(
287-
// "/",
288-
// secretSalt,
289-
// agentId
290-
// );
291-
// const evmKeypair = await provider.deriveEcdsaKeypair(
292-
// "/",
293-
// secretSalt,
294-
// agentId
295-
// );
296175
const cosmosKeypair =
297176
await provider.deriveSecp256k1KeypairForCosmos(
298177
"/",
299178
secretSalt,
300179
agentId
301180
);
302-
303-
console.log(
304-
">>>>>>>>>>>>>>>>>>>>>>>>>.",
305-
cosmosKeypair.keypair.privateKey
306-
);
307-
// console.log(
308-
// ">>>>>>>>>>>>>>>>>>>>>>>>>.",
309-
// solanaKeypair.keypair.publicKey
310-
// );
311181
return JSON.stringify({
312-
// solana: solanaKeypair.keypair.publicKey,
313-
// evm: evmKeypair.keypair.address,
314182
cosmos: cosmosKeypair.address,
315183
});
316184
} catch (error) {

0 commit comments

Comments
 (0)