@opendatalabs/vana-sdk
Version:
A TypeScript library for interacting with Vana Network smart contracts.
112 lines (111 loc) • 3.88 kB
TypeScript
/**
* ECIES Constants and Format Specification
*
* These constants define the eccrypto-compatible ECIES format used throughout the SDK.
* Maintaining these exact values ensures backward compatibility with data encrypted
* using the original eccrypto library.
*/
/**
* Elliptic curve parameters
*/
export declare const CURVE: {
/** The elliptic curve used (secp256k1 - same as Bitcoin/Ethereum) */
readonly name: "secp256k1";
/** Private key length in bytes */
readonly PRIVATE_KEY_LENGTH: 32;
/** Compressed public key length in bytes (0x02 or 0x03 prefix + 32 bytes) */
readonly COMPRESSED_PUBLIC_KEY_LENGTH: 33;
/** Uncompressed public key length in bytes (0x04 prefix + 64 bytes) */
readonly UNCOMPRESSED_PUBLIC_KEY_LENGTH: 65;
/** ECDH shared secret X coordinate length */
readonly SHARED_SECRET_LENGTH: 32;
/** Public key prefixes */
readonly PREFIX: {
/** Uncompressed public key prefix */
readonly UNCOMPRESSED: 4;
/** Compressed public key prefix for even Y */
readonly COMPRESSED_EVEN: 2;
/** Compressed public key prefix for odd Y */
readonly COMPRESSED_ODD: 3;
};
/** X coordinate starts at byte 1 (after prefix) */
readonly X_COORDINATE_OFFSET: 1;
/** X coordinate ends at byte 33 (1 + 32) */
readonly X_COORDINATE_END: 33;
};
/**
* Symmetric encryption parameters (AES-256-CBC)
*/
export declare const CIPHER: {
/** Cipher algorithm - must match eccrypto */
readonly algorithm: "aes-256-cbc";
/** AES key length in bytes */
readonly KEY_LENGTH: 32;
/** Initialization vector length in bytes */
readonly IV_LENGTH: 16;
/** Block size for AES */
readonly BLOCK_SIZE: 16;
};
/**
* Key derivation function parameters
*/
export declare const KDF: {
/** Hash algorithm for key derivation - must match eccrypto */
readonly algorithm: "sha512";
/** Output length of SHA-512 in bytes */
readonly OUTPUT_LENGTH: 64;
/** Encryption key slice (first 32 bytes of KDF output) */
readonly ENCRYPTION_KEY_OFFSET: 0;
readonly ENCRYPTION_KEY_LENGTH: 32;
/** MAC key slice (last 32 bytes of KDF output) */
readonly MAC_KEY_OFFSET: 32;
readonly MAC_KEY_LENGTH: 32;
};
/**
* Message authentication code parameters
*/
export declare const MAC: {
/** MAC algorithm - must match eccrypto */
readonly algorithm: "sha256";
/** HMAC-SHA256 output length in bytes */
readonly LENGTH: 32;
};
/**
* ECIES encrypted data format offsets and lengths
* Format: [iv(16)][ephemPublicKey(65)][ciphertext(variable)][mac(32)]
*/
export declare const FORMAT: {
/** Offsets for each component in serialized format */
readonly IV_OFFSET: 0;
readonly IV_LENGTH: 16;
/** Ephemeral public key (always uncompressed in eccrypto format) */
readonly EPHEMERAL_KEY_OFFSET: 16;
readonly EPHEMERAL_KEY_LENGTH: 65;
/** Ciphertext starts after IV and ephemeral key */
readonly CIPHERTEXT_OFFSET: number;
/** MAC is always the last 32 bytes */
readonly MAC_LENGTH: 32;
/** Minimum size of encrypted data (IV + ephemKey + MAC, no ciphertext) */
readonly MIN_ENCRYPTED_LENGTH: number;
/**
* Helper to calculate total length of encrypted data
*
* @param ciphertextLength - Length of the ciphertext portion
* @returns Total length including all components
*/
readonly getTotalLength: (ciphertextLength: number) => number;
};
/**
* Security constants for data clearing
*/
export declare const SECURITY: {
/** Overwrite patterns for secure data clearing */
readonly CLEAR_PATTERNS: {
readonly ZEROS: 0;
readonly ONES: 255;
/** Pattern multiplier for third pass */
readonly PATTERN_MULTIPLIER: 7;
/** Pattern offset for third pass */
readonly PATTERN_OFFSET: 13;
};
};