Skip to main content
Glama
check-session-key.jsβ€’4.39 kB
#!/usr/bin/env node /** * Check session key configuration and explain what's needed */ import dotenv from 'dotenv'; import crypto from 'crypto'; dotenv.config(); const DERIVE_WALLET = process.env.DERIVE_WALLET || ""; const DERIVE_PRIVATE_KEY = process.env.DERIVE_PRIVATE_KEY || ""; console.log("πŸ” Session Key Configuration Check\n"); console.log("=" .repeat(60)); console.log("\nπŸ“‹ Current Configuration:"); console.log(` Main Wallet (DERIVE_WALLET): ${DERIVE_WALLET}`); if (DERIVE_PRIVATE_KEY) { console.log(` Session Key Private Key: Set (${DERIVE_PRIVATE_KEY.substring(0, 6)}...)`); // Try to derive the public address from the private key try { const key = DERIVE_PRIVATE_KEY.startsWith("0x") ? DERIVE_PRIVATE_KEY.slice(2) : DERIVE_PRIVATE_KEY; if (key.length === 64) { console.log(` βœ… Private key format looks correct (64 hex chars)`); console.log(`\nπŸ’‘ This private key will be used to sign API requests`); } else { console.log(` ⚠️ Private key length: ${key.length} (expected 64)`); } } catch (error) { console.log(` ❌ Error validating private key: ${error.message}`); } } else { console.log(` Session Key Private Key: ❌ NOT SET`); console.log(`\n⚠️ You have a session key public address:`); console.log(` 0x65E4fa918ecBDd6c5e234cEC6aE685A160C80709`); console.log(`\n But you need the PRIVATE KEY of this wallet to sign API requests.`); } console.log("\n" + "=".repeat(60)); console.log("\nπŸ“š How Derive Authentication Works:\n"); console.log(" 1. Main Wallet (DERIVE_WALLET)"); console.log(" └─ This is YOUR wallet that owns the Derive account"); console.log(" └─ Address: " + DERIVE_WALLET); console.log(""); console.log(" 2. Session Key Wallet"); console.log(" └─ A separate wallet registered to act on your behalf"); console.log(" └─ Public Address: 0x65E4fa918ecBDd6c5e234cEC6aE685A160C80709"); console.log(" └─ Private Key: ??? (This is what you need!)"); console.log(""); console.log(" 3. API Requests"); console.log(" └─ Send X-LyraWallet header: " + DERIVE_WALLET); console.log(" └─ Sign with session key private key"); console.log(" └─ Derive verifies: 'Is this session key registered to this wallet?'"); console.log("\n" + "=".repeat(60)); console.log("\nβœ… Solutions:\n"); console.log(" Option A: Export Session Key Private Key"); console.log(" ─────────────────────────────────────────"); console.log(" 1. Check if Derive UI shows the private key"); console.log(" 2. Settings β†’ Developers β†’ Session Keys"); console.log(" 3. Look for 'Export' or 'Show Private Key' option"); console.log(""); console.log(" Option B: Create New Session Key (Recommended)"); console.log(" ───────────────────────────────────────────────"); console.log(" 1. Create new MetaMask account (Account 2)"); console.log(" 2. Export its private key from MetaMask"); console.log(" 3. Register that address as session key on Derive"); console.log(" 4. Add private key to .env:"); console.log(" DERIVE_PRIVATE_KEY=0x..."); console.log(""); console.log(" Option C: Test Without Authentication"); console.log(" ─────────────────────────────────────────"); console.log(" For now, you can use public endpoints:"); console.log(" β€’ Market data (prices, orderbooks)"); console.log(" β€’ Trade history (public)"); console.log(" β€’ Funding rates"); console.log(" β€’ Option settlements"); console.log(""); console.log(" Private endpoints require authentication:"); console.log(" β€’ Your account info"); console.log(" β€’ Your positions"); console.log(" β€’ Your orders"); console.log(" β€’ Placing trades"); console.log("\n" + "=".repeat(60)); if (!DERIVE_PRIVATE_KEY) { console.log("\n⚠️ Action Required:"); console.log(" Set DERIVE_PRIVATE_KEY in your .env file"); console.log(" with the private key of a session key wallet."); process.exit(1); } else { console.log("\nβœ… Configuration looks complete!"); console.log(" Try running: node test-credentials.js"); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/solenyaresearch0000/derive-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server