UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

123 lines 4.14 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var constants_exports = {}; __export(constants_exports, { CIPHER: () => CIPHER, CURVE: () => CURVE, FORMAT: () => FORMAT, KDF: () => KDF, MAC: () => MAC, SECURITY: () => SECURITY }); module.exports = __toCommonJS(constants_exports); const CURVE = { /** The elliptic curve used (secp256k1 - same as Bitcoin/Ethereum) */ name: "secp256k1", /** Private key length in bytes */ PRIVATE_KEY_LENGTH: 32, /** Compressed public key length in bytes (0x02 or 0x03 prefix + 32 bytes) */ COMPRESSED_PUBLIC_KEY_LENGTH: 33, /** Uncompressed public key length in bytes (0x04 prefix + 64 bytes) */ UNCOMPRESSED_PUBLIC_KEY_LENGTH: 65, /** ECDH shared secret X coordinate length */ SHARED_SECRET_LENGTH: 32, /** Public key prefixes */ PREFIX: { /** Uncompressed public key prefix */ UNCOMPRESSED: 4, /** Compressed public key prefix for even Y */ COMPRESSED_EVEN: 2, /** Compressed public key prefix for odd Y */ COMPRESSED_ODD: 3 }, /** X coordinate starts at byte 1 (after prefix) */ X_COORDINATE_OFFSET: 1, /** X coordinate ends at byte 33 (1 + 32) */ X_COORDINATE_END: 33 }; const CIPHER = { /** Cipher algorithm - must match eccrypto */ algorithm: "aes-256-cbc", /** AES key length in bytes */ KEY_LENGTH: 32, /** Initialization vector length in bytes */ IV_LENGTH: 16, /** Block size for AES */ BLOCK_SIZE: 16 }; const KDF = { /** Hash algorithm for key derivation - must match eccrypto */ algorithm: "sha512", /** Output length of SHA-512 in bytes */ OUTPUT_LENGTH: 64, /** Encryption key slice (first 32 bytes of KDF output) */ ENCRYPTION_KEY_OFFSET: 0, ENCRYPTION_KEY_LENGTH: 32, /** MAC key slice (last 32 bytes of KDF output) */ MAC_KEY_OFFSET: 32, MAC_KEY_LENGTH: 32 }; const MAC = { /** MAC algorithm - must match eccrypto */ algorithm: "sha256", /** HMAC-SHA256 output length in bytes */ LENGTH: 32 }; const FORMAT = { /** Offsets for each component in serialized format */ IV_OFFSET: 0, IV_LENGTH: CIPHER.IV_LENGTH, /** Ephemeral public key (always uncompressed in eccrypto format) */ EPHEMERAL_KEY_OFFSET: CIPHER.IV_LENGTH, EPHEMERAL_KEY_LENGTH: CURVE.UNCOMPRESSED_PUBLIC_KEY_LENGTH, /** Ciphertext starts after IV and ephemeral key */ CIPHERTEXT_OFFSET: CIPHER.IV_LENGTH + CURVE.UNCOMPRESSED_PUBLIC_KEY_LENGTH, /** MAC is always the last 32 bytes */ MAC_LENGTH: MAC.LENGTH, /** Minimum size of encrypted data (IV + ephemKey + MAC, no ciphertext) */ MIN_ENCRYPTED_LENGTH: CIPHER.IV_LENGTH + CURVE.UNCOMPRESSED_PUBLIC_KEY_LENGTH + MAC.LENGTH, /** * Helper to calculate total length of encrypted data * * @param ciphertextLength - Length of the ciphertext portion * @returns Total length including all components */ getTotalLength: (ciphertextLength) => CIPHER.IV_LENGTH + CURVE.UNCOMPRESSED_PUBLIC_KEY_LENGTH + ciphertextLength + MAC.LENGTH }; const SECURITY = { /** Overwrite patterns for secure data clearing */ CLEAR_PATTERNS: { ZEROS: 0, ONES: 255, /** Pattern multiplier for third pass */ PATTERN_MULTIPLIER: 7, /** Pattern offset for third pass */ PATTERN_OFFSET: 13 } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { CIPHER, CURVE, FORMAT, KDF, MAC, SECURITY }); //# sourceMappingURL=constants.cjs.map