Comprehensive JavaScript SDK for building Solana blockchain applications with modern architecture and type safety
93
Evaluation — 93%
↑ 1.29xAgent success when using this tile
Ed25519 key pair generation, digital signatures, and cryptographic operations for Solana blockchain interactions.
Generate Ed25519 key pairs for signing transactions and deriving addresses.
/**
* Standard Web Crypto API key pair interface
*/
interface CryptoKeyPair {
privateKey: CryptoKey;
publicKey: CryptoKey;
}
/**
* Generate a new Ed25519 key pair using Web Crypto API
* @returns Promise resolving to a CryptoKeyPair
*/
function generateKeyPair(): Promise<CryptoKeyPair>;
/**
* Create key pair from raw byte array containing both private and public key data
* @param bytes - ReadonlyUint8Array containing key pair data
* @param extractable - Whether the keys should be extractable (optional, defaults to false)
* @returns Promise resolving to a CryptoKeyPair
*/
function createKeyPairFromBytes(bytes: ReadonlyUint8Array, extractable?: boolean): Promise<CryptoKeyPair>;
/**
* Create key pair from private key bytes only
* @param bytes - 32-byte private key as ReadonlyUint8Array
* @param extractable - Whether the keys should be extractable (defaults to false)
* @returns Promise resolving to a CryptoKeyPair with derived public key
*/
function createKeyPairFromPrivateKeyBytes(bytes: ReadonlyUint8Array, extractable?: boolean): Promise<CryptoKeyPair>;
/**
* Import private key from raw bytes
* @param bytes - 32-byte private key as ReadonlyUint8Array
* @param extractable - Whether the key should be extractable (optional, defaults to false)
* @returns Promise resolving to a CryptoKey
*/
function createPrivateKeyFromBytes(bytes: ReadonlyUint8Array, extractable?: boolean): Promise<CryptoKey>;
/**
* Derive public key from private key
* @param privateKey - CryptoKey containing private key
* @param extractable - Whether the public key should be extractable (defaults to false)
* @returns Promise resolving to public key CryptoKey
*/
function getPublicKeyFromPrivateKey(privateKey: CryptoKey, extractable?: boolean): Promise<CryptoKey>;Usage Examples:
import { generateKeyPair, createKeyPairFromPrivateKeyBytes, getAddressFromPublicKey } from "@solana/web3.js";
// Generate a new key pair
const keyPair = await generateKeyPair();
const { privateKey, publicKey } = keyPair;
// Derive address from public key
const address = await getAddressFromPublicKey(publicKey);
console.log("Address:", address);
// Import existing key pair from private key bytes
const existingPrivateKeyBytes = new Uint8Array(32); // Your private key bytes
const importedKeyPair = await createKeyPairFromPrivateKeyBytes(existingPrivateKeyBytes);Sign data and verify signatures using Ed25519 cryptography.
/**
* Raw signature bytes (64 bytes for Ed25519)
*/
type SignatureBytes = Uint8Array & { readonly __brand: unique symbol };
/**
* Sign arbitrary data with a private key
* @param key - CryptoKey containing private key
* @param data - Data to sign as ReadonlyUint8Array
* @returns Promise resolving to signature bytes
*/
function signBytes(key: CryptoKey, data: ReadonlyUint8Array): Promise<SignatureBytes>;
/**
* Verify a signature against data and public key
* @param key - CryptoKey containing public key
* @param signature - Signature bytes to verify
* @param data - Original data that was signed as ReadonlyUint8Array
* @returns Promise resolving to true if signature is valid
*/
function verifySignature(key: CryptoKey, signature: SignatureBytes, data: ReadonlyUint8Array): Promise<boolean>;Usage Examples:
import { generateKeyPair, signBytes, verifySignature } from "@solana/web3.js";
// Generate key pair for signing
const { privateKey, publicKey } = await generateKeyPair();
// Sign some data
const message = new TextEncoder().encode("Hello, Solana!");
const signature = await signBytes(privateKey, message);
// Verify the signature
const isValid = await verifySignature(publicKey, signature, message);
console.log("Signature valid:", isValid); // trueUtilities for working with signature strings and validation.
/**
* Branded string type for base58-encoded signatures
*/
type Signature = string & { readonly __brand: unique symbol };
/**
* Type guard to check if a string is a valid Signature
* @param putativeSignature - String to check
* @returns True if input is a valid Signature
*/
function isSignature(putativeSignature: string): putativeSignature is Signature;
/**
* Assert that a string is a valid Signature
* @param putativeSignature - String to assert
* @throws Error if input is not a valid Signature
*/
function assertIsSignature(putativeSignature: string): asserts putativeSignature is Signature;
/**
* Convert a string to a Signature type (with validation)
* @param putativeSignature - String to convert
* @returns Signature type
*/
function signature(putativeSignature: string): Signature;Usage Examples:
import { signature, isSignature } from "@solana/web3.js";
// Convert and validate signature string
const signatureString = "2Kb...ABC"; // Base58 signature string
const sig = signature(signatureString);
// Type guard usage
if (isSignature(signatureString)) {
console.log("Valid signature format");
}import { generateKeyPair } from "@solana/web3.js";
// Generate key pair
const keyPair = await generateKeyPair();
// For client-side storage (browser)
// Store in IndexedDB or secure key management system
// NEVER store private keys in localStorage or sessionStorage
// For server-side storage (Node.js)
// Store in encrypted format with proper key derivation
// Consider using hardware security modules (HSMs) for productionimport {
createKeyPairFromPrivateKeyBytes,
getAddressFromPublicKey
} from "@solana/web3.js";
// Derive multiple addresses from a master key
async function deriveAddresses(masterPrivateKey: Uint8Array, count: number): Promise<Address[]> {
const addresses: Address[] = [];
for (let i = 0; i < count; i++) {
// Create deterministic private key (implement your own derivation logic)
const derivedPrivateKey = deriveChildKey(masterPrivateKey, i);
// Create key pair
const keyPair = await createKeyPairFromPrivateKeyBytes(derivedPrivateKey);
// Get address
const address = await getAddressFromPublicKey(keyPair.publicKey);
addresses.push(address);
}
return addresses;
}/**
* Raw signature bytes (64 bytes for Ed25519)
*/
type SignatureBytes = Uint8Array & { readonly __brand: unique symbol };
/**
* Branded string type for base58-encoded signatures
*/
type Signature = string & { readonly __brand: unique symbol };Install with Tessl CLI
npx tessl i tessl/npm-solana--web3-jsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10