npm package: @neurosell/securedts
Description: A lightweight dependency-free library for secured types and local storage items. Compare field values and storage data using device fingerprinting
Author: Neurosell
Latest version: 1.0.0

# SecuredTS
![SecuredTS - Lightweight secured types and storage](img/cover.png)

**SecuredTS** - A **lightweight** pure typescript and dependency-free library for protecting local storage, class fields, and cryptography in your client-side web applications. The library also includes a simple method for collecting the user's device fingerprint to generate secure storage keys.

---

[Get Started](#installation) | [Other Libraries](https://github.com/neurosell) | [Telegram](https://t.me/devsdaddy) | [Contacts](https://neurosell.top/)

---

❓ **Why SecuredTS?**<br/>
🔹 **Lightweight Library** with zero dependencies;<br/>
🔹 **Powerful** secured fields with AES-encryption written in Typescript;<br/>
🔹 **Simple** encrypted local storage;<br/>
🔹 **Device fingerprint** based;<br/>
🔹 **Cross-platform** Support;

---

## Table of Contents
* [Installation](#installation)
* [Use Cases](#use-cases)
* [Secured Storage (Encrypted Local Storage)](#secured-storage-usage)
* [Secured Fields](#secured-fields)
* [Device Fingerprint](#device-fingerprint-class)
* [Crypto Classes](#crypto-classes)

---

## Installation
The process of installing the NS Storage library for your web applications is quite simple.

**Just import from npm:**
```bash
npm install @neurosell/securedts
```

**Or from CDN:**
```html
<script src="https://cdn.jsdelivr.net/npm/@neurosell/securedts@1.0.0/browser/securedts.global.js"></script>
<script type="text/javascript">
    // Will be connected as Global
    const { NStorage } = window.SecuredTS;
</script>
```

**Or from GitHub (for developers):**
```bash
git clone https://github.com/Neurosell/SecuredTS
```

---

## Use Cases
You can use **SecuredTS** library in case of:
* Secure your **local storage data with device fingerprint** key;
* Store Secured (Encrypted) **Fields into any objects**;
* Get **Device fingerprinting**;
* Work with objects and text using different AES encryption;

---

## Secured Storage Usage
The **NS Storage** Library may be used instead basic local storage with encrypted by device fingerprint keys and values.
Use this to protect your local storage objects.

**Usage Example:**
```javascript
// Create a storage instance
const exampleStorage = new NStorage();

// Save Item
exampleStorage.SetItem("exampleKey", "exampleValue"); // Will be saved in storage as "95ef95887680ac20b53f":"d2f28c846b9ca50e8627ddcc890f"

// Read Item
exampleStorage.GetItem("exampleKey"); // Returns Decrypted "exampleValue"
```

<hr/>

## Secured Fields
The **NS Storage** Library has own **Secured Fields** implementation for any your objects.
You can store **secured values** to protect memory hacking (for example with CheatEngine). This field is not store un-encrypted values.

**Example Class with Secured Fields:**
```javascript
class MyClass {
    construtor(){
        this.unencryptedField = "My Unencrypted Field";                 // Raw value can be found and changed in memory
        this.securedField = new SecuredField("My Secured Field");       // Raw value can't be found and changed in memory
    }
}
```

**Now you can use your Secured Fields:**
```javascript
// Create our Object Instance
const myObj = new MyClass();

// Get RAW Value
const rawValue = myObj.securedField.Value;

// Update Value (will be stored in memory with encryption)
myObj.securedField.Value = "new value to be encrypted";
```

<hr/>

## Device Fingerprint Class
The **NS Storage** Library has own simple Device Fingerprint Class Implementation.
Use this class to collect device information, UUID and device fingerprint by one line of code.

**Example Usage:**
```javascript
// Get Device Data, Fingerprint and UUID
const fingerprintData = NDeviceFingerprint.GetDeviceFingerprint();
console.log(fingerprintData.Data, fingerprintData.Key, fingerprintData.UUID);
```

**Collected Information:**
- User Agent;
- Browser Information (Name and Version);
- OS Information (Name and Version);
- Sceen Information (Resolution and Color Depth);
- Mobile Detection;
- Cookie Support Detection;
- HTML5 Features Detection;
- Language;
- Timezone Data;
- Device Memory;
- Do Not Track Flag;
- Browser Mime Types and Plugins List;
- WebGL Features List;
- Canvas Fingerprint;
<hr/>

## Crypto Classes
The **NS Storage** Library has own AES-Based Crypto Classes Implementation.
You can use any of these classes for your projects or **NEncryptor** helper class.

**Example Usage (with Encryptor):**
```javascript
// Create Encryptor Object
const myEncryptor = new NEncryptor("My Encryption Key", { Mode: NEncryptor.Mode.CTR });

// Get Encrypted HEX
const encryptedHEX = myEncryptor.Encrypt("My Decrypted Text");

// Get Decrypted Text
const decryptedText = myEncryptor.Decrypt(encryptedHEX);
```

**Example Usage:**
```javascript
// Prepare AES Encryption Key
const key = "myencryptionkey";
const hashedKey = new NCryptoMD5(key).GetHEX();
const bytes = new Array(16);
for (var i = 0; i < hashedKey.length;) {
    var hexByte = hashedKey[i++] + hashedKey[i++];
    var byte = parseInt(hexByte, 16);
    bytes[i / 2 - 1] = byte;
}

// Create Your Encryptor with converted to bytes array Encryption Key
const encryptor = new NCryptoCTR(bytes, new NCryptoCounter(1));

// Encrypt Some Text
const decryptedText = "My Decrypted Text";                      // Here your Decrypted Text
const decryptedBytes = encryptor._textToBytes(decryptedText);   // Convert to Decrypted Bytes Array
const encryptedBytes = encryptor.Encrypt(decryptedBytes);       // Encrypt your Decrypted Bytes Array
const encryptedHEX = encryptor._bytesToHex(encryptedBytes);     // Convert Encrypted Bytes Array to HEX String

// Decrypt Some Text
const encryptedBytes = encryptor._hexToBytes(encryptedHEX);     // Convert Encrypted HEX String to Encrypted Bytes Array
const decryptedBytes = encryptor.Decrypt(encryptedBytes);       // Decrypt Bytes Array
console.log(encryptor._bytesToText(decryptedBytes));            // Convert Decrypted Bytes to Text
```

**List of Available Classes:**
- **NEncryptor** - Multi-Method Encryption Helper;
- **NCrypto** - Base class with Utils Methods;
- **NCryptoAES** - Basic AES Implementation;
- **NCryptoECB** - AES in ECB Mode Implementation;
- **NCryptoCBC** - AES in CBC Mode Implementation;
- **NCryptoCFB** - AES in CFB Mode Implementation;
- **NCryptoOFB** - AES in OFB Mode Implementation;
- **NCryptoCTR (Recommended)** - AES in CTR Mode Implementation;
- **NCryptoCounter** - Util class for AES Counter;
- **NCryptoMD5** - MD5 Hash Implementation;

**Encryption Classes Methods:**
- **Name** - Returns {string} Encryption Method Name;
- **Encrypt** - Returns {bytes} Encrypted UTF8 Bytes Array;
- **Decrypt** - Returns {bytes} Decrypted UTF8 Bytes Array;

---

[Get Started](#installation) | [Other Libraries](https://github.com/neurosell) | [Telegram](https://t.me/devsdaddy) | [Contacts](https://neurosell.top/)