@opendatalabs/vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts.
101 lines (100 loc) • 3.42 kB
TypeScript
/**
* Provides platform-agnostic cryptographic utility functions.
*
* @remarks
* This module contains utility functions for cryptographic operations that work
* consistently across Node.js and browser environments. All functions use `Uint8Array`
* exclusively for binary data to ensure cross-platform compatibility.
*
* @category Cryptography
*/
/**
* Processes a wallet public key for cryptographic operations.
*
* @remarks
* Converts hex string public keys to Uint8Array format.
* For normalization to uncompressed format, use the crypto provider's
* normalizeToUncompressed method.
*
* @param publicKey - The wallet public key as hex string or byte array.
* @returns The public key as a Uint8Array.
*
* @example
* ```typescript
* const keyBytes = processWalletPublicKey("0x04...");
* const normalized = provider.normalizeToUncompressed(keyBytes);
* ```
*/
export declare function processWalletPublicKey(publicKey: string | Uint8Array): Uint8Array;
/**
* Processes a wallet private key for cryptographic operations.
*
* @param privateKey - The wallet private key as hex string or byte array.
* @returns The private key as a Uint8Array.
*
* @example
* ```typescript
* const key = processWalletPrivateKey("0x...");
* console.log(key.length); // 32 (secp256k1 private key)
* ```
*/
export declare function processWalletPrivateKey(privateKey: string | Uint8Array): Uint8Array;
/**
* Parses legacy eccrypto-format encrypted data buffer.
* Format: [iv(16)][ephemPublicKey(65)][ciphertext(variable)][mac(32)]
*
* @param encryptedBuffer - Buffer containing encrypted data in eccrypto format
* @returns Parsed encrypted data components
*/
export declare function parseEncryptedDataBuffer(encryptedBuffer: Uint8Array): {
iv: Uint8Array;
ephemPublicKey: Uint8Array;
ciphertext: Uint8Array;
mac: Uint8Array;
};
/**
* Generates a deterministic seed from a message for key derivation
*
* @param message - Message to derive seed from
* @returns Seed as Uint8Array
*/
export declare function generateSeed(message: string): Uint8Array;
/**
* Compares two Uint8Arrays for equality
*
* @param a - First array
* @param b - Second array
* @returns True if arrays are equal
*/
export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
/**
* Creates a copy of a Uint8Array
*
* @param bytes - Array to copy
* @returns New array with same contents
*/
export declare function copyBytes(bytes: Uint8Array): Uint8Array;
/**
* Validates a secp256k1 public key format
*
* @param publicKey - Public key to validate
* @returns True if valid format (33, 65, or 64 bytes)
*/
export declare function isValidPublicKeyFormat(publicKey: Uint8Array): boolean;
/**
* Validates a secp256k1 private key format
*
* @param privateKey - Private key to validate
* @returns True if valid format (32 bytes)
*/
export declare function isValidPrivateKeyFormat(privateKey: Uint8Array): boolean;
/**
* Asserts that a public key is in uncompressed format (65 bytes with 0x04 prefix).
* This validation function only checks format, it does not transform keys.
* For key normalization (including decompression), use the crypto provider's
* normalizeToUncompressed method.
*
* @param publicKey - Public key to validate
* @throws {Error} When public key is not in uncompressed format
*/
export declare function assertUncompressedPublicKey(publicKey: Uint8Array): void;