@pathscale/secure-local-storage-chacha20-poly1305 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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +403 -0
- package/dist/SecureLocalStorage.d.ts +54 -0
- package/dist/SecureLocalStorage.d.ts.map +1 -0
- package/dist/encryption.d.ts +36 -0
- package/dist/encryption.d.ts.map +1 -0
- package/dist/environment.d.ts +17 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/fingerprinting.d.ts +30 -0
- package/dist/fingerprinting.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +656 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +647 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +81 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-05-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial renamed fork package: `@pathscale/secure-local-storage-chacha20-poly1305`.
|
|
12
|
+
- ChaCha20-Poly1305 authenticated encryption for stored values.
|
|
13
|
+
- PBKDF2-SHA256 key derivation through `@noble/hashes`.
|
|
14
|
+
- Versioned encrypted value envelope containing algorithm, nonce, ciphertext, and version.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Replaced the original encryption dependency with `@noble/ciphers`.
|
|
18
|
+
- Updated installation, import examples, package metadata, and npm badges for the renamed package.
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
- Removed legacy encryption code and package dependencies.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 jahidulsaeid
|
|
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,403 @@
|
|
|
1
|
+
# Secure Local Storage ChaCha20-Poly1305
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@pathscale/secure-local-storage-chacha20-poly1305) [](http://npm-stat.com/charts.html?package=@pathscale/secure-local-storage-chacha20-poly1305) [](https://www.typescriptlang.org/) [](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
A secure, encrypted local storage library with browser fingerprinting for enhanced security. This fork provides a drop-in replacement for localStorage with ChaCha20-Poly1305 authenticated encryption, type preservation, and browser-specific security keys.
|
|
6
|
+
|
|
7
|
+
## 🚀 Features
|
|
8
|
+
|
|
9
|
+
- **🔐 Automatic Encryption**: All data is encrypted using ChaCha20-Poly1305 with browser-specific keys
|
|
10
|
+
- **🔍 Browser Fingerprinting**: Generates unique keys based on browser characteristics
|
|
11
|
+
- **📝 Type Preservation**: Maintains original data types (string, number, boolean, object)
|
|
12
|
+
- **🎯 Framework Agnostic**: Works with React, Vue, Angular, Vite, Next.js, and vanilla JavaScript
|
|
13
|
+
- **💾 Memory Caching**: Singleton pattern with in-memory cache for performance
|
|
14
|
+
- **🛡️ Secure by Default**: Each browser generates its own encryption key
|
|
15
|
+
- **⚙️ Configurable**: Extensive configuration options and environment variable support
|
|
16
|
+
- **📦 TypeScript Ready**: Full TypeScript support with comprehensive type definitions
|
|
17
|
+
- **🚀 Production Ready**: Thoroughly tested and optimized for performance
|
|
18
|
+
|
|
19
|
+
## 🤔 Why Secure Local Storage?
|
|
20
|
+
|
|
21
|
+
### The Problem with Regular localStorage
|
|
22
|
+
|
|
23
|
+
Regular localStorage stores data as plain text, making it vulnerable to:
|
|
24
|
+
|
|
25
|
+
- **Data theft**: Anyone with device access can read your stored data
|
|
26
|
+
- **Cross-browser attacks**: Encrypted data from one browser can be copied to another
|
|
27
|
+
- **No type safety**: Everything is stored as strings, losing original data types
|
|
28
|
+
|
|
29
|
+
### The Solution
|
|
30
|
+
|
|
31
|
+
Secure Local Storage generates a unique encryption key for each browser using:
|
|
32
|
+
- Browser fingerprinting (10+ unique identifiers)
|
|
33
|
+
- User-specific hash keys
|
|
34
|
+
- Environment-specific configuration
|
|
35
|
+
|
|
36
|
+
This ensures that data encrypted in one browser cannot be decrypted in another, even if the encrypted data is copied.
|
|
37
|
+
|
|
38
|
+
## 📦 Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @pathscale/secure-local-storage-chacha20-poly1305
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
or
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
yarn add @pathscale/secure-local-storage-chacha20-poly1305
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 🏃♂️ Quick Start
|
|
51
|
+
|
|
52
|
+
### Basic Usage
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import secureLocalStorage from '@pathscale/secure-local-storage-chacha20-poly1305';
|
|
56
|
+
|
|
57
|
+
// Store different data types
|
|
58
|
+
secureLocalStorage.setItem('user', {
|
|
59
|
+
name: 'John Doe',
|
|
60
|
+
age: 30,
|
|
61
|
+
active: true
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
secureLocalStorage.setItem('count', 42);
|
|
65
|
+
secureLocalStorage.setItem('enabled', true);
|
|
66
|
+
secureLocalStorage.setItem('message', 'Hello, World!');
|
|
67
|
+
|
|
68
|
+
// Retrieve data (maintains original types)
|
|
69
|
+
const user = secureLocalStorage.getItem('user'); // Returns object
|
|
70
|
+
const count = secureLocalStorage.getItem('count'); // Returns number
|
|
71
|
+
const enabled = secureLocalStorage.getItem('enabled'); // Returns boolean
|
|
72
|
+
const message = secureLocalStorage.getItem('message'); // Returns string
|
|
73
|
+
|
|
74
|
+
// Remove items
|
|
75
|
+
secureLocalStorage.removeItem('user');
|
|
76
|
+
|
|
77
|
+
// Clear all secure storage
|
|
78
|
+
secureLocalStorage.clear();
|
|
79
|
+
|
|
80
|
+
// Get all keys
|
|
81
|
+
const keys = secureLocalStorage.keys(); // Returns string[]
|
|
82
|
+
|
|
83
|
+
// Get storage length
|
|
84
|
+
const length = secureLocalStorage.length(); // Returns number
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Advanced Usage
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { SecureLocalStorage } from '@pathscale/secure-local-storage-chacha20-poly1305';
|
|
91
|
+
|
|
92
|
+
// Create a custom instance with configuration
|
|
93
|
+
const customStorage = SecureLocalStorage.getInstance({
|
|
94
|
+
hashKey: 'my-custom-key',
|
|
95
|
+
prefix: 'myapp_',
|
|
96
|
+
disabledKeys: ['Canvas', 'Fonts'], // Disable specific fingerprint properties
|
|
97
|
+
debug: true
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Use the custom instance
|
|
101
|
+
customStorage.setItem('data', { custom: true });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## ⚙️ Configuration
|
|
105
|
+
|
|
106
|
+
### Environment Variables
|
|
107
|
+
|
|
108
|
+
Secure Local Storage supports multiple frameworks through environment variables:
|
|
109
|
+
|
|
110
|
+
#### React
|
|
111
|
+
```bash
|
|
112
|
+
REACT_APP_SECURE_LOCAL_STORAGE_HASH_KEY=your-secret-key
|
|
113
|
+
REACT_APP_SECURE_LOCAL_STORAGE_PREFIX=myapp_
|
|
114
|
+
REACT_APP_SECURE_LOCAL_STORAGE_DISABLED_KEYS=Canvas|Fonts
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Vite
|
|
118
|
+
```bash
|
|
119
|
+
VITE_SECURE_LOCAL_STORAGE_HASH_KEY=your-secret-key
|
|
120
|
+
VITE_SECURE_LOCAL_STORAGE_PREFIX=myapp_
|
|
121
|
+
VITE_SECURE_LOCAL_STORAGE_DISABLED_KEYS=Canvas|Fonts
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Next.js
|
|
125
|
+
```bash
|
|
126
|
+
NEXT_PUBLIC_SECURE_LOCAL_STORAGE_HASH_KEY=your-secret-key
|
|
127
|
+
NEXT_PUBLIC_SECURE_LOCAL_STORAGE_PREFIX=myapp_
|
|
128
|
+
NEXT_PUBLIC_SECURE_LOCAL_STORAGE_DISABLED_KEYS=Canvas|Fonts
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Generic/Node.js
|
|
132
|
+
```bash
|
|
133
|
+
SECURE_LOCAL_STORAGE_HASH_KEY=your-secret-key
|
|
134
|
+
SECURE_LOCAL_STORAGE_PREFIX=myapp_
|
|
135
|
+
SECURE_LOCAL_STORAGE_DISABLED_KEYS=Canvas|Fonts
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Vite Configuration
|
|
139
|
+
|
|
140
|
+
For Vite projects, you need to define `process.env` in your `vite.config.ts`:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { defineConfig } from 'vite'
|
|
144
|
+
|
|
145
|
+
export default defineConfig({
|
|
146
|
+
define: {
|
|
147
|
+
"process.env": {
|
|
148
|
+
SECURE_LOCAL_STORAGE_HASH_KEY: JSON.stringify(process.env.VITE_SECURE_LOCAL_STORAGE_HASH_KEY),
|
|
149
|
+
// Add other environment variables as needed
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Configuration Options
|
|
156
|
+
|
|
157
|
+
| Option | Type | Default | Description |
|
|
158
|
+
|--------|------|---------|-------------|
|
|
159
|
+
| `hashKey` | `string` | `'secure-local-storage-default-key'` | Custom encryption key |
|
|
160
|
+
| `prefix` | `string` | `'sls_'` | Storage key prefix |
|
|
161
|
+
| `disabledKeys` | `FingerprintProperty[]` | `[]` | Disabled fingerprint properties |
|
|
162
|
+
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
163
|
+
|
|
164
|
+
### Fingerprint Properties
|
|
165
|
+
|
|
166
|
+
You can disable specific browser fingerprint properties:
|
|
167
|
+
|
|
168
|
+
| Property | Description |
|
|
169
|
+
|----------|-------------|
|
|
170
|
+
| `UserAgent` | Browser user agent string |
|
|
171
|
+
| `ScreenPrint` | Screen dimensions and color depth |
|
|
172
|
+
| `Plugins` | Installed browser plugins |
|
|
173
|
+
| `Fonts` | Available system fonts |
|
|
174
|
+
| `LocalStorage` | localStorage availability |
|
|
175
|
+
| `SessionStorage` | sessionStorage availability |
|
|
176
|
+
| `TimeZone` | System timezone |
|
|
177
|
+
| `Language` | Browser language |
|
|
178
|
+
| `SystemLanguage` | System language |
|
|
179
|
+
| `Cookie` | Cookie support |
|
|
180
|
+
| `Canvas` | Canvas fingerprint |
|
|
181
|
+
| `Hostname` | Current hostname |
|
|
182
|
+
|
|
183
|
+
> **Note**: Disabling properties reduces the uniqueness of the browser fingerprint, potentially making encryption less secure.
|
|
184
|
+
|
|
185
|
+
## 🔧 API Reference
|
|
186
|
+
|
|
187
|
+
### Methods
|
|
188
|
+
|
|
189
|
+
#### `setItem(key: string, value: StorageValue): void`
|
|
190
|
+
Stores a value in secure local storage.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
secureLocalStorage.setItem('user', { name: 'John', age: 30 });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `getItem(key: string): StorageValue`
|
|
197
|
+
Retrieves a value from secure local storage. Returns `null` if the key doesn't exist.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const user = secureLocalStorage.getItem('user');
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### `removeItem(key: string): void`
|
|
204
|
+
Removes a specific item from secure local storage.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
secureLocalStorage.removeItem('user');
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### `clear(): void`
|
|
211
|
+
Removes all items from secure local storage.
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
secureLocalStorage.clear();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
#### `keys(): string[]`
|
|
218
|
+
Returns an array of all keys in secure local storage.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const allKeys = secureLocalStorage.keys();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### `length(): number`
|
|
225
|
+
Returns the number of items in secure local storage.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const itemCount = secureLocalStorage.length();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Types
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
type StorageValue = string | number | boolean | object | null;
|
|
235
|
+
|
|
236
|
+
interface SecureStorageConfig {
|
|
237
|
+
hashKey?: string;
|
|
238
|
+
prefix?: string;
|
|
239
|
+
disabledKeys?: FingerprintProperty[];
|
|
240
|
+
debug?: boolean;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type FingerprintProperty =
|
|
244
|
+
| 'UserAgent' | 'ScreenPrint' | 'Plugins' | 'Fonts'
|
|
245
|
+
| 'LocalStorage' | 'SessionStorage' | 'TimeZone' | 'Language'
|
|
246
|
+
| 'SystemLanguage' | 'Cookie' | 'Canvas' | 'Hostname';
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## 🔒 Security Features
|
|
250
|
+
|
|
251
|
+
### Encryption Details
|
|
252
|
+
- **Algorithm**: ChaCha20-Poly1305 authenticated encryption with PBKDF2-SHA256 key derivation
|
|
253
|
+
- **Key Generation**: Combines user hash key with browser fingerprint
|
|
254
|
+
- **Salt**: Uses a fixed salt for consistent key generation
|
|
255
|
+
- **Iterations**: 1000 PBKDF2 iterations for key strengthening
|
|
256
|
+
|
|
257
|
+
### Browser Fingerprinting
|
|
258
|
+
The library generates a unique fingerprint using:
|
|
259
|
+
- User agent string
|
|
260
|
+
- Screen dimensions and color depth
|
|
261
|
+
- Installed plugins
|
|
262
|
+
- Available fonts (canvas-based detection)
|
|
263
|
+
- Storage capabilities
|
|
264
|
+
- Timezone and language settings
|
|
265
|
+
- Canvas fingerprint
|
|
266
|
+
- Current hostname
|
|
267
|
+
|
|
268
|
+
### Data Protection
|
|
269
|
+
- Each encrypted item includes metadata (type, timestamp, version)
|
|
270
|
+
- Type information is preserved and restored
|
|
271
|
+
- Memory cache prevents repeated decryption operations
|
|
272
|
+
- Automatic validation of encrypted data integrity
|
|
273
|
+
|
|
274
|
+
## 📚 Examples
|
|
275
|
+
|
|
276
|
+
### React Example
|
|
277
|
+
|
|
278
|
+
```tsx
|
|
279
|
+
import React, { useState, useEffect } from 'react';
|
|
280
|
+
import secureLocalStorage from '@pathscale/secure-local-storage-chacha20-poly1305';
|
|
281
|
+
|
|
282
|
+
const UserProfile: React.FC = () => {
|
|
283
|
+
const [user, setUser] = useState(null);
|
|
284
|
+
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
// Load user from secure storage
|
|
287
|
+
const savedUser = secureLocalStorage.getItem('user');
|
|
288
|
+
if (savedUser) {
|
|
289
|
+
setUser(savedUser);
|
|
290
|
+
}
|
|
291
|
+
}, []);
|
|
292
|
+
|
|
293
|
+
const saveUser = (userData: any) => {
|
|
294
|
+
secureLocalStorage.setItem('user', userData);
|
|
295
|
+
setUser(userData);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const logout = () => {
|
|
299
|
+
secureLocalStorage.removeItem('user');
|
|
300
|
+
setUser(null);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<div>
|
|
305
|
+
{user ? (
|
|
306
|
+
<div>
|
|
307
|
+
<h1>Welcome, {user.name}!</h1>
|
|
308
|
+
<button onClick={logout}>Logout</button>
|
|
309
|
+
</div>
|
|
310
|
+
) : (
|
|
311
|
+
<button onClick={() => saveUser({ name: 'John', id: 1 })}>
|
|
312
|
+
Login
|
|
313
|
+
</button>
|
|
314
|
+
)}
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
};
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Vue Example
|
|
321
|
+
|
|
322
|
+
```vue
|
|
323
|
+
<template>
|
|
324
|
+
<div>
|
|
325
|
+
<h1 v-if="user">Welcome, {{ user.name }}!</h1>
|
|
326
|
+
<button @click="toggleUser">
|
|
327
|
+
{{ user ? 'Logout' : 'Login' }}
|
|
328
|
+
</button>
|
|
329
|
+
</div>
|
|
330
|
+
</template>
|
|
331
|
+
|
|
332
|
+
<script>
|
|
333
|
+
import secureLocalStorage from '@pathscale/secure-local-storage-chacha20-poly1305';
|
|
334
|
+
|
|
335
|
+
export default {
|
|
336
|
+
data() {
|
|
337
|
+
return {
|
|
338
|
+
user: null
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
mounted() {
|
|
343
|
+
this.user = secureLocalStorage.getItem('user');
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
methods: {
|
|
347
|
+
toggleUser() {
|
|
348
|
+
if (this.user) {
|
|
349
|
+
secureLocalStorage.removeItem('user');
|
|
350
|
+
this.user = null;
|
|
351
|
+
} else {
|
|
352
|
+
const userData = { name: 'John', id: 1 };
|
|
353
|
+
secureLocalStorage.setItem('user', userData);
|
|
354
|
+
this.user = userData;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
</script>
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## 🤝 Contributing
|
|
363
|
+
|
|
364
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
365
|
+
|
|
366
|
+
Please read our [Contributing Guide](CONTRIBUTING.md) for detailed information on:
|
|
367
|
+
|
|
368
|
+
- Setting up the development environment
|
|
369
|
+
- Running tests locally
|
|
370
|
+
- Code style guidelines
|
|
371
|
+
- Submitting pull requests
|
|
372
|
+
- Development workflow
|
|
373
|
+
|
|
374
|
+
### Development Setup
|
|
375
|
+
|
|
376
|
+
1. Clone the repository
|
|
377
|
+
2. Install dependencies: `npm install`
|
|
378
|
+
3. Build the project: `npm run build`
|
|
379
|
+
4. Run linting: `npm run lint`
|
|
380
|
+
5. Test locally in a browser with the built files
|
|
381
|
+
|
|
382
|
+
For detailed development instructions, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
383
|
+
|
|
384
|
+
## 📄 License
|
|
385
|
+
|
|
386
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
387
|
+
|
|
388
|
+
## 🙋♂️ Support
|
|
389
|
+
|
|
390
|
+
If you have any questions or issues, please:
|
|
391
|
+
|
|
392
|
+
1. Check the [documentation](#-api-reference)
|
|
393
|
+
2. Search existing issues in the fork repository
|
|
394
|
+
3. Create a new issue if needed
|
|
395
|
+
|
|
396
|
+
## 🔗 Related Projects
|
|
397
|
+
|
|
398
|
+
- [noble-ciphers](https://github.com/paulmillr/noble-ciphers) - Audited JavaScript ciphers including ChaCha20-Poly1305
|
|
399
|
+
- [fingerprintjs](https://github.com/fingerprintjs/fingerprintjs) - Browser fingerprinting
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
Forked from `@jahidulsaeid/secure-local-storage` and ported to ChaCha20-Poly1305.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SecureStorageConfig, StorageValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Secure Local Storage - A secure, encrypted local storage with browser fingerprinting
|
|
4
|
+
*/
|
|
5
|
+
export declare class SecureLocalStorage {
|
|
6
|
+
private static instance;
|
|
7
|
+
private fingerprinting;
|
|
8
|
+
private encryption;
|
|
9
|
+
private environment;
|
|
10
|
+
private config;
|
|
11
|
+
private storageEngine;
|
|
12
|
+
private prefix;
|
|
13
|
+
private memoryCache;
|
|
14
|
+
private isInitialized;
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Get the singleton instance
|
|
18
|
+
*/
|
|
19
|
+
static getInstance(config?: Partial<SecureStorageConfig>): SecureLocalStorage;
|
|
20
|
+
/**
|
|
21
|
+
* Set an item in secure storage
|
|
22
|
+
*/
|
|
23
|
+
setItem(key: string, value: StorageValue): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get an item from secure storage
|
|
26
|
+
*/
|
|
27
|
+
getItem(key: string): StorageValue;
|
|
28
|
+
/**
|
|
29
|
+
* Remove an item from secure storage
|
|
30
|
+
*/
|
|
31
|
+
removeItem(key: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Clear all items from secure storage
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get all keys in secure storage
|
|
38
|
+
*/
|
|
39
|
+
keys(): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Get the number of items in secure storage
|
|
42
|
+
*/
|
|
43
|
+
length(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Update configuration
|
|
46
|
+
*/
|
|
47
|
+
updateConfig(newConfig: Partial<SecureStorageConfig>): void;
|
|
48
|
+
private getStorageEngine;
|
|
49
|
+
private getStorageKey;
|
|
50
|
+
private generateDefaultHashKey;
|
|
51
|
+
private generateSecretKey;
|
|
52
|
+
private initializeFromStorage;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=SecureLocalStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecureLocalStorage.d.ts","sourceRoot":"","sources":["../src/SecureLocalStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAE3E;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmC;IAC1D,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,aAAa,CAAkB;IAEvC,OAAO;IA4BP;;OAEG;WACW,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,kBAAkB;IAOpF;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAqBtD;;OAEG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAoCzC;;OAEG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAmBpC;;OAEG;IACI,KAAK,IAAI,IAAI;IA+BpB;;OAEG;IACI,IAAI,IAAI,MAAM,EAAE;IAkBvB;;OAEG;IACI,MAAM,IAAI,MAAM;IAIvB;;OAEG;IACI,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI;IAoBlE,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,qBAAqB;CAsB9B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StorageValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Encryption utility for secure data storage
|
|
4
|
+
*/
|
|
5
|
+
export declare class EncryptionManager {
|
|
6
|
+
private secretKey;
|
|
7
|
+
private readonly version;
|
|
8
|
+
private readonly textEncoder;
|
|
9
|
+
private readonly textDecoder;
|
|
10
|
+
constructor(secretKey: string);
|
|
11
|
+
/**
|
|
12
|
+
* Update the secret key
|
|
13
|
+
*/
|
|
14
|
+
updateSecretKey(newSecretKey: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Encrypt data with type preservation
|
|
17
|
+
*/
|
|
18
|
+
encrypt(data: StorageValue): string;
|
|
19
|
+
/**
|
|
20
|
+
* Decrypt data with type restoration
|
|
21
|
+
*/
|
|
22
|
+
decrypt(encryptedData: string): StorageValue;
|
|
23
|
+
/**
|
|
24
|
+
* Validate if data was encrypted with this library
|
|
25
|
+
*/
|
|
26
|
+
isValidEncryptedData(encryptedData: string): boolean;
|
|
27
|
+
private deriveKey;
|
|
28
|
+
private serializeData;
|
|
29
|
+
private deserializeData;
|
|
30
|
+
private getDataType;
|
|
31
|
+
private isChachaEnvelope;
|
|
32
|
+
private encodeBase64;
|
|
33
|
+
private decodeBase64;
|
|
34
|
+
private getGlobalBuffer;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../src/encryption.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAC;AAuB7D;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;gBAErC,SAAS,EAAE,MAAM;IAI7B;;OAEG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAKlD;;OAEG;IACI,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM;IAsB1C;;OAEG;IACI,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,YAAY;IAoBnD;;OAEG;IACI,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAe3D,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,eAAe;IAuBvB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,eAAe;CAGxB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SecureStorageConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Environment configuration manager for different frameworks
|
|
4
|
+
*/
|
|
5
|
+
export declare class EnvironmentManager {
|
|
6
|
+
private config;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Get configuration from environment variables
|
|
10
|
+
*/
|
|
11
|
+
getConfig(): SecureStorageConfig;
|
|
12
|
+
private loadEnvironmentVariables;
|
|
13
|
+
private getHashKey;
|
|
14
|
+
private getPrefix;
|
|
15
|
+
private getDisabledKeys;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,mBAAmB,EAAuB,MAAM,SAAS,CAAC;AAEtF;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAoB;;IAMlC;;OAEG;IACI,SAAS,IAAI,mBAAmB;IAgBvC,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,eAAe;CAcxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BrowserFingerprint, FingerprintProperty } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Browser fingerprinting utility for generating unique browser identifiers
|
|
4
|
+
*/
|
|
5
|
+
export declare class BrowserFingerprinting {
|
|
6
|
+
private disabledKeys;
|
|
7
|
+
constructor(disabledKeys?: FingerprintProperty[]);
|
|
8
|
+
/**
|
|
9
|
+
* Generate a comprehensive browser fingerprint
|
|
10
|
+
*/
|
|
11
|
+
generateFingerprint(): BrowserFingerprint;
|
|
12
|
+
/**
|
|
13
|
+
* Convert fingerprint to a hash string
|
|
14
|
+
*/
|
|
15
|
+
fingerprintToString(fingerprint: BrowserFingerprint): string;
|
|
16
|
+
private isEnabled;
|
|
17
|
+
private getUserAgent;
|
|
18
|
+
private getScreenPrint;
|
|
19
|
+
private getPlugins;
|
|
20
|
+
private getFonts;
|
|
21
|
+
private hasLocalStorage;
|
|
22
|
+
private hasSessionStorage;
|
|
23
|
+
private getTimeZone;
|
|
24
|
+
private getLanguage;
|
|
25
|
+
private getSystemLanguage;
|
|
26
|
+
private hasCookieSupport;
|
|
27
|
+
private getCanvasFingerprint;
|
|
28
|
+
private getHostname;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=fingerprinting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprinting.d.ts","sourceRoot":"","sources":["../src/fingerprinting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAElE;;GAEG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,YAAY,CAA2B;gBAEnC,YAAY,GAAE,mBAAmB,EAAO;IAIpD;;OAEG;IACI,mBAAmB,IAAI,kBAAkB;IAiBhD;;OAEG;IACI,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM;IAMnE,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,QAAQ;IA+BhB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,WAAW;CAIpB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { SecureLocalStorage } from './SecureLocalStorage';
|
|
2
|
+
export { BrowserFingerprinting } from './fingerprinting';
|
|
3
|
+
export { EncryptionManager } from './encryption';
|
|
4
|
+
export { EnvironmentManager } from './environment';
|
|
5
|
+
export * from './types';
|
|
6
|
+
import { SecureLocalStorage } from './SecureLocalStorage';
|
|
7
|
+
/**
|
|
8
|
+
* Default secure local storage instance
|
|
9
|
+
*/
|
|
10
|
+
declare const secureLocalStorage: SecureLocalStorage;
|
|
11
|
+
export default secureLocalStorage;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,QAAA,MAAM,kBAAkB,oBAAmC,CAAC;AAE5D,eAAe,kBAAkB,CAAC"}
|