@pod-protocol/sdk
Version:
TypeScript SDK for PoD Protocol - AI agent communication on Solana
181 lines • 6.53 kB
TypeScript
import type { Address } from "@solana/addresses";
import { MessageType } from "./types";
export { MessageType } from "./types";
/**
* Calculate PDA for an agent account
*/
export declare function findAgentPDA(walletAddress: Address, programId: Address): Promise<[Address, number]>;
/**
* Calculate PDA for a message account
*/
export declare function findMessagePDA(sender: Address, recipient: Address, messageId: string, programId: Address): Promise<[Address, number]>;
/**
* Calculate PDA for a channel account
*/
export declare function findChannelPDA(channelId: string, creator: Address, programId: Address): Promise<[Address, number]>;
/**
* Calculate PDA for an escrow account
*/
export declare function findEscrowPDA(channelAddress: Address, depositorAddress: Address, programId: Address): Promise<[Address, number]>;
/**
* Convert MessageType enum to numeric ID
*/
export declare function getMessageTypeId(messageType: MessageType, customValue?: number): number;
/**
* Convert numeric ID back to MessageType
*/
export declare function parseMessageTypeFromNumber(id: number): {
type: MessageType;
customValue?: number;
};
/**
* Alias for parseMessageTypeFromNumber for backward compatibility
*/
export declare const getMessageTypeFromId: typeof parseMessageTypeFromNumber;
/**
* Convert MessageType enum to program format (object with empty record)
*/
export declare function serializeMessageTypeToProgram(messageType: MessageType, customValue?: number): any;
/**
* Alias for serializeMessageTypeToProgram for backward compatibility
*/
export declare const convertMessageTypeToProgram: typeof serializeMessageTypeToProgram;
/**
* Convert program format back to MessageType enum
*/
export declare function parseMessageTypeFromProgram(programType: any): {
type: MessageType;
customValue?: number;
};
/**
* Alias for parseMessageTypeFromProgram for backward compatibility
*/
export declare const convertMessageTypeFromProgram: typeof parseMessageTypeFromProgram;
/**
* Handle legacy object-based message type format for backward compatibility
*/
export declare function getMessageTypeIdFromObject(msg: any): number;
/**
* Create a SHA-256 hash of message payload
*/
export declare function hashPayload(payload: string | Uint8Array): Promise<Uint8Array>;
/**
* Retry a function with exponential backoff
*/
export declare function retry<T>(fn: () => Promise<T>, maxAttempts?: number, delay?: number): Promise<T>;
/**
* Check if an agent has a specific capability
*/
export declare function hasCapability(capabilities: number, capability: number): boolean;
/**
* Add a capability to an agent's capabilities bitmask
*/
export declare function addCapability(capabilities: number, capability: number): number;
/**
* Remove a capability from an agent's capabilities bitmask
*/
export declare function removeCapability(capabilities: number, capability: number): number;
/**
* Get capability names from bitmask
*/
export declare function getCapabilityNames(capabilities: number): string[];
/**
* Convert lamports to SOL
*/
export declare function lamportsToSol(lamports: number, decimals?: number): number;
/**
* Convert SOL to lamports
*/
export declare function solToLamports(sol: number): number;
/**
* Check if a string is a valid Solana public key
*/
/**
* Convert timestamp to number, handling BN and other formats
*/
export declare function convertTimestamp(timestamp: any, fallback?: any): number;
/**
* Get timestamp from account data
*/
export declare function getAccountTimestamp(account: any): number;
/**
* Get creation timestamp from account data
*/
export declare function getAccountCreatedAt(account: any): number;
/**
* Get last updated timestamp from account data
*/
export declare function getAccountLastUpdated(account: any): number;
/**
* Sleep for a given number of milliseconds
*/
export declare function sleep(ms: number): Promise<void>;
/**
* Format a public key for display (show first 4 and last 4 characters)
*/
export declare function formatAddress(addr: Address | string, short?: boolean): string;
/**
* Validate and parse a message type string
*/
export declare function parseMessageTypeFromString(typeStr: string): MessageType;
/**
* Generate a unique message ID for tracking
*/
export declare function generateMessageId(): string;
/**
* Calculate the estimated fee for a transaction
*/
export declare function estimateTransactionFee(messageLength: number, baseFee?: number): number;
/**
* Convert duration to human readable format
*/
export declare function formatDuration(ms: number): string;
/**
* Convert bytes to human readable format
*/
export declare function formatBytes(bytes: number): string;
/**
* Validate capability combination
*/
export declare function validateCapabilities(capabilities: number): boolean;
/**
* Get channel visibility string
*/
export declare function getVisibilityString(visibility: any): string;
/**
* Calculate PDA for a channel participant
*/
export declare function findParticipantPDA(channelAddress: Address, agentAddress: Address, programId: Address): Promise<[Address, number]>;
/**
* Calculate PDA for a channel invitation
*/
export declare function findInvitationPDA(channelAddress: Address, inviteeAddress: Address, programId: Address): Promise<[Address, number]>;
/**
* Calculate PDA for a channel message account
*/
export declare function findChannelMessagePDA(channel: Address, user: Address, nonce: number, programId?: Address): Promise<[Address, number]>;
/**
* Create a deterministic seed for account derivation
*/
export declare function createSeed(input: string): Buffer;
/**
* Wait for transaction confirmation with retry
*/
export declare function confirmTransaction(connection: any, signature: string, maxRetries?: number, delay?: number): Promise<boolean>;
/**
* Convert various address formats to Address type
*/
export declare function normalizeAddress(addr: string | Address): Address;
/**
* Format SOL amounts
*/
export declare function formatSOL(lamports: number | bigint): string;
/**
* Validate public key format (for backward compatibility)
*/
export declare function isValidAddress(pubkey: Address | string): boolean;
export declare function getMessageTypeName(type: MessageType): string;
export declare function parseMessageTypeFromId(id: number): any;
export declare function serializeMessageType(messageType: any): number;
export declare function mapMessageTypeToNumber(type: string): MessageType;
//# sourceMappingURL=utils.d.ts.map