Generate invite codes and derive deterministic keypairs for the Send API.
This page covers the client-side prerequisites for the Send API: generating random 12-character base58 invite codes, deriving deterministic Solana secret keys from those codes, and the security requirements for handling invite codes and private keys.
The Send API is designed for transaction building only - it expects and exchanges parameters such as public keys, amounts, and mint addresses. The API does not handle private keys or invite codes for security reasons.All cryptographic operations must be performed client-side:
Invite code generation
Private key derivation from invite codes
Transaction signing
The following sections provide the complete implementation steps required before using the API.
WARNINGCRITICAL SECURITY REQUIREMENTS
Never share invite codes or private keys - treat them like passwords or seed phrases
Store invite codes securely - use encrypted storage, secure vaults, or environment variables
Validate all inputs - ensure invite codes meet expected format before processing
Implement proper error handling - avoid exposing sensitive data in logs or error messages
⚠️ Loss of funds: Any exposure of invite codes or private keys may result in permanent loss of funds. Jupiter is not liable for losses due to compromised credentials.
npm install @solana/web3.js@1 # Using v1 of web3.js instead of v2npm install dotenv # Useful for testing and handling of invite code and private keynpm install @noble/ed25519npm install @noble/hashes
import crypto from "crypto";import * as ed from "@noble/ed25519";import { sha512 } from "@noble/hashes/sha512";import { PublicKey } from "@solana/web3.js";// Configure the ed25519 library to use SHA-512 for internal operations// This is REQUIRED before using any ed25519 functions like getPublicKey()// The library needs to know which hash function to use for key derivation and signingconst hashFunction = (...messages) => sha512(ed.etc.concatBytes(...messages));ed.etc.sha512Sync = hashFunction;// Import createHash function from Node.js crypto module using dynamic import// This allows us to use the modern 'node:crypto' protocol for better compatibility// createHash is used for SHA-256 hashing in the invite code functionsconst { createHash } = await import("node:crypto");
// This function creates a random 12-character base58 invite code// Uses 13 random bytes (~1.4 quintillion possible codes)export async function create_invite_code() { const buf = crypto.randomBytes(13); // 58^12 = 1.449225352 e21 return binary_to_base58(new Uint8Array(buf)).substring(0, 12);};
// This function converts an invite code to a deterministic private key// Uses SHA256 hash of `"invite:"` + `invite_code` as the seed// Returns a 64-byte Solana secret key (32 bytes private + 32 bytes public key)export function invite_code_to_priv_key(invite_code) { // Hash the invite code with a prefix const pre_hash = "invite:" + invite_code; const sha = createHash("sha256"); const priv_key = crypto.createHash("sha256").update(pre_hash).digest(); // Use ed25519 to get the public key const pub_key = ed.getPublicKey(new Uint8Array(priv_key)); const solana_priv_key = new Uint8Array(64); solana_priv_key.set(priv_key); solana_priv_key.set(pub_key, 32); return solana_priv_key;};