zetrix_crypto_encrypt_key
Encrypt private keys with passwords for secure storage on the Zetrix blockchain, protecting sensitive cryptographic data from unauthorized access.
Instructions
Encrypt a private key with a password for secure storage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| privateKey | Yes | The private key to encrypt | |
| password | Yes | The password to use for encryption |
Implementation Reference
- src/index.ts:623-640 (registration)Tool registration in the MCP tools list, including name, description, and input schema definition{ name: "zetrix_crypto_encrypt_key", description: "Encrypt a private key with a password for secure storage", inputSchema: { type: "object", properties: { privateKey: { type: "string", description: "The private key to encrypt", }, password: { type: "string", description: "The password to use for encryption", }, }, required: ["privateKey", "password"], }, },
- src/index.ts:1347-1363 (handler)MCP server request handler for the tool. Validates arguments and delegates to ZetrixEncryption.encryptPrivateKey, formats responsecase "zetrix_crypto_encrypt_key": { if (!args) { throw new Error("Missing arguments"); } const encryptedData = await zetrixEncryption.encryptPrivateKey( args.privateKey as string, args.password as string ); return { content: [ { type: "text", text: JSON.stringify({ encryptedData }, null, 2), }, ], }; }
- src/zetrix-encryption.ts:202-233 (helper)Core implementation of private key encryption using the official zetrix-encryption-nodejs library's keystore.encrypt method, wrapped in Promise for async/await compatibility/** * Encrypt a private key with a password (uses callbacks, wrapped in Promise) * @param privateKey - The private key to encrypt * @param password - The password to use for encryption * @returns Encrypted keystore data (object that can be passed to decrypt) */ async encryptPrivateKey( privateKey: string, password: string ): Promise<any> { await this.initEncryption(); return new Promise((resolve, reject) => { try { this.keystore.encrypt(privateKey, password, (result: any) => { if (result) { // The library returns an object with encrypted data // Return as-is for decrypt to consume resolve(result); } else { reject(new Error("Encryption failed: No data returned")); } }); } catch (error) { reject( new Error( `Failed to encrypt private key: ${error instanceof Error ? error.message : String(error)}` ) ); } }); }