shogun-core 6.9.8 → 6.9.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.
Files changed (34) hide show
  1. package/README.md +8 -136
  2. package/dist/browser/shogun-core.js +10966 -14092
  3. package/dist/browser/shogun-core.js.map +1 -1
  4. package/dist/src/gundb/crypto.js +0 -14
  5. package/dist/src/gundb/db.js +14 -13
  6. package/dist/src/gundb/index.js +0 -2
  7. package/dist/src/index.js +2 -4
  8. package/dist/src/managers/AuthManager.js +1 -3
  9. package/dist/src/managers/CoreInitializer.js +7 -126
  10. package/dist/src/plugins/nostr/nostrSigner.js +22 -31
  11. package/dist/src/plugins/web3/web3Connector.js +13 -38
  12. package/dist/src/plugins/web3/web3Signer.js +15 -22
  13. package/dist/src/plugins/webauthn/webauthn.js +7 -5
  14. package/dist/src/plugins/webauthn/webauthnPlugin.js +22 -20
  15. package/dist/src/plugins/webauthn/webauthnSigner.js +3 -3
  16. package/dist/src/utils/seedPhrase.js +36 -10
  17. package/dist/tsconfig.tsbuildinfo +1 -1
  18. package/dist/types/src/core.d.ts +2 -4
  19. package/dist/types/src/gundb/db.d.ts +1 -9
  20. package/dist/types/src/gundb/index.d.ts +0 -2
  21. package/dist/types/src/index.d.ts +2 -4
  22. package/dist/types/src/interfaces/shogun.d.ts +1 -5
  23. package/dist/types/src/managers/CoreInitializer.d.ts +0 -15
  24. package/dist/types/src/plugins/nostr/nostrSigner.d.ts +0 -1
  25. package/dist/types/src/plugins/web3/web3Connector.d.ts +2 -1
  26. package/dist/types/src/plugins/webauthn/webauthnSigner.d.ts +0 -1
  27. package/dist/types/src/utils/seedPhrase.d.ts +11 -3
  28. package/package.json +3 -4
  29. package/dist/src/gundb/db-holster.js +0 -1337
  30. package/dist/src/gundb/rxjs-holster.js +0 -383
  31. package/dist/src/gundb/rxjs.js +0 -506
  32. package/dist/types/src/gundb/db-holster.d.ts +0 -283
  33. package/dist/types/src/gundb/rxjs-holster.d.ts +0 -84
  34. package/dist/types/src/gundb/rxjs.d.ts +0 -110
package/README.md CHANGED
@@ -6,18 +6,13 @@
6
6
 
7
7
  ## Overview
8
8
 
9
- Shogun Core is a comprehensive SDK for building decentralized applications (dApps) that simplifies authentication, wallet management, and decentralized data storage. It combines GunDB's or Holster's peer-to-peer networking with modern authentication standards and blockchain integration.
10
-
11
- **Now supports both Gun and Holster!** You can use either database backend - Gun for maximum compatibility or Holster for modern ES modules and improved performance.
9
+ Shogun Core is a comprehensive SDK for building decentralized applications (dApps) that simplifies authentication, wallet management, and decentralized data storage. It utilizes GunDB's peer-to-peer networking with modern authentication standards and blockchain integration.
12
10
 
13
11
  ## Features
14
12
 
15
13
  - 🔐 **Multiple Authentication Methods**: Password, WebAuthn (biometrics), Web3 (MetaMask), Nostr, Challenge (Server-Signed)
16
- - 🌐 **Decentralized Storage**: Built on GunDB or Holster for peer-to-peer data synchronization
17
- - 🔄 **Dual Database Support**: Use Gun (maximum compatibility) or Holster (modern ES modules, improved performance)
14
+ - 🌐 **Decentralized Storage**: Built on GunDB for peer-to-peer data synchronization
18
15
  - 🔌 **Plugin System**: Extensible architecture with built-in plugins
19
-
20
- - 📱 **Reactive Programming**: RxJS integration for real-time data streams
21
16
  - 🛡️ **Security**: End-to-end encryption and secure key management
22
17
  - 🎯 **TypeScript**: Full TypeScript support with comprehensive type definitions
23
18
 
@@ -31,7 +26,7 @@ yarn add shogun-core
31
26
 
32
27
  ## Quick Start
