@gorbchain-xyz/chaindecode
Version:
GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.
98 lines (97 loc) • 3.23 kB
TypeScript
/**
* Utility functions for cryptographic operations
*/
export declare const ENCRYPTION_ALGORITHM = "aes-256-gcm";
export declare const KEY_SIZE = 32;
export declare const IV_SIZE = 16;
export declare const SALT_SIZE = 32;
export declare const AUTH_TAG_SIZE = 16;
export declare const KEY_DERIVATION_ITERATIONS = 100000;
/**
* Generate cryptographically secure random bytes
*/
export declare function generateRandomBytes(length: number): Uint8Array;
/**
* Derive a key from password/secret using PBKDF2
*/
export declare function deriveKey(secret: Uint8Array, salt: Uint8Array, iterations?: number): Uint8Array;
/**
* Generate a key pair for encryption (compatible with Solana format)
*/
export declare function generateKeyPair(): {
publicKey: Uint8Array;
privateKey: Uint8Array;
};
/**
* Convert ed25519 public key to curve25519 for encryption
*/
export declare function ed25519ToCurve25519PublicKey(ed25519PublicKey: Uint8Array): Uint8Array;
/**
* Convert ed25519 private key to curve25519 for encryption
*/
export declare function ed25519ToCurve25519PrivateKey(ed25519PrivateKey: Uint8Array): Uint8Array;
/**
* Perform symmetric key exchange
* This ensures both sides get the same shared secret regardless of call order
*/
export declare function performKeyExchange(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
/**
* Encrypt data using AES-256-GCM
*/
export declare function encryptAES(data: Uint8Array, key: Uint8Array, iv?: Uint8Array): {
encrypted: Uint8Array;
iv: Uint8Array;
authTag: Uint8Array;
};
/**
* Decrypt data using AES-256-GCM
*/
export declare function decryptAES(encrypted: Uint8Array, key: Uint8Array, iv: Uint8Array, authTag: Uint8Array): Uint8Array;
/**
* Sign data using ed25519
*/
export declare function signData(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array;
/**
* Verify signature using ed25519
*/
export declare function verifySignature(data: string | Uint8Array, signature: Uint8Array | string, publicKey: Uint8Array | string): boolean;
/**
* Compress data using zlib
*/
export declare function compressData(data: Uint8Array): Promise<Uint8Array>;
/**
* Decompress data using zlib
*/
export declare function decompressData(compressed: Uint8Array): Promise<Uint8Array>;
/**
* Generate a deterministic ID from multiple inputs
*/
export declare function generateId(...inputs: (string | Uint8Array)[]): string;
/**
* Combine multiple buffers
*/
export declare function combineBuffers(...buffers: Uint8Array[]): Uint8Array;
/**
* Split a buffer at specific positions
*/
export declare function splitBuffer(buffer: Uint8Array, ...lengths: number[]): Uint8Array[];
/**
* Convert string to Uint8Array
*/
export declare function stringToBytes(str: string): Uint8Array;
/**
* Convert Uint8Array to string
*/
export declare function bytesToString(bytes: Uint8Array): string;
/**
* Validate Solana public key
*/
export declare function isValidPublicKey(publicKey: string): boolean;
/**
* Get current timestamp in seconds
*/
export declare function getCurrentTimestamp(): number;
/**
* Check if a timestamp has expired
*/
export declare function hasExpired(timestamp: number, ttlSeconds: number): boolean;