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/zetrix-encryption.ts:208-233 (handler)Core implementation of private key encryption using the official zetrix-encryption-nodejs library's keystore.encrypt method, wrapped in Promise for async/await compatibility.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)}` ) ); } }); }
- src/index.ts:1347-1363 (handler)MCP server handler for the tool call, which delegates to zetrixEncryption.encryptPrivateKey and formats the response.case "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/index.ts:623-640 (schema)Tool schema definition including input validation schema, registered in the tools list for MCP server.{ 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:60-766 (registration)Registration of all tools including zetrix_crypto_encrypt_key in the MCP server's tools list, exposed via ListToolsRequestSchema.const tools: Tool[] = [ { name: "zetrix_check_health", description: "Check the health status of the Zetrix node", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_get_account", description: "Get Zetrix account information including balance and metadata", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_get_block", description: "Get information about a specific block by height", inputSchema: { type: "object", properties: { blockNumber: { type: "number", description: "The block height/number to query", }, }, required: ["blockNumber"], }, }, { name: "zetrix_get_latest_block", description: "Get the latest block information from Zetrix blockchain", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_get_transaction", description: "Get transaction details by transaction hash", inputSchema: { type: "object", properties: { hash: { type: "string", description: "The transaction hash", }, }, required: ["hash"], }, }, { name: "zetrix_get_balance", description: "Get the ZETRIX balance of an account. Returns balance in both ZETA (micro units) and ZETRIX (main units). Note: 1 ZETRIX = 1,000,000 ZETA", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_create_keypair", description: "Generate a new public-private key pair (for testing only)", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_get_account_base", description: "Get basic account information without assets and metadata", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_get_account_assets", description: "Get asset holdings for an account", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, code: { type: "string", description: "Asset code (optional, must be used with issuer)", }, issuer: { type: "string", description: "Asset issuer address (optional, must be used with code)", }, }, required: ["address"], }, }, { name: "zetrix_get_account_metadata", description: "Get metadata associated with an account", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, key: { type: "string", description: "Specific metadata key (optional)", }, }, required: ["address"], }, }, { name: "zetrix_get_transaction_history", description: "Get completed transaction records", inputSchema: { type: "object", properties: { hash: { type: "string", description: "Transaction hash (optional)", }, ledgerSeq: { type: "number", description: "Block sequence number (optional)", }, }, }, }, { name: "zetrix_get_transaction_cache", description: "Get pending transactions not yet executed", inputSchema: { type: "object", properties: { hash: { type: "string", description: "Transaction hash (optional)", }, limit: { type: "number", description: "Number of pending transactions to return (optional)", }, }, }, }, { name: "zetrix_get_ledger", description: "Get block/ledger information with optional details", inputSchema: { type: "object", properties: { seq: { type: "number", description: "Block sequence number (optional)", }, withValidator: { type: "boolean", description: "Include validator list (optional)", }, withConsValue: { type: "boolean", description: "Include consensus value (optional)", }, withFee: { type: "boolean", description: "Include fee configuration (optional)", }, }, }, }, { name: "zetrix_multi_query", description: "Execute multiple API queries simultaneously", inputSchema: { type: "object", properties: { items: { type: "array", description: "Array of query objects", }, }, required: ["items"], }, }, { name: "zetrix_get_transaction_blob", description: "Serialize transaction data into hexadecimal format", inputSchema: { type: "object", properties: { transaction: { type: "object", description: "Transaction object with source_address, nonce, fee_limit, gas_price, operations", }, }, required: ["transaction"], }, }, { name: "zetrix_submit_transaction", description: "Submit signed transaction to blockchain for execution", inputSchema: { type: "object", properties: { transactionBlob: { type: "string", description: "Serialized transaction blob", }, signatures: { type: "array", description: "Array of signature objects with sign_data and public_key", }, }, required: ["transactionBlob", "signatures"], }, }, { name: "zetrix_call_contract", description: "Call smart contract in sandbox environment for debugging", inputSchema: { type: "object", properties: { contractAddress: { type: "string", description: "Deployed contract address (optional)", }, code: { type: "string", description: "Contract source code (optional)", }, input: { type: "string", description: "Function parameters (optional)", }, contractBalance: { type: "string", description: "Contract balance (optional)", }, feeLimit: { type: "string", description: "Fee limit (optional)", }, gasPrice: { type: "string", description: "Gas price (optional)", }, optType: { type: "number", description: "Operation type (optional)", }, sourceAddress: { type: "string", description: "Source address (optional)", }, }, }, }, { name: "zetrix_test_transaction", description: "Evaluate transaction fees without blockchain submission", inputSchema: { type: "object", properties: { items: { type: "array", description: "Array of test transaction items", }, }, required: ["items"], }, }, { name: "zetrix_ws_connect", description: "Connect and register to Zetrix WebSocket for real-time updates", inputSchema: { type: "object", properties: { apiList: { type: "array", description: "Optional list of API message types to register (numbers)", }, }, }, }, { name: "zetrix_ws_submit_transaction", description: "Submit transaction via WebSocket and get real-time status updates", inputSchema: { type: "object", properties: { transaction: { type: "object", description: "Transaction object", }, signatures: { type: "array", description: "Array of signature objects with public_key and sign_data", }, trigger: { type: "object", description: "Optional trigger object", }, }, required: ["transaction", "signatures"], }, }, { name: "zetrix_ws_subscribe_tx", description: "Subscribe to transaction notifications for specific addresses", inputSchema: { type: "object", properties: { addresses: { type: "array", description: "Array of account addresses to subscribe to", }, }, required: ["addresses"], }, }, { name: "zetrix_ws_disconnect", description: "Disconnect from WebSocket", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_ws_status", description: "Check WebSocket connection status", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_sdk_create_account", description: "Create a new Zetrix account using the official SDK", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_sdk_get_balance", description: "Get account balance using the official SDK", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_sdk_is_activated", description: "Check if an account is activated on the blockchain", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_sdk_get_nonce", description: "Get account nonce (transaction sequence number)", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, }, { name: "zetrix_sdk_call_contract", description: "Call a smart contract function (query only, no state change) using SDK", inputSchema: { type: "object", properties: { contractAddress: { type: "string", description: "The deployed smart contract address", }, input: { type: "string", description: "JSON string with method and params", }, sourceAddress: { type: "string", description: "Optional source address for the call", }, }, required: ["contractAddress"], }, }, { name: "zetrix_sdk_invoke_contract", description: "Invoke a smart contract function with state change (requires private key)", inputSchema: { type: "object", properties: { sourceAddress: { type: "string", description: "The account address initiating the transaction", }, privateKey: { type: "string", description: "Private key for signing the transaction", }, contractAddress: { type: "string", description: "The smart contract address to invoke", }, amount: { type: "string", description: "Amount of ZTX to send with invocation (in micro-ZTX)", }, input: { type: "string", description: "JSON string with method and params", }, metadata: { type: "string", description: "Optional transaction description", }, }, required: ["sourceAddress", "privateKey", "contractAddress", "amount", "input"], }, }, // Encryption Tools { name: "zetrix_crypto_generate_keypair", description: "Generate a new Zetrix key pair with private key, public key, and address", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_crypto_get_public_key", description: "Derive public key from private key", inputSchema: { type: "object", properties: { privateKey: { type: "string", description: "The encrypted private key", }, }, required: ["privateKey"], }, }, { name: "zetrix_crypto_get_address", description: "Get Zetrix address from public key", inputSchema: { type: "object", properties: { publicKey: { type: "string", description: "The public key", }, }, required: ["publicKey"], }, }, { name: "zetrix_crypto_validate_key", description: "Validate private key, public key, or address format", inputSchema: { type: "object", properties: { type: { type: "string", enum: ["privateKey", "publicKey", "address"], description: "Type of key to validate", }, value: { type: "string", description: "The key or address to validate", }, }, required: ["type", "value"], }, }, { name: "zetrix_crypto_sign", description: "Sign a message with a private key", inputSchema: { type: "object", properties: { message: { type: "string", description: "The message to sign (hex string)", }, privateKey: { type: "string", description: "The private key to sign with", }, }, required: ["message", "privateKey"], }, }, { name: "zetrix_crypto_verify", description: "Verify a signature against a message and public key", inputSchema: { type: "object", properties: { message: { type: "string", description: "The original message (hex string)", }, signature: { type: "string", description: "The signature to verify", }, publicKey: { type: "string", description: "The public key to verify against", }, }, required: ["message", "signature", "publicKey"], }, }, { 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"], }, }, { name: "zetrix_crypto_decrypt_key", description: "Decrypt an encrypted private key with a password", inputSchema: { type: "object", properties: { encryptedData: { type: "string", description: "The encrypted keystore data", }, password: { type: "string", description: "The password used for encryption", }, }, required: ["encryptedData", "password"], }, }, // Smart Contract Development Tools { name: "zetrix_contract_get_chain_functions", description: "Get documentation for all built-in Chain object functions available in Zetrix smart contracts", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_contract_get_utils_functions", description: "Get documentation for all built-in Utils object functions available in Zetrix smart contracts", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_contract_get_structure_guide", description: "Get guide on how to structure Zetrix smart contracts with ES5 patterns, classes, and inheritance", inputSchema: { type: "object", properties: {}, }, }, { name: "zetrix_contract_get_token_standard", description: "Get token standard specification (ZTP20, ZTP721, or ZTP1155)", inputSchema: { type: "object", properties: { standard: { type: "string", enum: ["ZTP20", "ZTP721", "ZTP1155"], description: "Token standard to get documentation for", }, }, required: ["standard"], }, }, { name: "zetrix_contract_init_dev_environment", description: "Initialize a new Zetrix smart contract development environment using create-zetrix-tool. This creates a complete project structure with testing framework, examples, and utilities.", inputSchema: { type: "object", properties: { contractName: { type: "string", description: "Name of the contract project to create (alphanumeric and hyphens only)", }, workingDirectory: { type: "string", description: "Directory where to create the project (defaults to current directory)", }, }, required: ["contractName"], }, }, { name: "zetrix_contract_generate_advanced", description: "Generate advanced multi-class Zetrix smart contract with interfaces, libraries, utilities, main contract, and comprehensive test specs. **MANDATORY WORKFLOW: (1) First call zetrix_contract_init_dev_environment with contractName (e.g., 'CertificateContract'). (2) Then call this tool with the SAME contractName and outputDirectory set to './{contractName}'. Calling this tool WITHOUT initializing the project first will result in an error.** Supports complex architectures with inheritance, composition, and modular design.", inputSchema: { type: "object", properties: { contractName: { type: "string", description: "Name of the main contract (e.g., 'StableCoin', 'NFTMarketplace')", }, contractType: { type: "string", enum: ["token", "nft", "defi", "governance", "marketplace", "custom"], description: "Type of contract to generate", }, features: { type: "array", items: { type: "string", enum: ["pausable", "ownable", "roles", "upgradeable", "whitelist", "blacklist", "timelock", "oracle"], }, description: "Advanced features to include", }, tokenStandard: { type: "string", enum: ["ZTP20", "ZTP721", "ZTP1155"], description: "Token standard (required if contractType is 'token' or 'nft')", }, includeTests: { type: "boolean", description: "Generate comprehensive test specifications (default: true)", }, outputDirectory: { type: "string", description: "Directory to output the contract files (defaults to current directory)", }, }, required: ["contractName", "contractType"], }, }, { name: "zetrix_contract_get_testing_guide", description: "Get guide on testing Zetrix smart contracts with TEST_INVOKE and TEST_QUERY", inputSchema: { type: "object", properties: {}, }, }, ];