@@ -91,116 +91,6 @@ class DeriveKeyProvider {
91
91
throw error ;
92
92
}
93
93
}
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
- // }
204
94
async deriveSecp256k1KeypairForCosmos (
205
95
path : string ,
206
96
subject : string ,
@@ -241,11 +131,10 @@ class DeriveKeyProvider {
241
131
242
132
// Step 3: Encode the result in Bech32
243
133
const cosmosAddress = bech32 . encode (
244
- "osmo" ,
134
+ "osmo" , // change this to your specified prefix
245
135
bech32 . toWords ( ripemd160 ) // Use the 20-byte hash from RIPEMD160
246
136
) ;
247
137
248
- console . log ( "cosmosAddress>>>>>>>>>." , cosmosAddress ) ;
249
138
const attestation = await this . generateDeriveKeyAttestation (
250
139
agentId ,
251
140
Buffer . from ( publicKey ) . toString ( "hex" )
@@ -283,34 +172,13 @@ const deriveKeyProvider: Provider = {
283
172
try {
284
173
const secretSalt =
285
174
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
- // );
296
175
const cosmosKeypair =
297
176
await provider . deriveSecp256k1KeypairForCosmos (
298
177
"/" ,
299
178
secretSalt ,
300
179
agentId
301
180
) ;
302
-
303
- console . log (
304
- ">>>>>>>>>>>>>>>>>>>>>>>>>." ,
305
- cosmosKeypair . keypair . privateKey
306
- ) ;
307
- // console.log(
308
- // ">>>>>>>>>>>>>>>>>>>>>>>>>.",
309
- // solanaKeypair.keypair.publicKey
310
- // );
311
181
return JSON . stringify ( {
312
- // solana: solanaKeypair.keypair.publicKey,
313
- // evm: evmKeypair.keypair.address,
314
182
cosmos : cosmosKeypair . address ,
315
183
} ) ;
316
184
} catch ( error ) {
0 commit comments