xypriss-security 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NEHONIX INC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # XyPriss Security
2
+
3
+ [![npm version](https://badge.fury.io/js/xypriss-security.svg)](https://badge.fury.io/js/xypriss-security)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **XyPriss Security** is an advanced JavaScript security library designed for enterprise-grade applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applications.
8
+
9
+ ## 🔒 Key Features
10
+
11
+ ### Secure Data Structures
12
+
13
+ - **SecureArray**: Military-grade encrypted arrays with AES-256-CTR-HMAC
14
+ - **SecureString**: Protected string handling with automatic memory cleanup
15
+ - **SecureObject**: Encrypted object storage with metadata management
16
+ - **SecureBuffer**: Protected memory allocation with secure wiping
17
+
18
+ ### Cryptographic Operations
19
+
20
+ - **Token Generation**: Secure random tokens with configurable entropy
21
+ - **Password Management**: Argon2ID hashing with pepper support
22
+ - **Hash Functions**: SHA-256/512, BLAKE3, with timing-safe operations
23
+ - **Key Derivation**: PBKDF2, Argon2, scrypt implementations
24
+
25
+ ### Advanced Security Features
26
+
27
+ - **Quantum-Resistant Cryptography**: Post-quantum algorithms (Kyber, Dilithium)
28
+ - **Tamper-Evident Logging**: Immutable audit trails with cryptographic verification
29
+ - **Fortified Functions**: Tamper-resistant function execution with integrity checks
30
+ - **Side-Channel Protection**: Timing-safe operations and memory protection
31
+
32
+ ### Enterprise Features
33
+
34
+ - **Zero Dependencies**: Self-contained with no external dependencies
35
+ - **Browser & Node.js**: Universal compatibility across environments
36
+ - **TypeScript Native**: Full type safety and IntelliSense support
37
+ - **Performance Optimized**: Benchmarked for high-throughput applications
38
+
39
+ ## 📦 Installation
40
+
41
+ ```bash
42
+ npm install xypriss-security
43
+ ```
44
+
45
+ For use with XyPriss framework:
46
+
47
+ ```bash
48
+ npm install xypriss xypriss-security
49
+ ```
50
+
51
+ ## 🚀 Quick Start
52
+
53
+ ### Basic Usage
54
+
55
+ ```typescript
56
+ import {
57
+ XyPrissSecurity,
58
+ SecureString,
59
+ SecureArray,
60
+ Hash,
61
+ SecureRandom,
62
+ } from "xypriss-security";
63
+
64
+ // Initialize the security library
65
+ const security = new XyPrissSecurity();
66
+
67
+ // Create secure strings
68
+ const securePassword = new SecureString("my-secret-password");
69
+ console.log(securePassword.length); // 18
70
+ console.log(securePassword.toString()); // Returns encrypted representation
71
+
72
+ // Generate secure random tokens
73
+ const token = SecureRandom.generateToken(32);
74
+ console.log(token); // 64-character hex string
75
+
76
+ // Hash operations
77
+ const hash = Hash.create("sensitive-data", {
78
+ algorithm: "sha256",
79
+ outputFormat: "hex",
80
+ });
81
+ console.log(hash); // SHA-256 hash in hex format
82
+ ```
83
+
84
+ ### Secure Data Handling
85
+
86
+ ```typescript
87
+ import { SecureArray, SecureObject } from "xypriss-security";
88
+
89
+ // Secure array operations
90
+ const secureData = new SecureArray([1, 2, 3, 4, 5]);
91
+ secureData.push(6);
92
+ console.log(secureData.length); // 6
93
+
94
+ // Secure object storage
95
+ const secureObj = new SecureObject({
96
+ apiKey: "secret-api-key",
97
+ credentials: { username: "admin", password: "secure123" },
98
+ });
99
+
100
+ // Access with automatic decryption
101
+ const apiKey = secureObj.get("apiKey");
102
+ console.log(apiKey); // 'secret-api-key'
103
+ ```
104
+
105
+ ### Password Management
106
+
107
+ ```typescript
108
+ import { Password } from "xypriss-security";
109
+
110
+ // Hash passwords with Argon2ID
111
+ const hashedPassword = await Password.hash("user-password", {
112
+ algorithm: "argon2id",
113
+ memoryCost: 65536,
114
+ timeCost: 3,
115
+ parallelism: 4,
116
+ });
117
+
118
+ // Verify passwords
119
+ const isValid = await Password.verify("user-password", hashedPassword);
120
+ console.log(isValid); // true
121
+ ```
122
+
123
+ ### Cryptographic Operations
124
+
125
+ ```typescript
126
+ import { Crypto, KeyDerivation } from "xypriss-security";
127
+
128
+ // Generate encryption keys
129
+ const key = await KeyDerivation.deriveKey("master-password", {
130
+ salt: "unique-salt",
131
+ iterations: 100000,
132
+ keyLength: 32,
133
+ algorithm: "pbkdf2",
134
+ });
135
+
136
+ // Encrypt/decrypt data
137
+ const encrypted = await Crypto.encrypt("sensitive-data", key);
138
+ const decrypted = await Crypto.decrypt(encrypted, key);
139
+ console.log(decrypted); // 'sensitive-data'
140
+ ```
141
+
142
+ ## 🏗️ Architecture
143
+
144
+ ### Core Modules
145
+
146
+ #### Security Core (`/core`)
147
+
148
+ - **crypto.ts**: Main cryptographic operations and algorithms
149
+ - **hash.ts**: Secure hashing functions with timing-safe operations
150
+ - **random.ts**: Cryptographically secure random number generation
151
+ - **validators.ts**: Input validation and sanitization utilities
152
+
153
+ #### Secure Components (`/components`)
154
+
155
+ - **secure-array**: Encrypted array implementation
156
+ - **secure-string**: Protected string handling
157
+ - **secure-object**: Encrypted object storage
158
+ - **secure-memory**: Memory management and protection
159
+ - **fortified-function**: Tamper-resistant function execution
160
+
161
+ #### Advanced Features (`/components`)
162
+
163
+ - **post-quantum**: Quantum-resistant cryptographic algorithms
164
+ - **tamper-evident-logging**: Immutable audit trail system
165
+ - **side-channel**: Protection against timing and cache attacks
166
+ - **attestation**: Code and data integrity verification
167
+
168
+ #### Utilities (`/utils`)
169
+
170
+ - **errorHandler**: Secure error handling and logging
171
+ - **performanceMonitor**: Security-aware performance monitoring
172
+ - **securityUtils**: General security utility functions
173
+ - **patterns**: Security pattern matching and detection
174
+
175
+ ## 📚 API Reference
176
+
177
+ ### XyPrissSecurity Class
178
+
179
+ The main entry point for the security library.
180
+
181
+ ```typescript
182
+ class XyPrissSecurity {
183
+ constructor(config?: SecurityConfig);
184
+
185
+ // Core methods
186
+ encrypt(data: any, options?: EncryptionOptions): Promise<string>;
187
+ decrypt(encryptedData: string, options?: DecryptionOptions): Promise<any>;
188
+ hash(data: string, options?: HashOptions): string;
189
+ generateToken(length?: number): string;
190
+
191
+ // Validation methods
192
+ validateInput(input: any, rules: ValidationRules): ValidationResult;
193
+ sanitize(input: string, options?: SanitizeOptions): string;
194
+ }
195
+ ```
196
+
197
+ ### SecureString
198
+
199
+ Protected string handling with automatic memory cleanup.
200
+
201
+ ```typescript
202
+ class SecureString {
203
+ constructor(value: string, options?: SecureStringOptions);
204
+
205
+ get length(): number;
206
+ toString(): string;
207
+ valueOf(): string;
208
+ clear(): void;
209
+
210
+ // String operations
211
+ substring(start: number, end?: number): SecureString;
212
+ indexOf(searchString: string): number;
213
+ replace(searchValue: string, replaceValue: string): SecureString;
214
+ }
215
+ ```
216
+
217
+ ### SecureArray
218
+
219
+ Military-grade encrypted arrays with comprehensive operations.
220
+
221
+ ```typescript
222
+ class SecureArray<T> {
223
+ constructor(initialData?: T[], options?: SecureArrayOptions);
224
+
225
+ get length(): number;
226
+ push(...items: T[]): number;
227
+ pop(): T | undefined;
228
+ shift(): T | undefined;
229
+ unshift(...items: T[]): number;
230
+
231
+ // Array operations
232
+ map<U>(callback: (value: T, index: number) => U): SecureArray<U>;
233
+ filter(callback: (value: T, index: number) => boolean): SecureArray<T>;
234
+ reduce<U>(callback: (acc: U, value: T, index: number) => U, initial: U): U;
235
+ }
236
+ ```
237
+
238
+ ### Hash Utilities
239
+
240
+ Secure hashing with multiple algorithms and timing-safe operations.
241
+
242
+ ```typescript
243
+ class Hash {
244
+ static create(data: string, options?: HashOptions): string;
245
+ static verify(data: string, hash: string, options?: HashOptions): boolean;
246
+ static hmac(data: string, key: string, options?: HmacOptions): string;
247
+
248
+ // Supported algorithms: sha256, sha512, blake3, argon2
249
+ static algorithms: string[];
250
+ }
251
+ ```
252
+
253
+ ### SecureRandom
254
+
255
+ Cryptographically secure random number generation.
256
+
257
+ ```typescript
258
+ class SecureRandom {
259
+ static generateToken(length: number): string;
260
+ static generateBytes(length: number): Uint8Array;
261
+ static generateInt(min: number, max: number): number;
262
+ static generateUUID(): string;
263
+
264
+ // Entropy management
265
+ static addEntropy(source: string): void;
266
+ static getEntropyLevel(): number;
267
+ }
268
+ ```
269
+
270
+ ## 🔧 Configuration
271
+
272
+ ### Security Configuration
273
+
274
+ ```typescript
275
+ interface SecurityConfig {
276
+ encryption?: {
277
+ algorithm?: "aes-256-gcm" | "chacha20-poly1305";
278
+ keyDerivation?: "pbkdf2" | "argon2" | "scrypt";
279
+ iterations?: number;
280
+ };
281
+
282
+ memory?: {
283
+ secureWipe?: boolean;
284
+ protectedAllocation?: boolean;
285
+ maxBufferSize?: number;
286
+ };
287
+
288
+ logging?: {
289
+ auditTrail?: boolean;
290
+ tamperEvident?: boolean;
291
+ logLevel?: "debug" | "info" | "warn" | "error";
292
+ };
293
+
294
+ validation?: {
295
+ strictMode?: boolean;
296
+ sanitizeInputs?: boolean;
297
+ maxInputLength?: number;
298
+ };
299
+ }
300
+ ```
301
+
302
+ ## 🚀 Performance
303
+
304
+ XyPriss Security is optimized for high-performance applications:
305
+
306
+ - **Encryption**: 10,000+ operations/second (AES-256-GCM)
307
+ - **Hashing**: 50,000+ operations/second (SHA-256)
308
+ - **Memory**: Zero-copy operations where possible
309
+ - **CPU**: Optimized algorithms with SIMD support
310
+
311
+ ## 🔒 Security Guarantees
312
+
313
+ - **Memory Safety**: Automatic secure memory wiping
314
+ - **Timing Safety**: Constant-time operations for sensitive data
315
+ - **Quantum Resistance**: Post-quantum cryptographic algorithms
316
+ - **Side-Channel Protection**: Resistance to timing and cache attacks
317
+ - **Tamper Evidence**: Cryptographic integrity verification
318
+
319
+ ## 🤝 Contributing
320
+
321
+ We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md).
322
+
323
+ ## 📄 License
324
+
325
+ MIT License - see [LICENSE](./LICENSE) file for details.
326
+
327
+ ## 🆘 Support
328
+
329
+ - [Documentation](./docs/)
330
+ - [GitHub Issues](https://github.com/Nehonix-Team/XyPriss/issues)
331
+ - [Security Advisories](https://github.com/Nehonix-Team/XyPriss/security)
332
+
333
+ ---
334
+
335
+ **XyPriss Security** - Military-grade security for modern JavaScript applications.
336
+