peerpigeon 0.1.1 → 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.
Files changed (70) hide show
  1. package/README.md +141 -1365
  2. package/cli.js +1382 -0
  3. package/dist/peerpigeon-browser.js +12290 -0
  4. package/dist/peerpigeon-browser.js.map +7 -0
  5. package/docs/API_DOCUMENTATION.md +1945 -0
  6. package/docs/BOOTSTRAP_HUBS.md +319 -0
  7. package/docs/CLI_README.md +371 -0
  8. package/docs/DOCUMENTATION_REORGANIZATION.md +172 -0
  9. package/docs/HUB_QUICK_REF.md +107 -0
  10. package/docs/HUB_SCRIPTS.md +331 -0
  11. package/docs/HUB_SYSTEM.md +552 -0
  12. package/docs/MIGRATION_COMPLETE.md +93 -0
  13. package/docs/NETWORK_NAMESPACES.md +212 -0
  14. package/docs/README.md +107 -0
  15. package/docs/SELECTIVE_STREAMING_GUIDE.md +427 -0
  16. package/docs/TEST_CLEANUP_COMPLETE.md +80 -0
  17. package/examples/bootstrap-hub-example.js +292 -0
  18. package/examples/browser/README.md +278 -0
  19. package/examples/browser/app.js +2426 -49
  20. package/examples/browser/index.html +481 -630
  21. package/examples/browser/minimal/README.md +55 -0
  22. package/examples/browser/minimal/index.html +75 -0
  23. package/examples/browser/minimal/minimal.js +234 -0
  24. package/examples/browser/styles.css +687 -1425
  25. package/examples/browser/test-bundle.html +35 -0
  26. package/examples/browser-2/index.html +30 -0
  27. package/examples/browser-2/package.json +21 -0
  28. package/examples/browser-2/src/App-simple.vue +21 -0
  29. package/examples/browser-2/src/App.vue +420 -0
  30. package/examples/browser-2/src/components/CryptoView.vue +1661 -0
  31. package/examples/browser-2/src/components/DHTView.vue +1281 -0
  32. package/examples/browser-2/src/components/DebugView.vue +1773 -0
  33. package/examples/browser-2/src/components/MediaView.vue +1048 -0
  34. package/examples/browser-2/src/components/MessagingView.vue +775 -0
  35. package/examples/browser-2/src/components/NetworkView.vue +930 -0
  36. package/examples/browser-2/src/components/StorageView.vue +1376 -0
  37. package/examples/browser-2/src/main.js +5 -0
  38. package/examples/browser-2/src/stores/peerpigeon.js +895 -0
  39. package/examples/browser-2/vite.config.js +6 -0
  40. package/examples/hub-example.js +186 -0
  41. package/examples/multi-hub-test.js +186 -0
  42. package/examples/node/README.md +2 -2
  43. package/examples/selective-streaming-demo.html +698 -0
  44. package/examples/standard-events-demo.js +126 -0
  45. package/package.json +33 -16
  46. package/server/index.js +1032 -98
  47. package/server/start.js +49 -0
  48. package/src/ConnectionManager.js +239 -225
  49. package/src/CryptoManager.js +147 -18
  50. package/src/DebugLogger.js +0 -7
  51. package/src/DistributedStorageManager.js +224 -205
  52. package/src/EnvironmentDetector.js +109 -2
  53. package/src/EventEmitter.js +79 -1
  54. package/src/EvictionManager.js +10 -9
  55. package/src/GossipManager.js +163 -11
  56. package/src/PeerConnection.js +333 -310
  57. package/src/PeerPigeonMesh.js +577 -135
  58. package/src/SignalingClient.js +14 -243
  59. package/src/SignalingHandler.js +31 -10
  60. package/src/StorageManager.js +0 -39
  61. package/src/WebDHT-Simple.js +389 -0
  62. package/src/WebDHT.js +363 -1165
  63. package/src/browser-entry.js +40 -0
  64. package/examples/browser/assets/images/favicon.png +0 -0
  65. package/examples/browser/assets/images/pigeon.png +0 -0
  66. package/examples/browser/crypto-test.html +0 -427
  67. package/examples/browser/ui-old.js +0 -1926
  68. package/examples/browser/ui.js +0 -3391
  69. package/websocket-server/README.md +0 -247
  70. package/websocket-server/server.js +0 -391
