Skip to main content
Glama
keypair.ts1.14 kB
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'; import bip39 from 'bip39'; /** * Get keypair from private key * @param privateKey Private key * @returns Keypair or null if error */ export function getKeypairFromPrivateKey(privateKey: string) { try { const keypair = Ed25519Keypair.fromSecretKey(privateKey); return keypair; } catch (error) { console.error('Error creating keypair from private key:', error); return null; } } export function getRandomKeypair() { const keypair = new Ed25519Keypair(); return keypair; } export function getKeypairFromMnemonic(mnemonic: string, idx: number = 0) { const path = `m/44'/784'/0'/0'/${idx}'`; const keypair = Ed25519Keypair.deriveKeypair(mnemonic, path); return keypair; } export function getAccountInfoFromKeypair(keypair: Ed25519Keypair) { const publicKey = keypair.getPublicKey().toSuiPublicKey(); const privateKey = keypair.getSecretKey(); const address = keypair.toSuiAddress(); return { publicKey, privateKey, address }; } export function genRandomMnemonic() { const mnemonic = bip39.generateMnemonic(); return mnemonic; }

Implementation Reference

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/0xdwong/sui-mcp'

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