33
28
 
34
- ### Using Gun (Default)
29
+ ### Basic Initialization
35
30
 
36
31
  ```typescript
37
32
  import { ShogunCore } from 'shogun-core';
@@ -61,40 +56,13 @@ const shogun = new ShogunCore({
61
56
  });
62
57
  ```
63
58
 
64
- ### Using Holster (Alternative)
65
-
66
- ```typescript
67
- import { ShogunCore } from 'shogun-core';
68
- import Holster from '@mblaney/holster';
69
-
70
- // Create Holster instance first
71
- const holster = Holster({
72
- peers: ['ws://localhost:8765'],
73
- });
74
-
75
- // Initialize Shogun Core with the Holster instance
76
- const shogun = new ShogunCore({
77
- holsterInstance: holster, // Use Holster instead of Gun
78
-
79
- // Enable authentication plugins (same as Gun)
80
- web3: { enabled: true },
81
- webauthn: {
82
- enabled: true,
83
- rpName: 'My Awesome App',
84
- rpId: window.location.hostname,
85
- },
86
- nostr: { enabled: true },
87
- });
88
59
 
89
- // All other APIs work the same way!
90
- ```
91
60
 
92
61
  ## Database API Reference
93
62
 
94
- The `shogun.db` instance provides a high-level API for interacting with the decentralized database. Shogun Core automatically handles the differences between **Gun** and **Holster** backends.
63
+ The `shogun.db` instance provides a high-level API for interacting with the decentralized database.
95
64
 
96
65
  ### 1. Connection & Session Management
97
- These methods work with both backends.
98
66
 
99
67
  - `db.isLoggedIn(): boolean`: Returns `true` if a user is currently authenticated.
100
68
  - `db.getCurrentUser(): { pub: string; user?: any } | null`: Returns the current user's public key and instance.
@@ -103,7 +71,7 @@ These methods work with both backends.
103
71
  - `db.restoreSession(): Promise<RestoreResult>`: Attempts to restore a previous session from `sessionStorage`.
104
72
 
105
73
  ### 2. Promise-based Advanced Utilities (Firegun API)
106
- *Note: These methods currently provide full Promise support and auto-retries primarily when using the **Gun** backend.*
74
+ *Note: These methods provide full Promise support and auto-retries.*
107
75
 
108
76
  ```typescript
109
77
  const db = shogun.db;
@@ -139,7 +107,7 @@ db.Off('myListener');
139
107
  db.Listen('public/status', (status) => console.log('Status:', status));
140
108
  ```
141
109
 
142
- ### 4. User-Space Operations (Gun Only)
110
+ ### 4. User-Space Operations
143
111
  These methods automatically prefix the path with `~pubkey/` of the logged-in user.
144
112
 
145
113
  - `db.userGet(path: string)`: Read from current user's graph.
@@ -148,7 +116,6 @@ These methods automatically prefix the path with `~pubkey/` of the logged-in use
148
116
  - `db.userLoad(path: string)`: Recursively load user-space data.
149
117
 
150
118
  ### 5. Advanced Features
151
- - **Reactive Streams**: `db.rx()` returns an RxJS helper for observable-based data handling.
152
119
  - **Content Addressing**: `db.addContentAdressing('#key', data)` hashes data using SHA-256 for immutable storage.
153
120
  - **Security**: `db.generatePublicCert()` creates a public certificate for P2P interactions.
154
121
  - **Cleanup**: `db.aggressiveAuthCleanup()` forcefully clears all local auth state.
