UNPKG

@pod-protocol/sdk

Version:

TypeScript SDK for PoD Protocol - AI agent communication on Solana

179 lines 4.74 kB
/** * Web3.js v2 Compatibility Utilities * * Provides type conversions and compatibility layer between: * - Web3.js v1.x and v2.0 * - Anchor types and Web3.js v2.0 types * - Legacy SDK types and modern types */ import type { Address } from "@solana/addresses"; import type { KeyPairSigner } from "@solana/signers"; import type { Rpc } from "@solana/rpc"; type Signature = string; type TransactionMessage = { version: number; [key: string]: any; }; import { Wallet } from "@coral-xyz/anchor"; /** * Type Conversion Utilities */ export declare class TypeConverter { /** * Convert string to Address (Web3.js v2) */ static toAddress(input: string | Address): Address; /** * Convert Address to string */ static toString(input: Address | string): string; /** * Convert array of strings to array of Addresses */ static toAddresses(inputs: (string | Address)[]): Address[]; /** * Convert string to Signature (Web3.js v2) */ static toSignature(input: string | Signature): Signature; /** * Convert number/bigint to BigInt */ static toBigInt(input: number | bigint | string): bigint; /** * Convert BigInt to number (with safety check) */ static toNumber(input: bigint | number, maxSafeValue?: number): number; /** * Safely convert potentially unsafe values to safe numbers */ static toSafeNumber(input: any, fallback?: number): number; } /** * Wallet Compatibility Layer */ export declare class WalletAdapter { /** * Create a Web3.js v2 KeyPairSigner from various inputs */ static createKeyPairSigner(input?: { privateKey?: Uint8Array; secretKey?: number[]; }): Promise<KeyPairSigner>; /** * Convert Anchor Wallet to KeyPairSigner (best effort) */ static convertAnchorWallet(wallet: Wallet): { address: Address; signMessages: (messages: any[]) => Promise<any[]>; }; /** * Check if object is a valid KeyPairSigner */ static isKeyPairSigner(obj: any): obj is KeyPairSigner; /** * Check if object is an Anchor Wallet */ static isAnchorWallet(obj: any): obj is Wallet; } /** * RPC Compatibility Layer */ export declare class RpcAdapter { /** * Create a compatible RPC client wrapper */ static createCompatibleRpc(endpoint: string): { rpc: Rpc<any>; getBalance: (address: Address) => Promise<bigint>; getAccountInfo: (address: Address) => Promise<any>; sendTransaction: (transaction: any) => Promise<Signature>; }; } /** * Transaction Builder Compatibility */ export declare class TransactionBuilder { private instructions; private signers; private feePayer?; /** * Add instruction to transaction */ addInstruction(instruction: any): this; /** * Add multiple instructions */ addInstructions(instructions: any[]): this; /** * Set fee payer */ setFeePayer(payer: Address | KeyPairSigner): this; /** * Add signer */ addSigner(signer: KeyPairSigner): this; /** * Build transaction message (Web3.js v2 format) */ buildTransactionMessage(): Promise<TransactionMessage>; /** * Clear builder state */ clear(): this; /** * Get current state */ getState(): { instructionCount: number; signerCount: number; hasFeePayer: boolean; }; } /** * Legacy API Compatibility */ export declare class LegacyCompat { /** * Convert legacy PublicKey to Web3.js v2 Address */ static publicKeyToAddress(publicKey: any): Address; /** * Convert legacy Keypair to KeyPairSigner */ static keypairToSigner(keypair: any): Promise<KeyPairSigner>; /** * Convert legacy Connection to RPC client */ static connectionToRpc(connection: any): any; } /** * Validation Utilities */ export declare class ValidationUtils { /** * Validate Solana address */ static isValidAddress(input: any): boolean; /** * Validate signature */ static isValidSignature(input: any): boolean; /** * Validate numeric input */ static isValidNumber(input: any, options?: { min?: number; max?: number; allowBigInt?: boolean; }): boolean; } export declare const web3Compat: { TypeConverter: typeof TypeConverter; WalletAdapter: typeof WalletAdapter; RpcAdapter: typeof RpcAdapter; TransactionBuilder: typeof TransactionBuilder; LegacyCompat: typeof LegacyCompat; ValidationUtils: typeof ValidationUtils; }; export default web3Compat; //# sourceMappingURL=web3-compat.d.ts.map