@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
85 lines • 2.61 kB
TypeScript
/**
* @purpose Conversion helpers for @solana/web3.js compatibility
*
* Converts between @solana/kit and @solana/web3.js instruction formats.
*/
import type { PublicKeyConstructor } from './config';
import type { ReadonlyUint8Array } from '@solana/kit';
/**
* @solana/kit instruction format (Codama output)
*/
export interface KitInstruction {
programAddress: string;
accounts?: Array<{
address: string;
role: number;
}>;
data?: ReadonlyUint8Array | Uint8Array;
}
/**
* @solana/web3.js instruction format with string addresses
*/
export interface Web3jsInstructionWithStrings {
keys: Array<{
pubkey: string;
isWritable: boolean;
isSigner: boolean;
}>;
programId: string;
data: ReadonlyUint8Array | Uint8Array;
}
/**
* @solana/web3.js instruction format with PublicKey instances
*/
export interface Web3jsInstructionWithPublicKeys<TPublicKey = any> {
keys: Array<{
pubkey: TPublicKey;
isWritable: boolean;
isSigner: boolean;
}>;
programId: TPublicKey;
data: ReadonlyUint8Array | Uint8Array;
}
/**
* Convert @solana/kit instruction to @solana/web3.js format
*
* @param kitInstruction - Instruction in @solana/kit format (from Codama)
* @param PublicKey - Optional PublicKey constructor for web3.js compatibility
* @returns Instruction in @solana/web3.js format
*
* @example
* ```typescript
* // Without PublicKey - returns string addresses
* const web3Ix = toWeb3Instruction(kitIx);
* // web3Ix.keys[0].pubkey is a string
*
* // With PublicKey - returns PublicKey instances
* import { PublicKey } from '@solana/web3.js';
* const web3Ix = toWeb3Instruction(kitIx, PublicKey);
* // web3Ix.keys[0].pubkey is a PublicKey instance
* ```
*/
export declare function toWeb3Instruction<TPublicKey = any>(kitInstruction: KitInstruction, PublicKey?: PublicKeyConstructor<TPublicKey>): Web3jsInstructionWithPublicKeys<TPublicKey> | Web3jsInstructionWithStrings;
/**
* Convert PublicKey or Address to string
*
* Helper function for normalizing addresses from different libraries.
*
* @param value - Address as string or PublicKey instance
* @returns Base58-encoded address string
*
* @example
* ```typescript
* // String address (passthrough)
* const addr1 = toAddress("9WzDXw...");
*
* // web3.js PublicKey
* import { PublicKey } from '@solana/web3.js';
* const pubkey = new PublicKey("9WzDXw...");
* const addr2 = toAddress(pubkey);
* ```
*/
export declare function toAddress(value: string | {
toBase58(): string;
}): string;
//# sourceMappingURL=web3js.d.ts.map