UNPKG

@ghostspeak/sdk

Version:

TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta

229 lines (223 loc) 7.74 kB
import { SolanaClient } from 'gill'; export { SolanaClient } from 'gill'; export { d as deriveAgentPda, f as findProgramDerivedAddress } from './pda-Ce7VYg4T.js'; export { E as ErrorContext, G as GhostSpeakSDKError, R as ReputationTagEngine, T as TokenProgram, j as accounts, c as createErrorContext, d as deriveAssociatedTokenAddress, a as detectTokenProgram, e as enhanceTransactionError, l as features, f as formatTokenAmount, g as getTokenProgramType, k as governance, b as ipfs, i as isToken2022Mint, p as parseTokenAmount, h as privacy, w as withEnhancedErrors } from './feature-flags-B1g0DCPe.js'; export { s as authSignatures, c as createAuthorizationMessage, b as createSignedAuthorization, e as deserializeAuthorization, g as generateNonce, f as getAuthorizationId, h as isAuthorizationExhausted, i as isAuthorizationExpired, d as serializeAuthorization, a as signAuthorizationMessage, j as validateAuthorizationNetwork, v as verifyAuthorizationSignature } from './signature-verification-BDzoR1MG.js'; import { R as ReputationData, J as JobPerformance, a as ReputationCalculationResult, P as PerformanceSnapshot } from './reputation-types-Yebf0Rm_.js'; import '@solana/addresses'; import '@solana/kit'; /** * Centralized Solana Client Utilities using Gill * * This module provides a unified interface for creating and managing * Solana RPC clients using the Gill library. It serves as the single * source of truth for all RPC client operations in the SDK. * * Gill is a modern Solana JavaScript/TypeScript SDK built on top of * @solana/kit (formerly web3.js v2) that provides: * - Simplified client creation * - Built-in transaction confirmation * - Network moniker support (devnet, mainnet, localnet) * * @example * ```typescript * import { createSolanaClient, getDefaultSolanaClient } from './solana-client.js' * * // Create a client with custom endpoint * const client = createSolanaClient({ urlOrMoniker: 'https://my-rpc.com' }) * * // Get the default singleton client * const defaultClient = getDefaultSolanaClient() * * // Use the RPC * const balance = await client.rpc.getBalance(address).send() * ``` */ /** * Configuration options for creating a Solana client */ interface SolanaClientConfig { /** RPC URL or network moniker (devnet, mainnet, localnet, testnet) */ urlOrMoniker: string; } /** * Network monikers supported by Gill */ type NetworkMoniker = 'devnet' | 'mainnet' | 'localnet' | 'testnet'; /** * Create a new Solana client using Gill * * This is a wrapper around Gill's createSolanaClient that provides * additional configuration options and a consistent interface. * * @param config - Configuration options for the client * @returns A new SolanaClient instance * * @example * ```typescript * // Using a network moniker * const devnetClient = createSolanaClient({ urlOrMoniker: 'devnet' }) * * // Using a custom RPC URL * const customClient = createSolanaClient({ * urlOrMoniker: 'https://my-rpc-provider.com' * }) * ``` */ declare function createSolanaClient(config: SolanaClientConfig): SolanaClient<any>; /** * Get or create the default singleton Solana client * * This function provides a singleton pattern for SDK-wide RPC operations. * The client is lazily initialized and reused across all calls. * * If an endpoint is provided and differs from the cached endpoint, * a new client will be created. * * @param endpoint - Optional RPC endpoint or network moniker * @returns The singleton SolanaClient instance * * @example * ```typescript * // Get default client (devnet) * const client = getDefaultSolanaClient() * * // Get client for specific endpoint * const mainnetClient = getDefaultSolanaClient('mainnet') * * // Use custom RPC * const customClient = getDefaultSolanaClient('https://my-rpc.com') * ``` */ declare function getDefaultSolanaClient(endpoint?: string): SolanaClient<any>; /** * Reset the default singleton client * * This is useful for testing or when you need to force a client refresh. * After calling this function, the next call to getDefaultSolanaClient * will create a new client instance. * * @example * ```typescript * // In tests * beforeEach(() => { * resetDefaultClient() * }) * ``` */ declare function resetDefaultClient(): void; /** * Create a network-specific Solana client * * This is a convenience function for creating clients connected * to standard Solana networks using Gill's network moniker support. * * @param network - The network to connect to * @returns A new SolanaClient instance connected to the specified network * * @example * ```typescript * const devnetClient = createNetworkClient('devnet') * const mainnetClient = createNetworkClient('mainnet') * ``` */ declare function createNetworkClient(network: NetworkMoniker): SolanaClient<any>; /** * Check if an endpoint is a network moniker * * @param endpoint - The endpoint string to check * @returns True if the endpoint is a recognized network moniker */ declare function isNetworkMoniker(endpoint: string): endpoint is NetworkMoniker; /** * Get the default RPC URL for a network * * @param network - The network moniker * @returns The default RPC URL for the network */ declare function getDefaultEndpoint(network: NetworkMoniker): string; /** * Detect the network from an RPC endpoint URL * * @param endpoint - The RPC endpoint URL * @returns The detected network or 'unknown' */ declare function detectNetworkFromEndpoint(endpoint: string): NetworkMoniker | 'unknown'; /** * Common utility functions for GhostSpeak SDK */ /** * Convert SOL to lamports */ declare function sol(amount: number): bigint; /** * Convert lamports to SOL */ declare function lamportsToSol(lamports: bigint): number; /** * Advanced reputation calculation engine */ declare class ReputationCalculator { private fraudPatterns; constructor(); /** * Initialize fraud detection patterns */ private initializeFraudPatterns; /** * Calculate reputation update based on job performance */ calculateReputation(currentData: ReputationData, jobPerformance: JobPerformance): ReputationCalculationResult; /** * Apply time-based reputation decay */ private applyTimeDecay; /** * Calculate weighted score based on job performance */ private calculateWeightedScore; /** * Calculate timeliness score based on expected vs actual duration */ private calculateTimelinessScore; /** * Calculate dispute score */ private calculateDisputeScore; /** * Update category-specific reputation */ private updateCategoryReputation; /** * Calculate overall score from category reputations */ private calculateOverallScore; /** * Get reputation tier from score */ private getTierFromScore; /** * Check for badge achievements */ private checkBadgeAchievements; /** * Detect potential fraud patterns */ private detectFraud; /** * Create performance snapshot */ createPerformanceSnapshot(data: ReputationData, newScore: number): PerformanceSnapshot; /** * Calculate reputation slash amount */ calculateSlashAmount(currentScore: number, slashPercentage: number): { newScore: number; slashAmount: number; }; /** * Calculate staking bonus */ calculateStakingBonus(stakeAmount: number): number; } export { type NetworkMoniker, ReputationCalculator, type SolanaClientConfig, createNetworkClient, createSolanaClient, detectNetworkFromEndpoint, getDefaultEndpoint, getDefaultSolanaClient, isNetworkMoniker, lamportsToSol, resetDefaultClient, sol };