dphelper 3.5.5 → 3.7.2
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/README.md +0 -21
- package/docs/README.md +385 -0
- package/docs/SUMMARY.md +83 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/ai.md +345 -0
- package/docs/markdown/anchor.md +156 -0
- package/docs/markdown/array.md +208 -0
- package/docs/markdown/audio.md +113 -0
- package/docs/markdown/avoid.md +53 -0
- package/docs/markdown/biometric.md +338 -0
- package/docs/markdown/browser.md +203 -0
- package/docs/markdown/check.md +65 -0
- package/docs/markdown/color.md +159 -0
- package/docs/markdown/compress.md +310 -0
- package/docs/markdown/cookie.md +115 -0
- package/docs/markdown/coords.md +127 -0
- package/docs/markdown/credits.md +56 -0
- package/docs/markdown/date.md +260 -0
- package/docs/markdown/disable.md +109 -0
- package/docs/markdown/dispatch.md +108 -0
- package/docs/markdown/element.md +53 -0
- package/docs/markdown/event.md +85 -0
- package/docs/markdown/fetch.md +122 -0
- package/docs/markdown/form.md +302 -0
- package/docs/markdown/format.md +122 -0
- package/docs/markdown/i18n.md +292 -0
- package/docs/markdown/image.md +298 -0
- package/docs/markdown/json.md +269 -0
- package/docs/markdown/load.md +133 -0
- package/docs/markdown/logging.md +99 -0
- package/docs/markdown/math.md +172 -0
- package/docs/markdown/memory.md +85 -0
- package/docs/markdown/navigation.md +152 -0
- package/docs/markdown/net.md +60 -0
- package/docs/markdown/obj.md +242 -0
- package/docs/markdown/path.md +46 -0
- package/docs/markdown/promise.md +94 -0
- package/docs/markdown/sanitize.md +118 -0
- package/docs/markdown/screen.md +78 -0
- package/docs/markdown/scrollbar.md +82 -0
- package/docs/markdown/security.md +289 -0
- package/docs/markdown/shortcut.md +100 -0
- package/docs/markdown/socket.md +134 -0
- package/docs/markdown/sse.md +120 -0
- package/docs/markdown/svg.md +167 -0
- package/docs/markdown/sync.md +147 -0
- package/docs/markdown/system.md +78 -0
- package/docs/markdown/terminal.md +73 -0
- package/docs/markdown/text.md +245 -0
- package/docs/markdown/timer.md +98 -0
- package/docs/markdown/tools.md +111 -0
- package/docs/markdown/translators.md +65 -0
- package/docs/markdown/trigger.md +99 -0
- package/docs/markdown/triggers.md +133 -0
- package/docs/markdown/type.md +109 -0
- package/docs/markdown/types.md +102 -0
- package/docs/markdown/ui.md +45 -0
- package/docs/markdown/window.md +211 -0
- package/docs/markdown/worker.md +223 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +4 -6
- package/types/dphelper.d.ts +0 -15
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# sanitize
|
|
2
|
+
|
|
3
|
+
Input/output sanitization for security.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `html` | Sanitize HTML by escaping special characters | `dphelper.sanitize.html(html)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
Security-focused sanitization utilities:
|
|
14
|
+
- **HTML Escape** - Convert special characters to HTML entities
|
|
15
|
+
- **XSS Prevention** - Prevent cross-site scripting attacks
|
|
16
|
+
- **Input Validation** - Clean user-provided content
|
|
17
|
+
|
|
18
|
+
## Usage Examples
|
|
19
|
+
|
|
20
|
+
### HTML Sanitization
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// Escape HTML special characters
|
|
24
|
+
const userInput = '<script>alert("XSS")</script>';
|
|
25
|
+
const safe = dphelper.sanitize.html(userInput);
|
|
26
|
+
// Output: "<script>alert("XSS")</script>"
|
|
27
|
+
|
|
28
|
+
// More examples
|
|
29
|
+
const html1 = dphelper.sanitize.html('<div class="test">Hello</div>');
|
|
30
|
+
// "<div class="test">Hello</div>"
|
|
31
|
+
|
|
32
|
+
const html2 = dphelper.sanitize.html('Use <br> for line breaks');
|
|
33
|
+
// "Use <br> for line breaks"
|
|
34
|
+
|
|
35
|
+
const html3 = dphelper.sanitize.html("It's a beautiful day");
|
|
36
|
+
// "It's a beautiful day"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Display User Content Safely
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// Safely display user comments
|
|
43
|
+
function displayComment(comment) {
|
|
44
|
+
const sanitized = dphelper.sanitize.html(comment);
|
|
45
|
+
document.getElementById('comments').innerHTML = sanitized;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// User input (malicious)
|
|
49
|
+
const maliciousInput = '<img src=x onerror=alert(1)>';
|
|
50
|
+
displayComment(maliciousInput);
|
|
51
|
+
// Safely displays as text, not executed
|
|
52
|
+
|
|
53
|
+
// Chat message sanitization
|
|
54
|
+
const messages = [
|
|
55
|
+
'<b>User1:</b> Hello everyone!',
|
|
56
|
+
'<script>stealCookies()</script>Welcome!',
|
|
57
|
+
'Check out <a href="http://evil.com">this link</a>'
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
messages.forEach(msg => {
|
|
61
|
+
console.log(dphelper.sanitize.html(msg));
|
|
62
|
+
});
|
|
63
|
+
// <b>User1:</b> Hello everyone!
|
|
64
|
+
// <script>stealCookies()</script>Welcome!
|
|
65
|
+
// Check out <a href="http://evil.com">this link</a>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Form Input Validation
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
// Sanitize form inputs before storage
|
|
72
|
+
function sanitizeFormInput(input) {
|
|
73
|
+
if (typeof input !== 'string') return '';
|
|
74
|
+
return dphelper.sanitize.html(input.trim());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const formData = {
|
|
78
|
+
username: ' <script>bad()</script>user ',
|
|
79
|
+
bio: 'I love <programming> and "quotes"',
|
|
80
|
+
website: 'https://example.com'
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const sanitized = {
|
|
84
|
+
username: sanitizeFormInput(formData.username),
|
|
85
|
+
bio: sanitizeFormInput(formData.bio),
|
|
86
|
+
website: sanitizeFormInput(formData.website)
|
|
87
|
+
};
|
|
88
|
+
// { username: "<script>bad()</script>user", ... }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Database Storage
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// Sanitize before storing in database
|
|
95
|
+
function saveToDatabase(data) {
|
|
96
|
+
const sanitized = {};
|
|
97
|
+
for (const key in data) {
|
|
98
|
+
if (typeof data[key] === 'string') {
|
|
99
|
+
sanitized[key] = dphelper.sanitize.html(data[key]);
|
|
100
|
+
} else {
|
|
101
|
+
sanitized[key] = data[key];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return sanitized;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Details
|
|
109
|
+
|
|
110
|
+
- **Author:** Dario Passariello
|
|
111
|
+
- **Version:** 0.0.2
|
|
112
|
+
- **Creation Date:** 20241204
|
|
113
|
+
- **Last Modified:** 20241204
|
|
114
|
+
- **Environment:** both (browser + Node.js)
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# screen
|
|
2
|
+
|
|
3
|
+
Functionality for screen and fullscreen management.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `fullScreen` | Enter fullscreen mode | `dphelper.screen.fullScreen(element)` |
|
|
10
|
+
| `toggle` | Toggle fullscreen mode | `dphelper.screen.toggle(element)` |
|
|
11
|
+
|
|
12
|
+
## Description
|
|
13
|
+
|
|
14
|
+
Browser fullscreen control:
|
|
15
|
+
- **Fullscreen** - Request fullscreen for any element
|
|
16
|
+
- **Toggle** - Switch between fullscreen and normal mode
|
|
17
|
+
- **Video** - Perfect for video players and presentations
|
|
18
|
+
|
|
19
|
+
## Usage Examples
|
|
20
|
+
|
|
21
|
+
### Enter Fullscreen
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Fullscreen entire page
|
|
25
|
+
dphelper.screen.fullScreen();
|
|
26
|
+
|
|
27
|
+
// Fullscreen specific element
|
|
28
|
+
const video = document.getElementById('myVideo');
|
|
29
|
+
dphelper.screen.fullScreen(video);
|
|
30
|
+
|
|
31
|
+
// Fullscreen modal
|
|
32
|
+
const modal = document.getElementById('modal');
|
|
33
|
+
dphelper.screen.fullScreen(modal);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Toggle Fullscreen
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
// Toggle on/off
|
|
40
|
+
dphelper.screen.toggle();
|
|
41
|
+
|
|
42
|
+
// Toggle specific element
|
|
43
|
+
const element = document.getElementById('container');
|
|
44
|
+
dphelper.screen.toggle(element);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Video Player Fullscreen
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// Fullscreen video player
|
|
51
|
+
const videoPlayer = document.getElementById('video-player');
|
|
52
|
+
const fullscreenBtn = document.getElementById('fullscreen-btn');
|
|
53
|
+
|
|
54
|
+
fullscreenBtn.addEventListener('click', () => {
|
|
55
|
+
dphelper.screen.toggle(videoPlayer);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Handle fullscreen change
|
|
59
|
+
document.addEventListener('fullscreenchange', () => {
|
|
60
|
+
if (document.fullscreenElement) {
|
|
61
|
+
console.log('Entered fullscreen');
|
|
62
|
+
} else {
|
|
63
|
+
console.log('Exited fullscreen');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Details
|
|
69
|
+
|
|
70
|
+
- **Author:** Dario Passariello
|
|
71
|
+
- **Version:** 0.0.2
|
|
72
|
+
- **Creation Date:** 20240101
|
|
73
|
+
- **Last Modified:** 20240101
|
|
74
|
+
- **Environment:** client (browser)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# scrollbar
|
|
2
|
+
|
|
3
|
+
Scrollbar customization and scrolling utilities.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `custom` | Apply custom scrollbar styles | `dphelper.scrollbar.custom('.container')` |
|
|
10
|
+
| `indicator` | Add scroll progress indicator | `dphelper.scrollbar.indicator({ el: '#content' })` |
|
|
11
|
+
| `position.get` | Get saved scroll position | `dphelper.scrollbar.position.get('#container')` |
|
|
12
|
+
| `position.set` | Save scroll position | `dphelper.scrollbar.position.set('#container')` |
|
|
13
|
+
| `smooth` | Smooth mouse wheel scrolling | `dphelper.scrollbar.smooth(target, speed, smooth)` |
|
|
14
|
+
| `scrollTo` | Scroll to element | `dphelper.scrollbar.scrollTo('#container', '#element', 20)` |
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
Scrollbar management:
|
|
19
|
+
- **Custom Styling** - Apply custom scrollbar CSS
|
|
20
|
+
- **Progress Indicator** - Show scroll progress bar
|
|
21
|
+
- **Position Memory** - Save/restore scroll position
|
|
22
|
+
- **Smooth Scrolling** - Custom smooth scroll behavior
|
|
23
|
+
|
|
24
|
+
## Usage Examples
|
|
25
|
+
|
|
26
|
+
### Custom Scrollbar
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
// Apply custom scrollbar styles
|
|
30
|
+
dphelper.scrollbar.custom('.scroll-container', {
|
|
31
|
+
color_1: '#888',
|
|
32
|
+
color_1_hover: '#555',
|
|
33
|
+
width: '12px',
|
|
34
|
+
height: '12px',
|
|
35
|
+
rounded: '6px'
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Scroll Indicator
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// Add scroll progress indicator
|
|
43
|
+
dphelper.scrollbar.indicator({
|
|
44
|
+
el: '#main-content'
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Adds progress bar at top of page
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Scroll Position
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
// Save scroll position
|
|
54
|
+
dphelper.scrollbar.position.set('#chat-container');
|
|
55
|
+
|
|
56
|
+
// Restore on page load
|
|
57
|
+
dphelper.scrollbar.position.get('#chat-container');
|
|
58
|
+
|
|
59
|
+
// Useful for chat apps, long content
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Scroll To Element
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
// Scroll to element with gap
|
|
66
|
+
dphelper.scrollbar.scrollTo('#container', '#target-section', 50);
|
|
67
|
+
|
|
68
|
+
// Smooth scroll to section
|
|
69
|
+
dphelper.scrollbar.scrollTo('body', '#footer');
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Details
|
|
73
|
+
|
|
74
|
+
- **Author:** Dario Passariello
|
|
75
|
+
- **Version:** 0.0.2
|
|
76
|
+
- **Creation Date:** 20210101
|
|
77
|
+
- **Last Modified:** 20260220
|
|
78
|
+
- **Environment:** Client-side only (browser)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# security
|
|
2
|
+
|
|
3
|
+
Comprehensive security and cryptography utilities for encryption, hashing, identity generation, and browser fingerprinting.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
### UUID Generation
|
|
8
|
+
|
|
9
|
+
| Function | Description | Example |
|
|
10
|
+
|----------|-------------|---------|
|
|
11
|
+
| `uuid.v4` | Generates a random UUID v4 | `dphelper.security.uuid.v4` |
|
|
12
|
+
| `uuid.v5` | Generates a random UUID v5 | `dphelper.security.uuid.v5` |
|
|
13
|
+
| `uuid.byVal` | Generates a deterministic UUID from a string | `dphelper.security.uuid.byVal('string')` |
|
|
14
|
+
|
|
15
|
+
### Encryption/Decryption
|
|
16
|
+
|
|
17
|
+
| Function | Description | Example |
|
|
18
|
+
|----------|-------------|---------|
|
|
19
|
+
| `crypt` | Encrypts data using AES-256-GCM | `await dphelper.security.crypt(data, secret)` |
|
|
20
|
+
| `deCrypt` | Decrypts AES-256-GCM encrypted data | `await dphelper.security.deCrypt(encrypted, secret)` |
|
|
21
|
+
| `AES_KeyGen` | Generates a secure AES key | `await dphelper.security.AES_KeyGen(passKey)` |
|
|
22
|
+
|
|
23
|
+
### Hashing
|
|
24
|
+
|
|
25
|
+
| Function | Description | Example |
|
|
26
|
+
|----------|-------------|---------|
|
|
27
|
+
| `hashPass` | Creates secure password hash with salt (SHA-256) | `await dphelper.security.hashPass(user, pass)` |
|
|
28
|
+
| `SHA256_Hex` | Generates SHA-256 hash in hexadecimal | `await dphelper.security.SHA256_Hex(data)` |
|
|
29
|
+
|
|
30
|
+
### Identity Generation
|
|
31
|
+
|
|
32
|
+
| Function | Description | Example |
|
|
33
|
+
|----------|-------------|---------|
|
|
34
|
+
| `ulid` | Generates Universally Unique Lexicographically Sortable Identifier | `dphelper.security.ulid()` |
|
|
35
|
+
| `fingerprint` | Generates unique browser fingerprint | `await dphelper.security.fingerprint()` |
|
|
36
|
+
|
|
37
|
+
### Secure Storage
|
|
38
|
+
|
|
39
|
+
| Function | Description | Example |
|
|
40
|
+
|----------|-------------|---------|
|
|
41
|
+
| `saveEncrypted` | Encrypts and saves data to localStorage with HMAC | `await dphelper.security.saveEncrypted(key, value, secret)` |
|
|
42
|
+
| `getEncrypted` | Retrieves and decrypts data from localStorage | `await dphelper.security.getEncrypted(key, secret)` |
|
|
43
|
+
|
|
44
|
+
## Description
|
|
45
|
+
|
|
46
|
+
Enterprise-grade security module providing:
|
|
47
|
+
- **UUID Generation** - v4 (random), v5 (namespace-based), deterministic
|
|
48
|
+
- **Encryption** - AES-256-GCM with PBKDF2 key derivation
|
|
49
|
+
- **Hashing** - SHA-256 with secure salt generation
|
|
50
|
+
- **Identity** - ULID for sortable unique IDs, browser fingerprinting
|
|
51
|
+
- **Secure Storage** - Encrypted localStorage with HMAC integrity
|
|
52
|
+
|
|
53
|
+
## Usage Examples
|
|
54
|
+
|
|
55
|
+
### UUID Generation
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
// Random UUID v4 (most common use case)
|
|
59
|
+
console.log(dphelper.security.uuid.v4);
|
|
60
|
+
// "550e8400-e29b-41d4-a716-446655440000"
|
|
61
|
+
|
|
62
|
+
// Random UUID v5
|
|
63
|
+
console.log(dphelper.security.uuid.v5);
|
|
64
|
+
// "a3bb189e-8bf9-3888-9912-ace4e6543002"
|
|
65
|
+
|
|
66
|
+
// Deterministic UUID from string (same input = same output)
|
|
67
|
+
console.log(dphelper.security.uuid.byVal('hello'));
|
|
68
|
+
// "2cfb4a2e-7b3c-4a8e-9d1c-5e4f6a7b8c9d"
|
|
69
|
+
|
|
70
|
+
console.log(dphelper.security.uuid.byVal('hello'));
|
|
71
|
+
// "2cfb4a2e-7b3c-4a8e-9d1c-5e4f6a7b8c9d" (same!)
|
|
72
|
+
|
|
73
|
+
// Useful for generating consistent IDs from usernames
|
|
74
|
+
const userId = dphelper.security.uuid.byVal('john@example.com');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Encryption/Decryption
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
// Encrypt sensitive data
|
|
81
|
+
const secret = 'my-secret-password';
|
|
82
|
+
const data = 'Hello, World!';
|
|
83
|
+
|
|
84
|
+
const encrypted = await dphelper.security.crypt(data, secret);
|
|
85
|
+
console.log(encrypted);
|
|
86
|
+
// "base64encodedstring..." (contains salt + iv + encrypted data)
|
|
87
|
+
|
|
88
|
+
// Decrypt the data
|
|
89
|
+
const decrypted = await dphelper.security.deCrypt(encrypted, secret);
|
|
90
|
+
console.log(decrypted); // "Hello, World!"
|
|
91
|
+
|
|
92
|
+
// Generate a secure key from password
|
|
93
|
+
const key = await dphelper.security.AES_KeyGen('user-password');
|
|
94
|
+
console.log(key);
|
|
95
|
+
// "salthadexstring...keybits..."
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Password Hashing
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Hash a password (with automatic salt generation)
|
|
102
|
+
const user = 'john@example.com';
|
|
103
|
+
const password = 'mySecurePassword!123';
|
|
104
|
+
|
|
105
|
+
const hash = await dphelper.security.hashPass(user, password);
|
|
106
|
+
console.log(hash);
|
|
107
|
+
// "salthere...hashhere..." (64 char hex string)
|
|
108
|
+
|
|
109
|
+
// Verify password later
|
|
110
|
+
const storedHash = '...'; // Previously stored hash
|
|
111
|
+
const inputPassword = 'mySecurePassword!123';
|
|
112
|
+
const newHash = await dphelper.security.hashPass(user, inputPassword);
|
|
113
|
+
|
|
114
|
+
if (newHash === storedHash) {
|
|
115
|
+
console.log('Password correct!');
|
|
116
|
+
} else {
|
|
117
|
+
console.log('Invalid password');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// SHA-256 hash (raw)
|
|
121
|
+
const sha256 = await dphelper.security.SHA256_Hex('hello world');
|
|
122
|
+
console.log(sha256);
|
|
123
|
+
// "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### ULID Generation
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
// Generate ULID (unique, lexicographically sortable, time-based)
|
|
130
|
+
const id1 = dphelper.security.ulid();
|
|
131
|
+
const id2 = dphelper.security.ulid();
|
|
132
|
+
|
|
133
|
+
console.log(id1); // "01ARYZ6S41TVGZFM0X5SZW0JYP"
|
|
134
|
+
console.log(id2); // "01ARYZ6S41TVHZ0WS0QJZWMY5A"
|
|
135
|
+
|
|
136
|
+
// ULIDs are time-sortable
|
|
137
|
+
console.log(id1 < id2); // true (if id1 was created first)
|
|
138
|
+
|
|
139
|
+
// Great for database primary keys
|
|
140
|
+
const orderId = dphelper.security.ulid(); // Sortable by creation time
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Browser Fingerprinting
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
// Generate unique browser fingerprint
|
|
147
|
+
const fingerprint = await dphelper.security.fingerprint();
|
|
148
|
+
console.log(fingerprint);
|
|
149
|
+
// "a1b2c3d4e5f6..." (SHA-256 hash)
|
|
150
|
+
|
|
151
|
+
// Use for analytics, fraud detection, or session management
|
|
152
|
+
async function identifyUser() {
|
|
153
|
+
const fp = await dphelper.security.fingerprint();
|
|
154
|
+
|
|
155
|
+
// Send to your server
|
|
156
|
+
await fetch('/api/identify', {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
body: JSON.stringify({ fingerprint: fp })
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Secure LocalStorage
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
// Save encrypted data to localStorage
|
|
167
|
+
await dphelper.security.saveEncrypted('user_token', 'abc123xyz', 'my-secret');
|
|
168
|
+
|
|
169
|
+
await dphelper.security.saveEncrypted('user_data', JSON.stringify({
|
|
170
|
+
name: 'John',
|
|
171
|
+
email: 'john@example.com'
|
|
172
|
+
}), 'my-secret');
|
|
173
|
+
|
|
174
|
+
// Retrieve and decrypt data
|
|
175
|
+
const token = await dphelper.security.getEncrypted('user_token', 'my-secret');
|
|
176
|
+
console.log(token); // "abc123xyz"
|
|
177
|
+
|
|
178
|
+
const userData = await dphelper.security.getEncrypted('user_data', 'my-secret');
|
|
179
|
+
console.log(JSON.parse(userData));
|
|
180
|
+
// { name: 'John', email: 'john@example.com' }
|
|
181
|
+
|
|
182
|
+
// Tamper detection - returns null if data was modified
|
|
183
|
+
localStorage.setItem('user_token', 'modified_by_hacker');
|
|
184
|
+
const tampered = await dphelper.security.getEncrypted('user_token', 'my-secret');
|
|
185
|
+
console.log(tampered); // null (detected tampering!)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Security Features
|
|
189
|
+
|
|
190
|
+
### AES-256-GCM Encryption
|
|
191
|
+
- Uses PBKDF2 with **310,000 iterations** (OWASP 2023 compliant) for key derivation
|
|
192
|
+
- Random 16-byte salt for each encryption
|
|
193
|
+
- Random 12-byte IV (Initialization Vector)
|
|
194
|
+
- Authenticated encryption (confidentiality + integrity)
|
|
195
|
+
|
|
196
|
+
### Secure Password Hashing
|
|
197
|
+
- **SHA-256 only** (CNSA compliant, SHA-1 deprecated)
|
|
198
|
+
- Random 16-byte salt per hash
|
|
199
|
+
- Salt + hash stored together for verification
|
|
200
|
+
- Time-safe comparison
|
|
201
|
+
|
|
202
|
+
### HMAC-Protected Storage
|
|
203
|
+
- AES encryption for confidentiality
|
|
204
|
+
- HMAC-SHA256 for integrity verification
|
|
205
|
+
- Tamper detection on retrieval
|
|
206
|
+
- Version support for future updates
|
|
207
|
+
|
|
208
|
+
### Network Functions Security
|
|
209
|
+
|
|
210
|
+
> [!IMPORTANT]
|
|
211
|
+
> Network primitives (`fetch`, `sse`, `socket`) are **by design** for modern web development. Callers must:
|
|
212
|
+
> - Validate and sanitize all URLs before passing to these functions
|
|
213
|
+
> - Use `dphelper.sanitize.url()` for URL validation
|
|
214
|
+
> - Never pass untrusted user input directly to network functions
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
// Correct usage
|
|
218
|
+
const safeUrl = dphelper.sanitize.url(userInput);
|
|
219
|
+
await dphelper.fetch.get(safeUrl);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Advanced Usage
|
|
223
|
+
|
|
224
|
+
### Complete Authentication Flow
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
class AuthManager {
|
|
228
|
+
constructor(secret) {
|
|
229
|
+
this.secret = secret;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async register(username, password) {
|
|
233
|
+
// Hash password for storage
|
|
234
|
+
const hash = await dphelper.security.hashPass(username, password);
|
|
235
|
+
|
|
236
|
+
// Generate user ID
|
|
237
|
+
const userId = dphelper.security.uuid.byVal(username);
|
|
238
|
+
|
|
239
|
+
// Save user data securely
|
|
240
|
+
await dphelper.security.saveEncrypted(`user_${userId}`,
|
|
241
|
+
JSON.stringify({ hash, created: Date.now() }),
|
|
242
|
+
this.secret
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return userId;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async login(username, password) {
|
|
249
|
+
const userId = dphelper.security.uuid.byVal(username);
|
|
250
|
+
const stored = await dphelper.security.getEncrypted(`user_${userId}`, this.secret);
|
|
251
|
+
|
|
252
|
+
if (!stored) return null;
|
|
253
|
+
|
|
254
|
+
const userData = JSON.parse(stored);
|
|
255
|
+
const inputHash = await dphelper.security.hashPass(username, password);
|
|
256
|
+
|
|
257
|
+
return inputHash === userData.hash ? userId : null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Secure Message Passing
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
async function sendSecureMessage(recipient, message) {
|
|
266
|
+
// Generate encryption key
|
|
267
|
+
const key = await dphelper.security.AES_KeyGen(recipient);
|
|
268
|
+
|
|
269
|
+
// Encrypt message
|
|
270
|
+
const encrypted = await dphelper.security.crypt(message, key);
|
|
271
|
+
|
|
272
|
+
// Create message ID
|
|
273
|
+
const messageId = dphelper.security.ulid();
|
|
274
|
+
|
|
275
|
+
return { id: messageId, encrypted, key };
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Details
|
|
280
|
+
|
|
281
|
+
- **Author:** Dario Passariello & Jo
|
|
282
|
+
- **Version:** 0.0.2
|
|
283
|
+
- **Creation Date:** 20210101
|
|
284
|
+
- **Last Modified:** 20260220
|
|
285
|
+
- **Environment:** Works in both client and server environments
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# shortcut
|
|
2
|
+
|
|
3
|
+
Keyboard shortcut management.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `keys` | Handle keyboard shortcuts | `dphelper.shortcut.keys(event, trigger)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
Keyboard shortcut system:
|
|
14
|
+
- **Custom Shortcuts** - Define your own keyboard shortcuts
|
|
15
|
+
- **Ctrl/Meta Keys** - Support for modifier keys
|
|
16
|
+
- **Element Actions** - Trigger clicks on elements
|
|
17
|
+
- **Function Callbacks** - Execute custom functions
|
|
18
|
+
|
|
19
|
+
## Usage Examples
|
|
20
|
+
|
|
21
|
+
### Basic Shortcut Handling
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Handle keyboard events
|
|
25
|
+
document.addEventListener('keydown', (e) => {
|
|
26
|
+
dphelper.shortcut.keys(e);
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Custom Shortcut Configuration
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
// Define custom shortcuts
|
|
34
|
+
const shortcuts = {
|
|
35
|
+
data: [
|
|
36
|
+
{
|
|
37
|
+
key: '83', // S key
|
|
38
|
+
ctrl: true, // requires Ctrl
|
|
39
|
+
active: true,
|
|
40
|
+
description: 'Save - CTRL+S',
|
|
41
|
+
element: '#save-btn',
|
|
42
|
+
function: ''
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: '80', // P key
|
|
46
|
+
ctrl: true,
|
|
47
|
+
active: true,
|
|
48
|
+
description: 'Print - CTRL+P',
|
|
49
|
+
element: '',
|
|
50
|
+
function: 'print()'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: '27', // ESC
|
|
54
|
+
ctrl: false,
|
|
55
|
+
active: true,
|
|
56
|
+
description: 'Close - ESC',
|
|
57
|
+
element: '#close-modal',
|
|
58
|
+
function: ''
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
document.addEventListener('keydown', (e) => {
|
|
64
|
+
dphelper.shortcut.keys(e, shortcuts);
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Save Form
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
// Auto-save with Ctrl+S
|
|
72
|
+
const formShortcuts = {
|
|
73
|
+
data: [
|
|
74
|
+
{
|
|
75
|
+
key: '83',
|
|
76
|
+
ctrl: true,
|
|
77
|
+
active: true,
|
|
78
|
+
description: 'Save form',
|
|
79
|
+
element: '#save-form-btn',
|
|
80
|
+
function: ''
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
document.addEventListener('keydown', (e) => {
|
|
86
|
+
dphelper.shortcut.keys(e, formShortcuts);
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Details
|
|
91
|
+
|
|
92
|
+
- **Author:** Dario Passariello
|
|
93
|
+
- **Version:** 0.0.2
|
|
94
|
+
- **Creation Date:** 20210101
|
|
95
|
+
- **Last Modified:** 20260220
|
|
96
|
+
- **Environment:** client (browser)
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
*Automatically generated document*
|