@@ -164,7 +131,7 @@ Shogun Core provides a unified authentication interface. Plugins (Web3, WebAuthn
164
131
  await shogun.signUp('alice', 'Password123!');
165
132
  await shogun.login('alice', 'Password123!');
166
133
 
167
- // 2. Pair-based Authentication (Gun Only)
134
+ // 2. Pair-based Authentication
168
135
  const pair = await shogun.db.crypto.createPair();
169
136
  await shogun.loginWithPair('alice', pair);
170
137
 
@@ -346,41 +313,7 @@ console.log('Chat Pub:', chatPair.pub);
346
313
  </html>
347
314
  ```
348
315
 
349
- ### With Holster (ES Modules)
350
-
351
- ```html
352
- <!DOCTYPE html>
353
- <html>
354
- <head>
355
- <title>Shogun Core with Holster</title>
356
- </head>
357
- <body>
358
- <h1>My dApp</h1>
359
- <script type="module">
360
- import Holster from 'https://cdn.jsdelivr.net/npm/@mblaney/holster/build/holster.js';
361
- import { ShogunCore } from 'https://cdn.jsdelivr.net/npm/shogun-core/dist/src/index.js';
362
-
363
- // Create Holster instance
364
- const holster = Holster({
365
- peers: ['ws://localhost:8765'],
366
- });
367
-
368
- // Initialize Shogun Core
369
- const shogunCore = new ShogunCore({
370
- holsterInstance: holster,
371
- web3: { enabled: true },
372
- webauthn: {
373
- enabled: true,
374
- rpName: 'My Browser dApp',
375
- rpId: window.location.hostname,
376
- },
377
- });
378
316
 
379
- console.log('Shogun Core initialized with Holster!', shogunCore);
380
- </script>
381
- </body>
382
- </html>
383
- ```
384
317
 
385
318
  ## Event System
386
319
 
@@ -405,36 +338,13 @@ shogun.on('error', (error) => {
405
338
  });
406
339
  ```
407
340
 
408
- ## Database Backend: Gun vs Holster
409
-
410
- Shogun Core supports both Gun and Holster as database backends. Choose based on your needs:
411
-
412
- ### Gun (Default)
413
-
414
- - **Pros**: Maximum compatibility, large ecosystem, battle-tested
415
- - **Cons**: Older codebase, CommonJS modules
416
- - **Best for**: Existing projects, maximum compatibility
417
341
 
418
- ### Holster
419
-
420
- - **Pros**: Modern ES modules, improved performance, cleaner API
421
- - **Cons**: Newer project, smaller ecosystem
422
- - **Best for**: New projects, modern build systems, performance-critical apps
423
-
424
- **Note**: The API is identical regardless of which backend you choose. Shogun Core handles all the differences internally.
425
-
426
- ### Differences to be aware of:
427
-
428
- - **Pair-based authentication**: Currently only supported with Gun (username/password works with both)
429
- - **Event system**: Gun has native events, Holster uses polling (handled automatically)
430
- - **Chaining API**: Gun uses `.get().get()`, Holster uses `.get().next()` (handled automatically via proxy)
431
342
 
432
343
  ## Configuration Options
433
344
 
434
345
  ```typescript
435
346
  interface ShogunCoreConfig {
436
- gunInstance?: IGunInstance<any>; // Optional: existing Gun instance (required if holsterInstance not provided)
437
- holsterInstance?: any; // Optional: existing Holster instance (required if gunInstance not provided)
347
+ gunInstance?: IGunInstance<any>; // Optional: existing Gun instance
438
348
 
439
349
  // Plugin configurations
440
350
  webauthn?: {
@@ -471,45 +381,7 @@ interface ShogunCoreConfig {
471
381
  }
472
382
  ```
473
383
 
474
- **Note**:
475
-
476
- - Either `gunInstance` or `holsterInstance` must be provided (but not both)
477
-
478
- ## Migration Guide
479
-
480
- ### From Gun to Holster
481
-
482
- If you're currently using Gun and want to switch to Holster:
483
-
484
- 1. **Install Holster**:
485
-
486
- ```bash
487
- npm install @mblaney/holster
488
- # or
489
- yarn add @mblaney/holster
490
- ```
491
-
492
- 2. **Update your initialization**:
493
-
494
- ```typescript
495
- // Before (Gun)
496
- import Gun from "gun";
497
- const gun = Gun({ peers: [...] });
498
- const shogun = new ShogunCore({ gunInstance: gun });
499
-
500
- // After (Holster)
501
- import Holster from "@mblaney/holster";
502
- const holster = Holster({ peers: [...] });
503
- const shogun = new ShogunCore({ holsterInstance: holster });
504
- ```
505
-
506
- 3. **That's it!** All other code remains the same. The API is identical.
507
-
508
- ### Limitations when using Holster
509
384
 
510
- - Pair-based authentication (`loginWithPair()`) is not yet supported - use username/password instead
511
- - Some advanced Gun features may not be available
512
- - Event system uses polling instead of native events (handled automatically)
513
385
 
514
386
  ## Testing
515
387