@@ -0,0 +1,1376 @@
1
+ <template>
2
+ <div class="storage-view">
3
+ <div class="section-header">
4
+ <h2>📦 Distributed Storage Layer</h2>
5
+ <p>Encrypted, access-controlled storage with CRDT support for collaborative editing</p>
6
+ </div>
7
+
8
+ <!-- Storage Operations -->
9
+ <div class="storage-operations">
10
+ <h3>💾 Storage Operations</h3>
11
+
12
+ <div class="operation-tabs">
13
+ <button
14
+ @click="activeTab = 'store'"
15
+ :class="['tab-btn', { active: activeTab === 'store' }]"
16
+ >
17
+ STORE
18
+ </button>
19
+ <button
20
+ @click="activeTab = 'retrieve'"
21
+ :class="['tab-btn', { active: activeTab === 'retrieve' }]"
22
+ >
23
+ RETRIEVE
24
+ </button>
25
+ <button
26
+ @click="activeTab = 'update'"
27
+ :class="['tab-btn', { active: activeTab === 'update' }]"
28
+ >
29
+ UPDATE
30
+ </button>
31
+ <button
32
+ @click="activeTab = 'access'"
33
+ :class="['tab-btn', { active: activeTab === 'access' }]"
34
+ >
35
+ ACCESS CONTROL
36
+ </button>
37
+ </div>
38
+
39
+ <!-- STORE Operation -->
40
+ <div v-if="activeTab === 'store'" class="operation-panel">
41
+ <h4>💾 Store Data</h4>
42
+ <p class="operation-description">
43
+ Store data with encryption, access control, and optional immutability. Data is automatically distributed across the mesh.
44
+ </p>
45
+
46
+ <div class="form-group">
47
+ <label>Key:</label>
48
+ <input
49
+ v-model="storeKey"
50
+ placeholder="e.g., user:profile, doc:shared, config:app"
51
+ class="form-input"
52
+ >
53
+ </div>
54
+
55
+ <div class="form-group">
56
+ <label>Value (JSON):</label>
57
+ <textarea
58
+ v-model="storeValue"
59
+ placeholder='{"name": "Alice", "email": "alice@example.com"}'
60
+ rows="6"
61
+ class="form-textarea"
62
+ ></textarea>
63
+ </div>
64
+
65
+ <div class="form-group">
66
+ <label>Storage Options:</label>
67
+ <div class="option-checkboxes">
68
+ <label class="checkbox-label">
69
+ <input type="checkbox" v-model="storeOptions.isPublic">
70
+ Public (not encrypted, anyone can read)
71
+ </label>
72
+ <label class="checkbox-label">
73
+ <input type="checkbox" v-model="storeOptions.isImmutable">
74
+ Immutable (cannot be modified after creation)
75
+ </label>
76
+ <label class="checkbox-label">
77
+ <input type="checkbox" v-model="storeOptions.enableCRDT">
78
+ Enable CRDT (collaborative editing support)
79
+ </label>
80
+ <label class="checkbox-label">
81
+ <input type="checkbox" v-model="storeOptions.replicate">
82
+ Replicate across mesh
83
+ </label>
84
+ </div>
85
+ </div>
86
+
87
+ <div class="form-group" v-if="!storeOptions.isPublic">
88
+ <label>Encryption Level:</label>
89
+ <select v-model="storeOptions.encryptionLevel" class="form-select">
90
+ <option value="standard">Standard Encryption</option>
91
+ <option value="high">High Security</option>
92
+ <option value="group">Group Encryption</option>
93
+ </select>
94
+ </div>
95
+
96
+ <div class="form-group">
97
+ <label>TTL (seconds, optional):</label>
98
+ <input
99
+ v-model.number="storeOptions.ttl"
100
+ type="number"
101
+ placeholder="Leave empty for no expiration"
102
+ class="form-input"
103
+ >
104
+ </div>
105
+
106
+ <button
107
+ @click="performStore"
108
+ :disabled="!storeKey || !storeValue || !isConnected"
109
+ class="btn btn-primary"
110
+ >
111
+ <span class="btn-icon">💾</span>
112
+ Store Data
113
+ </button>
114
+ </div>
115
+
116
+ <!-- RETRIEVE Operation -->
117
+ <div v-if="activeTab === 'retrieve'" class="operation-panel">
118
+ <h4>📥 Retrieve Data</h4>
119
+ <p class="operation-description">
120
+ Retrieve encrypted data with automatic decryption based on your access permissions.
121
+ </p>
122
+
123
+ <div class="form-group">
124
+ <label>Key:</label>
125
+ <input
126
+ v-model="retrieveKey"
127
+ placeholder="Enter key to retrieve"
128
+ class="form-input"
129
+ >
130
+ </div>
131
+
132
+ <div class="form-group">
133
+ <label>Retrieve Options:</label>
134
+ <div class="option-checkboxes">
135
+ <label class="checkbox-label">
136
+ <input type="checkbox" v-model="retrieveOptions.forceRefresh">
137
+ Force refresh from network
138
+ </label>
139
+ <label class="checkbox-label">
140
+ <input type="checkbox" v-model="retrieveOptions.includeMetadata">
141
+ Include metadata
142
+ </label>
143
+ </div>
144
+ </div>
145
+
146
+ <button
147
+ @click="performRetrieve"
148
+ :disabled="!retrieveKey || !isConnected"
149
+ class="btn btn-primary"
150
+ >
151
+ <span class="btn-icon">🔍</span>
152
+ Retrieve Data
153
+ </button>
154
+
155
+ <div v-if="retrieveResult" class="result-panel">
156
+ <h5>Retrieved Data:</h5>
157
+ <pre class="result-content">{{ JSON.stringify(retrieveResult, null, 2) }}</pre>
158
+ </div>
159
+ </div>
160
+
161
+ <!-- UPDATE Operation -->
162
+ <div v-if="activeTab === 'update'" class="operation-panel">
163
+ <h4>🔄 Update Existing Data</h4>
164
+ <p class="operation-description">
165
+ Update data you own or contribute to CRDT-enabled collaborative documents.
166
+ </p>
167
+
168
+ <div class="form-group">
169
+ <label>Key:</label>
170
+ <input
171
+ v-model="updateKey"
172
+ placeholder="Key to update"
173
+ class="form-input"
174
+ >
175
+ </div>
176
+
177
+ <div class="form-group">
178
+ <label>New Value (JSON):</label>
179
+ <textarea
180
+ v-model="updateValue"
181
+ placeholder='{"name": "Alice Smith", "updated": true}'
182
+ rows="6"
183
+ class="form-textarea"
184
+ ></textarea>
185
+ </div>
186
+
187
+ <div class="form-group">
188
+ <label>Update Options:</label>
189
+ <div class="option-checkboxes">
190
+ <label class="checkbox-label">
191
+ <input type="checkbox" v-model="updateOptions.createIfNotExists">
192
+ Create if doesn't exist
193
+ </label>
194
+ <label class="checkbox-label">
195
+ <input type="checkbox" v-model="updateOptions.mergeData">
196
+ Merge with existing data
197
+ </label>
198
+ <label class="checkbox-label">
199
+ <input type="checkbox" v-model="updateOptions.incrementVersion">
200
+ Increment version
201
+ </label>
202
+ </div>
203
+ </div>
204
+
205
+ <button
206
+ @click="performUpdate"
207
+ :disabled="!updateKey || !updateValue || !isConnected"
208
+ class="btn btn-primary"
209
+ >
210
+ <span class="btn-icon">🔄</span>
211
+ Update Data
212
+ </button>
213
+ </div>
214
+
215
+ <!-- ACCESS CONTROL Operation -->
216
+ <div v-if="activeTab === 'access'" class="operation-panel">
217
+ <h4>🔐 Access Control</h4>
218
+ <p class="operation-description">
219
+ Grant or revoke access to your private data for specific peers.
220
+ </p>
221
+
222
+ <div class="access-section">
223
+ <h5>Grant Access</h5>
224
+ <div class="form-group">
225
+ <label>Data Key:</label>
226
+ <input
227
+ v-model="accessKey"
228
+ placeholder="Key to grant access to"
229
+ class="form-input"
230
+ >
231
+ </div>
232
+
233
+ <div class="form-group">
234
+ <label>Peer ID:</label>
235
+ <select v-model="selectedPeer" class="form-select">
236
+ <option value="">Select a peer...</option>
237
+ <option
238
+ v-for="peer in connectedPeersList"
239
+ :key="peer.id"
240
+ :value="peer.id"
241
+ >
242
+ {{ peer.id.substring(0, 16) }}... ({{ peer.status }})
243
+ </option>
244
+ </select>
245
+ </div>
246
+
247
+ <div class="access-controls">
248
+ <button
249
+ @click="grantAccess"
250
+ :disabled="!accessKey || !selectedPeer || !isConnected"
251
+ class="btn btn-success"
252
+ >
253
+ <span class="btn-icon">✅</span>
254
+ Grant Access
255
+ </button>
256
+
257
+ <button
258
+ @click="revokeAccess"
259
+ :disabled="!accessKey || !selectedPeer || !isConnected"
260
+ class="btn btn-danger"
261
+ >
262
+ <span class="btn-icon">❌</span>
263
+ Revoke Access
264
+ </button>
265
+ </div>
266
+ </div>
267
+ </div>
268
+ </div>
269
+
270
+ <!-- Stored Data Display -->
271
+ <div class="stored-data">
272
+ <div class="section-title">
273
+ <h3>📁 Stored Data ({{ storageData.size }})</h3>
274
+ <div class="data-controls">
275
+ <button @click="refreshAllStorageData" class="btn btn-secondary">
276
+ <span class="btn-icon">🔄</span>
277
+ Refresh All
278
+ </button>
279
+ <button @click="exportData" class="btn btn-secondary">
280
+ <span class="btn-icon">📤</span>
281
+ Export
282
+ </button>
283
+ <button @click="clearLocalStorageData" class="btn btn-danger">
284
+ <span class="btn-icon">🗑️</span>
285
+ Clear Local
286
+ </button>
287
+ </div>
288
+ </div>
289
+
290
+ <div v-if="storageData.size === 0" class="empty-data">
291
+ <div class="empty-icon">📭</div>
292
+ <p>No data stored yet</p>
293
+ <p class="empty-meta">Store some data using the STORE operation above</p>
294
+ </div>
295
+
296
+ <div v-else class="data-grid">
297
+ <div
298
+ v-for="[key, data] in Array.from(storageData.entries())"
299
+ :key="key"
300
+ class="data-item"
301
+ >
302
+ <div class="data-header">
303
+ <h4 class="data-key">{{ key }}</h4>
304
+ <div class="data-badges">
305
+ <span v-if="data.local" class="badge badge-local">Local</span>
306
+ <span v-else class="badge badge-remote">Remote</span>
307
+ <span v-if="data.options?.isPublic" class="badge badge-public">Public</span>
308
+ <span v-else class="badge badge-private">Private</span>
309
+ <span v-if="data.options?.isImmutable" class="badge badge-immutable">Immutable</span>
310
+ <span v-if="data.options?.enableCRDT" class="badge badge-crdt">CRDT</span>
311
+ </div>
312
+ </div>
313
+
314
+ <div class="data-meta">
315
+ <span class="data-timestamp">{{ formatTime(data.timestamp) }}</span>
316
+ <span v-if="data.version" class="data-version">v{{ data.version }}</span>
317
+ <span v-if="data.options?.ttl" class="data-ttl">TTL: {{ data.options.ttl }}s</span>
318
+ </div>
319
+
320
+ <div class="data-content">
321
+ <pre>{{ JSON.stringify(data.value, null, 2) }}</pre>
322
+ </div>
323
+
324
+ <div class="data-actions">
325
+ <button @click="copyStorageKey(key)" class="btn btn-sm btn-secondary">
326
+ <span class="btn-icon">📋</span>
327
+ Copy Key
328
+ </button>
329
+ <button @click="refreshSingleStorageData(key)" class="btn btn-sm btn-secondary">
330
+ <span class="btn-icon">🔄</span>
331
+ Refresh
332
+ </button>
333
+ <button
334
+ v-if="data.local && !data.options?.isImmutable"
335
+ @click="editData(key, data)"
336
+ class="btn btn-sm btn-primary"
337
+ >
338
+ <span class="btn-icon">✏️</span>
339
+ Edit
340
+ </button>
341
+ <button
342
+ v-if="data.local"
343
+ @click="viewAccessControl(key)"
344
+ class="btn btn-sm btn-info"
345
+ >
346
+ <span class="btn-icon">🔐</span>
347
+ Access
348
+ </button>
349
+ <button
350
+ v-if="data.local"
351
+ @click="deleteData(key)"
352
+ class="btn btn-sm btn-danger"
353
+ >
354
+ <span class="btn-icon">🗑️</span>
355
+ Delete
356
+ </button>
357
+ </div>
358
+ </div>
359
+ </div>
360
+ </div>
361
+
362
+ <!-- Storage Statistics -->
363
+ <div class="stats-section">
364
+ <h3>📊 Storage Statistics</h3>
365
+ <div class="stats-grid">
366
+ <div class="stat-card">
367
+ <div class="stat-icon">💾</div>
368
+ <div class="stat-content">
369
+ <h4>Local Data</h4>
370
+ <div class="stat-value">{{ localStorageCount }}</div>
371
+ <div class="stat-meta">Items stored locally</div>
372
+ </div>
373
+ </div>
374
+
375
+ <div class="stat-card">
376
+ <div class="stat-icon">🌐</div>
377
+ <div class="stat-content">
378
+ <h4>Remote Data</h4>
379
+ <div class="stat-value">{{ remoteStorageCount }}</div>
380
+ <div class="stat-meta">Items from other peers</div>
381
+ </div>
382
+ </div>
383
+
384
+ <div class="stat-card">
385
+ <div class="stat-icon">🔐</div>
386
+ <div class="stat-content">
387
+ <h4>Private Items</h4>
388
+ <div class="stat-value">{{ privateDataCount }}</div>
389
+ <div class="stat-meta">Encrypted data</div>
390
+ </div>
391
+ </div>
392
+
393
+ <div class="stat-card">
394
+ <div class="stat-icon">🌍</div>
395
+ <div class="stat-content">
396
+ <h4>Public Items</h4>
397
+ <div class="stat-value">{{ publicDataCount }}</div>
398
+ <div class="stat-meta">Unencrypted data</div>
399
+ </div>
400
+ </div>
401
+ </div>
402
+
403
+ <div class="storage-stats-detail" v-if="storageStats">
404
+ <h4>Detailed Storage Statistics:</h4>
405
+ <pre class="stats-json">{{ JSON.stringify(storageStats, null, 2) }}</pre>
406
+ </div>
407
+ </div>
408
+
409
+ <!-- Quick Actions -->
410
+ <div class="quick-actions">
411
+ <h3>⚡ Quick Storage Actions</h3>
412
+ <div class="action-buttons">
413
+ <button @click="createUserProfile" class="btn btn-secondary">
414
+ <span class="btn-icon">👤</span>
415
+ Create User Profile
416
+ </button>
417
+
418
+ <button @click="createSharedDocument" class="btn btn-secondary">
419
+ <span class="btn-icon">📄</span>
420
+ Create Shared Document
421
+ </button>
422
+
423
+ <button @click="createConfigFile" class="btn btn-secondary">
424
+ <span class="btn-icon">⚙️</span>
425
+ Create Config File
426
+ </button>
427
+
428
+ <button @click="demonstrateCollaboration" class="btn btn-secondary">
429
+ <span class="btn-icon">👥</span>
430
+ Demo Collaboration
431
+ </button>
432
+
433
+ <button @click="performEncryptionTest" class="btn btn-secondary">
434
+ <span class="btn-icon">🔒</span>
435
+ Test Encryption
436
+ </button>
437
+
438
+ <button @click="demonstrateAccessControl" class="btn btn-secondary">
439
+ <span class="btn-icon">🔐</span>
440
+ Demo Access Control
441
+ </button>
442
+ </div>
443
+ </div>
444
+ </div>
445
+ </template>
446
+
447
+ <script setup>
448
+ import { ref, computed, onMounted } from 'vue';
449
+ import { usePeerPigeonStore } from '../stores/peerpigeon.js';
450
+
451
+ const store = usePeerPigeonStore();
452
+
453
+ // Local reactive state
454
+ const activeTab = ref('store');
455
+
456
+ // Store form data
457
+ const storeKey = ref('');
458
+ const storeValue = ref('');
459
+ const storeOptions = ref({
460
+ isPublic: false,
461
+ isImmutable: false,
462
+ enableCRDT: false,
463
+ replicate: true,
464
+ encryptionLevel: 'standard',
465
+ ttl: null
466
+ });
467
+
468
+ // Retrieve form data
469
+ const retrieveKey = ref('');
470
+ const retrieveResult = ref(null);
471
+ const retrieveOptions = ref({
472
+ forceRefresh: false,
473
+ includeMetadata: false
474
+ });
475
+
476
+ // Update form data
477
+ const updateKey = ref('');
478
+ const updateValue = ref('');
479
+ const updateOptions = ref({
480
+ createIfNotExists: false,
481
+ mergeData: false,
482
+ incrementVersion: true
483
+ });
484
+
485
+ // Access control form data
486
+ const accessKey = ref('');
487
+ const selectedPeer = ref('');
488
+
489
+ // Computed properties
490
+ const storageData = computed(() => store.storageData);
491
+ const storageStats = computed(() => store.storageStats);
492
+ const connectedPeersList = computed(() => store.connectedPeersList);
493
+ const isConnected = computed(() => store.isConnected);
494
+
495
+ const localStorageCount = computed(() => {
496
+ return Array.from(storageData.value.values()).filter(data => data.local).length;
497
+ });
498
+
499
+ const remoteStorageCount = computed(() => {
500
+ return Array.from(storageData.value.values()).filter(data => !data.local).length;
501
+ });
502
+
503
+ const privateDataCount = computed(() => {
504
+ return Array.from(storageData.value.values()).filter(data => !data.options?.isPublic).length;
505
+ });
506
+
507
+ const publicDataCount = computed(() => {
508
+ return Array.from(storageData.value.values()).filter(data => data.options?.isPublic).length;
509
+ });
510
+
511
+ // Methods
512
+ const performStore = async () => {
513
+ try {
514
+ let value;
515
+ try {
516
+ value = JSON.parse(storeValue.value);
517
+ } catch (e) {
518
+ value = storeValue.value;
519
+ }
520
+
521
+ const options = { ...storeOptions.value };
522
+ if (options.ttl && options.ttl <= 0) {
523
+ delete options.ttl;
524
+ }
525
+
526
+ const success = await store.storageStore(storeKey.value, value, options);
527
+ if (success) {
528
+ store.addDebugLog(`Storage STORE successful: ${storeKey.value}`, 'success');
529
+ storeKey.value = '';
530
+ storeValue.value = '';
531
+ // Reset options to defaults
532
+ storeOptions.value = {
533
+ isPublic: false,
534
+ isImmutable: false,
535
+ enableCRDT: false,
536
+ replicate: true,
537
+ encryptionLevel: 'standard',
538
+ ttl: null
539
+ };
540
+ }
541
+ } catch (error) {
542
+ store.addDebugLog(`Storage STORE failed: ${error.message}`, 'error');
543
+ }
544
+ };
545
+
546
+ const performRetrieve = async () => {
547
+ try {
548
+ const options = { ...retrieveOptions.value };
549
+ const result = await store.storageRetrieve(retrieveKey.value, options);
550
+ retrieveResult.value = result;
551
+
552
+ if (result !== null) {
553
+ store.addDebugLog(`Storage RETRIEVE successful: ${retrieveKey.value}`, 'success');
554
+ } else {
555
+ store.addDebugLog(`Storage RETRIEVE returned null for key: ${retrieveKey.value}`, 'warning');
556
+ }
557
+ } catch (error) {
558
+ store.addDebugLog(`Storage RETRIEVE failed: ${error.message}`, 'error');
559
+ retrieveResult.value = null;
560
+ }
561
+ };
562
+
563
+ const performUpdate = async () => {
564
+ try {
565
+ let value;
566
+ try {
567
+ value = JSON.parse(updateValue.value);
568
+ } catch (e) {
569
+ value = updateValue.value;
570
+ }
571
+
572
+ if (store.mesh?.distributedStorage) {
573
+ const success = await store.mesh.distributedStorage.update(updateKey.value, value, updateOptions.value);
574
+ if (success) {
575
+ store.addDebugLog(`Storage UPDATE successful: ${updateKey.value}`, 'success');
576
+ updateKey.value = '';
577
+ updateValue.value = '';
578
+ }
579
+ }
580
+ } catch (error) {
581
+ store.addDebugLog(`Storage UPDATE failed: ${error.message}`, 'error');
582
+ }
583
+ };
584
+
585
+ const grantAccess = async () => {
586
+ try {
587
+ if (store.mesh?.distributedStorage) {
588
+ await store.mesh.distributedStorage.grantAccess(accessKey.value, selectedPeer.value);
589
+ store.addDebugLog(`Access granted to ${selectedPeer.value.substring(0, 8)}... for key: ${accessKey.value}`, 'success');
590
+ }
591
+ } catch (error) {
592
+ store.addDebugLog(`Failed to grant access: ${error.message}`, 'error');
593
+ }
594
+ };
595
+
596
+ const revokeAccess = async () => {
597
+ try {
598
+ if (store.mesh?.distributedStorage) {
599
+ await store.mesh.distributedStorage.revokeAccess(accessKey.value, selectedPeer.value);
600
+ store.addDebugLog(`Access revoked from ${selectedPeer.value.substring(0, 8)}... for key: ${accessKey.value}`, 'success');
601
+ }
602
+ } catch (error) {
603
+ store.addDebugLog(`Failed to revoke access: ${error.message}`, 'error');
604
+ }
605
+ };
606
+
607
+ const refreshAllStorageData = async () => {
608
+ for (const key of storageData.value.keys()) {
609
+ await refreshSingleStorageData(key);
610
+ }
611
+
612
+ // Also refresh storage stats
613
+ if (store.mesh?.distributedStorage) {
614
+ store.storageStats = await store.getStorageStats();
615
+ }
616
+
617
+ store.addDebugLog('Refreshed all storage data', 'info');
618
+ };
619
+
620
+ const refreshSingleStorageData = async (key) => {
621
+ try {
622
+ const result = await store.storageRetrieve(key, { forceRefresh: true });
623
+ if (result !== null) {
624
+ store.addDebugLog(`Refreshed storage key: ${key}`, 'success');
625
+ }
626
+ } catch (error) {
627
+ store.addDebugLog(`Failed to refresh storage key ${key}: ${error.message}`, 'error');
628
+ }
629
+ };
630
+
631
+ const clearLocalStorageData = () => {
632
+ store.storageData.clear();
633
+ store.addDebugLog('Cleared local storage data', 'info');
634
+ };
635
+
636
+ const copyStorageKey = async (key) => {
637
+ try {
638
+ await navigator.clipboard.writeText(key);
639
+ store.addDebugLog(`Copied key to clipboard: ${key}`, 'success');
640
+ } catch (error) {
641
+ store.addDebugLog('Failed to copy to clipboard', 'error');
642
+ }
643
+ };
644
+
645
+ const editData = (key, data) => {
646
+ updateKey.value = key;
647
+ updateValue.value = JSON.stringify(data.value, null, 2);
648
+ activeTab.value = 'update';
649
+ store.addDebugLog(`Editing data: ${key}`, 'info');
650
+ };
651
+
652
+ const viewAccessControl = (key) => {
653
+ accessKey.value = key;
654
+ activeTab.value = 'access';
655
+ store.addDebugLog(`Viewing access control for: ${key}`, 'info');
656
+ };
657
+
658
+ const deleteData = async (key) => {
659
+ if (confirm(`Are you sure you want to delete "${key}"?`)) {
660
+ try {
661
+ if (store.mesh?.distributedStorage) {
662
+ await store.mesh.distributedStorage.delete(key);
663
+ store.storageData.delete(key);
664
+ store.addDebugLog(`Deleted storage key: ${key}`, 'success');
665
+ }
666
+ } catch (error) {
667
+ store.addDebugLog(`Failed to delete storage key ${key}: ${error.message}`, 'error');
668
+ }
669
+ }
670
+ };
671
+
672
+ const exportData = () => {
673
+ const dataToExport = {};
674
+ for (const [key, data] of storageData.value) {
675
+ dataToExport[key] = {
676
+ value: data.value,
677
+ timestamp: data.timestamp,
678
+ options: data.options,
679
+ local: data.local
680
+ };
681
+ }
682
+
683
+ const dataStr = JSON.stringify(dataToExport, null, 2);
684
+ const dataBlob = new Blob([dataStr], { type: 'application/json' });
685
+ const url = URL.createObjectURL(dataBlob);
686
+
687
+ const a = document.createElement('a');
688
+ a.href = url;
689
+ a.download = `peerpigeon-storage-${Date.now()}.json`;
690
+ document.body.appendChild(a);
691
+ a.click();
692
+ document.body.removeChild(a);
693
+ URL.revokeObjectURL(url);
694
+
695
+ store.addDebugLog('Storage data exported', 'success');
696
+ };
697
+
698
+ const formatTime = (timestamp) => {
699
+ return new Date(timestamp).toLocaleTimeString();
700
+ };
701
+
702
+ // Quick Actions
703
+ const createUserProfile = async () => {
704
+ const profile = {
705
+ name: 'Alice Smith',
706
+ email: 'alice@example.com',
707
+ avatar: 'https://avatars.dicebear.com/api/avataaars/alice.svg',
708
+ preferences: {
709
+ theme: 'dark',
710
+ notifications: true,
711
+ language: 'en'
712
+ },
713
+ created: Date.now(),
714
+ lastUpdated: Date.now()
715
+ };
716
+
717
+ await store.storageStore('user:profile', profile, {
718
+ isPublic: false,
719
+ isImmutable: false,
720
+ enableCRDT: false,
721
+ replicate: true
722
+ });
723
+
724
+ store.addDebugLog('Created user profile in storage', 'success');
725
+ };
726
+
727
+ const createSharedDocument = async () => {
728
+ const document = {
729
+ title: 'Shared Document',
730
+ content: 'This is a shared document that supports collaborative editing.',
731
+ authors: [store.peerId.substring(0, 8) + '...'],
732
+ created: Date.now(),
733
+ lastModified: Date.now(),
734
+ version: 1
735
+ };
736
+
737
+ await store.storageStore('doc:shared', document, {
738
+ isPublic: true,
739
+ isImmutable: false,
740
+ enableCRDT: true,
741
+ replicate: true
742
+ });
743
+
744
+ store.addDebugLog('Created shared document in storage', 'success');
745
+ };
746
+
747
+ const createConfigFile = async () => {
748
+ const config = {
749
+ appName: 'PeerPigeon Vue Demo',
750
+ version: '1.0.0',
751
+ features: {
752
+ messaging: true,
753
+ media: true,
754
+ dht: true,
755
+ storage: true,
756
+ crypto: true
757
+ },
758
+ limits: {
759
+ maxPeers: 10,
760
+ maxMessageSize: 1024 * 1024,
761
+ maxStorageSize: 100 * 1024 * 1024
762
+ },
763
+ created: Date.now()
764
+ };
765
+
766
+ await store.storageStore('config:app', config, {
767
+ isPublic: true,
768
+ isImmutable: true,
769
+ enableCRDT: false,
770
+ replicate: true
771
+ });
772
+
773
+ store.addDebugLog('Created config file in storage', 'success');
774
+ };
775
+
776
+ const demonstrateCollaboration = async () => {
777
+ const collaboration = {
778
+ document: 'collaborative-demo',
779
+ participants: [store.peerId.substring(0, 8) + '...'],
780
+ content: {
781
+ title: 'Collaborative Demo',
782
+ sections: [
783
+ {
784
+ id: 1,
785
+ author: store.peerId.substring(0, 8) + '...',
786
+ content: 'This section was created by the first participant.',
787
+ timestamp: Date.now()
788
+ }
789
+ ]
790
+ },
791
+ metadata: {
792
+ created: Date.now(),
793
+ lastModified: Date.now(),
794
+ crdtVersion: 1
795
+ }
796
+ };
797
+
798
+ await store.storageStore('collab:demo', collaboration, {
799
+ isPublic: true,
800
+ isImmutable: false,
801
+ enableCRDT: true,
802
+ replicate: true
803
+ });
804
+
805
+ store.addDebugLog('Created collaboration demo in storage', 'success');
806
+ };
807
+
808
+ const performEncryptionTest = async () => {
809
+ const sensitiveData = {
810
+ secret: 'This is sensitive information',
811
+ keys: ['key1', 'key2', 'key3'],
812
+ metadata: {
813
+ classification: 'confidential',
814
+ owner: store.peerId.substring(0, 8) + '...',
815
+ created: Date.now()
816
+ }
817
+ };
818
+
819
+ await store.storageStore('test:encryption', sensitiveData, {
820
+ isPublic: false,
821
+ isImmutable: false,
822
+ enableCRDT: false,
823
+ replicate: true,
824
+ encryptionLevel: 'high'
825
+ });
826
+
827
+ store.addDebugLog('Created encryption test data in storage', 'success');
828
+ };
829
+
830
+ const demonstrateAccessControl = async () => {
831
+ const restrictedData = {
832
+ message: 'This data requires explicit access permissions',
833
+ level: 'restricted',
834
+ owner: store.peerId.substring(0, 8) + '...',
835
+ created: Date.now(),
836
+ accessLog: []
837
+ };
838
+
839
+ await store.storageStore('access:restricted', restrictedData, {
840
+ isPublic: false,
841
+ isImmutable: false,
842
+ enableCRDT: false,
843
+ replicate: true
844
+ });
845
+
846
+ store.addDebugLog('Created access control demo data in storage', 'success');
847
+ };
848
+
849
+ onMounted(async () => {
850
+ // Load storage stats
851
+ try {
852
+ store.storageStats = await store.getStorageStats();
853
+ } catch (error) {
854
+ console.warn('Failed to load storage stats:', error);
855
+ }
856
+ });
857
+ </script>
858
+
859
+ <style scoped>
860
+ /* Same base styles as DHTView with storage-specific modifications */
861
+ .storage-view {
862
+ max-width: 1200px;
863
+ margin: 0 auto;
864
+ }
865
+
866
+ .section-header {
867
+ text-align: center;
868
+ margin-bottom: 30px;
869
+ }
870
+
871
+ .section-header h2 {
872
+ font-size: 28px;
873
+ color: #333;
874
+ margin-bottom: 8px;
875
+ }
876
+
877
+ .section-header p {
878
+ color: #666;
879
+ font-size: 16px;
880
+ }
881
+
882
+ .storage-operations {
883
+ background: white;
884
+ border-radius: 12px;
885
+ padding: 24px;
886
+ margin-bottom: 30px;
887
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
888
+ }
889
+
890
+ .storage-operations h3 {
891
+ margin: 0 0 20px 0;
892
+ color: #333;
893
+ }
894
+
895
+ .operation-tabs {
896
+ display: flex;
897
+ gap: 2px;
898
+ margin-bottom: 20px;
899
+ border-bottom: 1px solid #eee;
900
+ }
901
+
902
+ .tab-btn {
903
+ padding: 12px 20px;
904
+ border: none;
905
+ background: none;
906
+ color: #666;
907
+ cursor: pointer;
908
+ border-bottom: 3px solid transparent;
909
+ transition: all 0.2s;
910
+ font-weight: 500;
911
+ }
912
+
913
+ .tab-btn:hover {
914
+ color: #3b82f6;
915
+ background: rgba(59, 130, 246, 0.05);
916
+ }
917
+
918
+ .tab-btn.active {
919
+ color: #3b82f6;
920
+ border-bottom-color: #3b82f6;
921
+ }
922
+
923
+ .operation-panel {
924
+ padding: 20px;
925
+ border: 1px solid #eee;
926
+ border-radius: 8px;
927
+ background: #fafafa;
928
+ }
929
+
930
+ .operation-panel h4 {
931
+ margin: 0 0 8px 0;
932
+ color: #333;
933
+ }
934
+
935
+ .operation-description {
936
+ color: #666;
937
+ font-size: 14px;
938
+ margin-bottom: 20px;
939
+ line-height: 1.5;
940
+ }
941
+
942
+ .form-group {
943
+ margin-bottom: 16px;
944
+ }
945
+
946
+ .form-group label {
947
+ display: block;
948
+ margin-bottom: 6px;
949
+ font-weight: 500;
950
+ color: #333;
951
+ font-size: 14px;
952
+ }
953
+
954
+ .form-input,
955
+ .form-textarea,
956
+ .form-select {
957
+ width: 100%;
958
+ padding: 10px 12px;
959
+ border: 1px solid #ddd;
960
+ border-radius: 6px;
961
+ font-size: 14px;
962
+ font-family: inherit;
963
+ }
964
+
965
+ .form-textarea {
966
+ resize: vertical;
967
+ font-family: monospace;
968
+ }
969
+
970
+ .form-input:focus,
971
+ .form-textarea:focus,
972
+ .form-select:focus {
973
+ outline: none;
974
+ border-color: #3b82f6;
975
+ box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
976
+ }
977
+
978
+ .option-checkboxes {
979
+ display: flex;
980
+ flex-direction: column;
981
+ gap: 8px;
982
+ }
983
+
984
+ .checkbox-label {
985
+ display: flex !important;
986
+ align-items: center;
987
+ gap: 8px;
988
+ font-size: 14px;
989
+ cursor: pointer;
990
+ margin-bottom: 0 !important;
991
+ }
992
+
993
+ .checkbox-label input[type="checkbox"] {
994
+ width: auto;
995
+ margin: 0;
996
+ }
997
+
998
+ .access-section {
999
+ border-top: 1px solid #eee;
1000
+ padding-top: 16px;
1001
+ }
1002
+
1003
+ .access-section h5 {
1004
+ margin: 0 0 16px 0;
1005
+ color: #333;
1006
+ }
1007
+
1008
+ .access-controls {
1009
+ display: flex;
1010
+ gap: 12px;
1011
+ }
1012
+
1013
+ .result-panel {
1014
+ margin-top: 16px;
1015
+ padding: 16px;
1016
+ background: white;
1017
+ border: 1px solid #eee;
1018
+ border-radius: 6px;
1019
+ }
1020
+
1021
+ .result-panel h5 {
1022
+ margin: 0 0 12px 0;
1023
+ color: #333;
1024
+ }
1025
+
1026
+ .result-content {
1027
+ margin: 0;
1028
+ padding: 12px;
1029
+ background: #f8f9fa;
1030
+ border-radius: 4px;
1031
+ font-size: 13px;
1032
+ overflow-x: auto;
1033
+ }
1034
+
1035
+ .btn {
1036
+ padding: 8px 16px;
1037
+ border: none;
1038
+ border-radius: 6px;
1039
+ font-size: 14px;
1040
+ font-weight: 500;
1041
+ cursor: pointer;
1042
+ transition: all 0.2s;
1043
+ display: inline-flex;
1044
+ align-items: center;
1045
+ gap: 6px;
1046
+ }
1047
+
1048
+ .btn:disabled {
1049
+ opacity: 0.6;
1050
+ cursor: not-allowed;
1051
+ }
1052
+
1053
+ .btn-primary {
1054
+ background: #3b82f6;
1055
+ color: white;
1056
+ }
1057
+
1058
+ .btn-primary:hover:not(:disabled) {
1059
+ background: #2563eb;
1060
+ }
1061
+
1062
+ .btn-secondary {
1063
+ background: #6b7280;
1064
+ color: white;
1065
+ }
1066
+
1067
+ .btn-secondary:hover:not(:disabled) {
1068
+ background: #4b5563;
1069
+ }
1070
+
1071
+ .btn-success {
1072
+ background: #10b981;
1073
+ color: white;
1074
+ }
1075
+
1076
+ .btn-success:hover:not(:disabled) {
1077
+ background: #059669;
1078
+ }
1079
+
1080
+ .btn-danger {
1081
+ background: #ef4444;
1082
+ color: white;
1083
+ }
1084
+
1085
+ .btn-danger:hover:not(:disabled) {
1086
+ background: #dc2626;
1087
+ }
1088
+
1089
+ .btn-info {
1090
+ background: #06b6d4;
1091
+ color: white;
1092
+ }
1093
+
1094
+ .btn-info:hover:not(:disabled) {
1095
+ background: #0891b2;
1096
+ }
1097
+
1098
+ .btn-sm {
1099
+ padding: 4px 8px;
1100
+ font-size: 12px;
1101
+ }
1102
+
1103
+ .btn-icon {
1104
+ font-size: 14px;
1105
+ }
1106
+
1107
+ .stored-data {
1108
+ background: white;
1109
+ border-radius: 12px;
1110
+ padding: 24px;
1111
+ margin-bottom: 30px;
1112
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1113
+ }
1114
+
1115
+ .section-title {
1116
+ display: flex;
1117
+ justify-content: space-between;
1118
+ align-items: center;
1119
+ margin-bottom: 20px;
1120
+ }
1121
+
1122
+ .section-title h3 {
1123
+ margin: 0;
1124
+ color: #333;
1125
+ }
1126
+
1127
+ .data-controls {
1128
+ display: flex;
1129
+ gap: 8px;
1130
+ }
1131
+
1132
+ .empty-data {
1133
+ text-align: center;
1134
+ padding: 60px 20px;
1135
+ color: #666;
1136
+ }
1137
+
1138
+ .empty-icon {
1139
+ font-size: 48px;
1140
+ margin-bottom: 16px;
1141
+ }
1142
+
1143
+ .empty-data p {
1144
+ margin: 0 0 8px 0;
1145
+ }
1146
+
1147
+ .empty-meta {
1148
+ font-size: 14px;
1149
+ color: #999;
1150
+ }
1151
+
1152
+ .data-grid {
1153
+ display: grid;
1154
+ gap: 16px;
1155
+ }
1156
+
1157
+ .data-item {
1158
+ border: 1px solid #eee;
1159
+ border-radius: 8px;
1160
+ padding: 16px;
1161
+ background: #fafafa;
1162
+ }
1163
+
1164
+ .data-header {
1165
+ display: flex;
1166
+ justify-content: space-between;
1167
+ align-items: flex-start;
1168
+ margin-bottom: 8px;
1169
+ }
1170
+
1171
+ .data-key {
1172
+ margin: 0;
1173
+ font-family: monospace;
1174
+ font-size: 14px;
1175
+ color: #333;
1176
+ word-break: break-all;
1177
+ }
1178
+
1179
+ .data-badges {
1180
+ display: flex;
1181
+ gap: 4px;
1182
+ flex-wrap: wrap;
1183
+ flex-shrink: 0;
1184
+ }
1185
+
1186
+ .badge {
1187
+ padding: 2px 6px;
1188
+ border-radius: 3px;
1189
+ font-size: 10px;
1190
+ text-transform: uppercase;
1191
+ font-weight: 500;
1192
+ }
1193
+
1194
+ .badge-local {
1195
+ background: #10b981;
1196
+ color: white;
1197
+ }
1198
+
1199
+ .badge-remote {
1200
+ background: #6b7280;
1201
+ color: white;
1202
+ }
1203
+
1204
+ .badge-public {
1205
+ background: #3b82f6;
1206
+ color: white;
1207
+ }
1208
+
1209
+ .badge-private {
1210
+ background: #ef4444;
1211
+ color: white;
1212
+ }
1213
+
1214
+ .badge-immutable {
1215
+ background: #f59e0b;
1216
+ color: white;
1217
+ }
1218
+
1219
+ .badge-crdt {
1220
+ background: #8b5cf6;
1221
+ color: white;
1222
+ }
1223
+
1224
+ .data-meta {
1225
+ display: flex;
1226
+ justify-content: space-between;
1227
+ align-items: center;
1228
+ margin-bottom: 12px;
1229
+ font-size: 12px;
1230
+ color: #999;
1231
+ flex-wrap: wrap;
1232
+ gap: 8px;
1233
+ }
1234
+
1235
+ .data-content {
1236
+ margin-bottom: 12px;
1237
+ }
1238
+
1239
+ .data-content pre {
1240
+ margin: 0;
1241
+ padding: 12px;
1242
+ background: white;
1243
+ border: 1px solid #eee;
1244
+ border-radius: 4px;
1245
+ font-size: 12px;
1246
+ overflow-x: auto;
1247
+ max-height: 200px;
1248
+ overflow-y: auto;
1249
+ }
1250
+
1251
+ .data-actions {
1252
+ display: flex;
1253
+ flex-wrap: wrap;
1254
+ gap: 6px;
1255
+ }
1256
+
1257
+ .stats-section {
1258
+ background: white;
1259
+ border-radius: 12px;
1260
+ padding: 24px;
1261
+ margin-bottom: 30px;
1262
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1263
+ }
1264
+
1265
+ .stats-section h3 {
1266
+ margin: 0 0 20px 0;
1267
+ color: #333;
1268
+ }
1269
+
1270
+ .stats-grid {
1271
+ display: grid;
1272
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
1273
+ gap: 16px;
1274
+ margin-bottom: 20px;
1275
+ }
1276
+
1277
+ .stat-card {
1278
+ display: flex;
1279
+ align-items: center;
1280
+ gap: 16px;
1281
+ padding: 16px;
1282
+ background: #f8f9fa;
1283
+ border-radius: 8px;
1284
+ border: 1px solid #eee;
1285
+ }
1286
+
1287
+ .stat-icon {
1288
+ font-size: 24px;
1289
+ opacity: 0.8;
1290
+ }
1291
+
1292
+ .stat-content h4 {
1293
+ margin: 0 0 4px 0;
1294
+ font-size: 13px;
1295
+ color: #666;
1296
+ text-transform: uppercase;
1297
+ letter-spacing: 0.5px;
1298
+ }
1299
+
1300
+ .stat-value {
1301
+ font-size: 20px;
1302
+ font-weight: 600;
1303
+ color: #333;
1304
+ margin-bottom: 2px;
1305
+ }
1306
+
1307
+ .stat-meta {
1308
+ font-size: 11px;
1309
+ color: #999;
1310
+ }
1311
+
1312
+ .storage-stats-detail h4 {
1313
+ margin: 0 0 12px 0;
1314
+ color: #333;
1315
+ }
1316
+
1317
+ .stats-json {
1318
+ margin: 0;
1319
+ padding: 16px;
1320
+ background: #f8f9fa;
1321
+ border: 1px solid #eee;
1322
+ border-radius: 6px;
1323
+ font-size: 12px;
1324
+ overflow-x: auto;
1325
+ max-height: 300px;
1326
+ overflow-y: auto;
1327
+ }
1328
+
1329
+ .quick-actions {
1330
+ background: white;
1331
+ border-radius: 12px;
1332
+ padding: 24px;
1333
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
1334
+ }
1335
+
1336
+ .quick-actions h3 {
1337
+ margin: 0 0 20px 0;
1338
+ color: #333;
1339
+ }
1340
+
1341
+ .action-buttons {
1342
+ display: flex;
1343
+ flex-wrap: wrap;
1344
+ gap: 12px;
1345
+ }
1346
+
1347
+ /* Responsive design */
1348
+ @media (max-width: 768px) {
1349
+ .operation-tabs {
1350
+ flex-wrap: wrap;
1351
+ }
1352
+
1353
+ .tab-btn {
1354
+ flex: 1;
1355
+ min-width: 120px;
1356
+ }
1357
+
1358
+ .access-controls {
1359
+ flex-direction: column;
1360
+ }
1361
+
1362
+ .data-header {
1363
+ flex-direction: column;
1364
+ align-items: flex-start;
1365
+ gap: 8px;
1366
+ }
1367
+
1368
+ .data-actions {
1369
+ justify-content: center;
1370
+ }
1371
+
1372
+ .action-buttons {
1373
+ flex-direction: column;
1374
+ }
1375
+ }
1376
+ </style>