@nealireverse_dev/utils
Version:
Utilities for internal use
134 lines (130 loc) • 3.81 kB
TypeScript
import { Keypair as Keypair$1, PublicKey } from '@solana/web3.js';
type KeypairInput = number[] | string | Keypair$1 | Uint8Array;
/**
* Options for creating Keypair
*/
interface KeypairOptions {
/** Keypair input data in various formats */
keypair: KeypairInput;
/** Flag for protecting keypair with encryption */
protect_keypair?: boolean;
}
/**
* Keypair encryption result
*/
interface EncryptedKeypair {
/** Encrypted data in base58 format */
encryptedData: string;
/** Encryption metadata */
metadata: {
algorithm: string;
version: string;
timestamp: number;
};
}
/**
* Decryption metadata
*/
interface DecryptionMetadata {
/** Encryption algorithm */
algorithm: string;
/** Algorithm version */
version: string;
/** Creation timestamp */
timestamp: number;
}
/**
* Keypair validation result
*/
interface KeypairValidation {
/** Keypair validity */
isValid: boolean;
/** Keypair length in bytes */
length: number;
/** Input data format */
format: 'array' | 'base58' | 'solana' | 'uint8array' | 'file' | 'unknown';
/** Error messages */
errors?: string[];
}
/**
* Options for keypair export
*/
interface ExportOptions {
/** Export format */
format: 'array' | 'base58' | 'uint8array' | 'encrypted';
/** Additional encryption options */
encryptionOptions?: {
algorithm?: string;
iterations?: number;
};
}
/**
* Keypair information
*/
interface KeypairInfo {
/** Keypair length in bytes */
length: number;
/** Whether keypair is protected */
isProtected: boolean;
/** Original data format */
originalFormat: string;
/** Creation timestamp */
createdAt: number;
/** Data hash for integrity verification */
hash?: string;
}
/**
* Class for working with key pairs
* Supports various input formats and encryption
*/
declare class Keypair {
private data;
private isProtected;
private originalFormat;
private createdAt;
private hash;
private static walletCache;
/**
* Creates a new Keypair instance
* @param data - Keypair data as Uint8Array
* @param isProtected - Keypair protection flag
* @param originalFormat - Original data format
*/
constructor(data: Uint8Array, isProtected?: boolean, originalFormat?: string);
/**
* Creates Keypair from various input formats
* @param options - Options for creating Keypair
* @returns Solana Keypair instance
* @throws {Error} If input data is incorrect
*/
static from(options: KeypairOptions): Keypair$1;
static fromKeypair(options: KeypairOptions): Keypair;
static fromArray(array: number[]): Keypair;
static fromBase58(base58String: string): Keypair;
static fromFile(filePath: string): Keypair;
static fromSolanaKeypair(solanaKeypair: Keypair$1): Keypair;
toArray(): number[];
toBase58(): string;
toUint8Array(): Uint8Array;
toSolanaKeypair(): Keypair$1;
getPublicKey(): PublicKey;
export(options: ExportOptions): number[] | string | Uint8Array | EncryptedKeypair;
encrypt(): string;
static decrypt(encryptedData: string): Keypair;
getProtected(): boolean;
getHash(): string;
getLength(): number;
getInfo(): KeypairInfo;
static getCacheInfo(): {
size: number;
};
static generate(): Keypair;
static clearCache(): void;
validate(): KeypairValidation;
private generateHash;
private static isFilePath;
private static isBase58;
private static readFile;
private static parseKeypairData;
}
export { type DecryptionMetadata, type EncryptedKeypair, type ExportOptions, Keypair, type KeypairInfo, type KeypairInput, type KeypairOptions, type KeypairValidation };