UNPKG

xypriss-security

Version:

Advanced High-Performance Security Framework. Military-grade encryption, post-quantum resilience, and fortified data structures.

90 lines 3.45 kB
"use strict"; /*************************************************************************** * XyPriss Security Core - Main Class ****************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.getByteLength = exports.isValidByteLength = exports.XyPrissSecurity = void 0; const bridge_1 = require("./bridge"); const constants_1 = require("../utils/constants"); const strulink_1 = require("strulink"); /** * ### XyPrissSecurity Main Class * * The primary interface for the XyPriss Security framework. */ class XyPrissSecurity { /** * Generates a secure API key with a prefix and timestamp for management. * * @param options - Configuration for the API key format and length. * @returns A structured, cryptographically strong API key. */ static generateAPIKey(options = {}) { const prefix = options.prefix || "X"; const separator = options.separator || ""; const randomLength = options.randomPartLength || 32; const includeTimestamp = options.includeTimestamp !== undefined ? options.includeTimestamp : false; // default to: false // console.log("includeTimestamp: ", includeTimestamp); //"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" const random = bridge_1.Bridge.generatePassword(randomLength, constants_1.C.GenP); // C.GenP + "+/" // console.log("Randomed: ", random); let key = `${prefix}${separator}${random}`; if (includeTimestamp) { key = `${prefix}${separator}${Date.now()}${separator}${random}`; } let enc = options.encoding; if (enc) { if (enc === "hex") { enc = "rawHex"; options.encoding = "rawHex"; } const str = strulink_1.__strl__.encode(key, enc); return str; } return key; } /** * Performs an environment security check to ensure integrity. */ static verifyRuntimeSecurity() { //FIXME return true; // always true } /** * Returns the actual byte length of a string (UTF-8 encoded). * Useful for strict buffer checks where character count differs from byte count. * * @param str - The string to measure. * @returns The number of bytes in the string. */ static getByteLength(str) { return bridge_1.Bridge.getByteLength(str); } /** * Verifies if a string has exactly the expected byte length. * * @param str - The string to check. * @param expectedLength - The expected number of bytes. * @returns True if the string byte length matches expectedLength. */ static isValidByteLength(str, expectedLength) { return bridge_1.Bridge.isValidByteLength(str, expectedLength); } } exports.XyPrissSecurity = XyPrissSecurity; /** * Verifies if a string has exactly the expected byte length (UTF-8). * * @param str - The string to check. * @param length - The expected number of bytes. * @returns True if the byte length matches, false otherwise. */ exports.isValidByteLength = XyPrissSecurity.isValidByteLength; /** * Returns the actual byte length of a string (UTF-8). * * @param str - The string to measure. * @returns The number of bytes. */ exports.getByteLength = XyPrissSecurity.getByteLength; //# sourceMappingURL=XyPrissSecurity.js.map