shogun-core 1.4.3 → 1.5.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 (57) hide show
  1. package/README.md +110 -108
  2. package/dist/browser/shogun-core.js +2 -1
  3. package/dist/browser/shogun-core.js.LICENSE.txt +4 -0
  4. package/dist/browser/shogun-core.js.map +1 -0
  5. package/dist/gundb/gunInstance.js +311 -293
  6. package/dist/index.js +47 -49
  7. package/dist/plugins/base.js +4 -1
  8. package/dist/plugins/index.js +1 -12
  9. package/dist/plugins/nostr/index.js +0 -6
  10. package/dist/plugins/nostr/nostrConnector.js +106 -382
  11. package/dist/plugins/nostr/nostrConnectorPlugin.js +46 -35
  12. package/dist/plugins/nostr/nostrSigner.js +3 -18
  13. package/dist/plugins/oauth/index.js +1 -6
  14. package/dist/plugins/oauth/oauthConnector.js +126 -92
  15. package/dist/plugins/oauth/oauthPlugin.js +35 -21
  16. package/dist/plugins/web3/index.js +0 -6
  17. package/dist/plugins/web3/web3Connector.js +17 -9
  18. package/dist/plugins/web3/web3ConnectorPlugin.js +14 -39
  19. package/dist/plugins/webauthn/index.js +0 -6
  20. package/dist/plugins/webauthn/webauthn.js +39 -5
  21. package/dist/plugins/webauthn/webauthnPlugin.js +12 -26
  22. package/dist/types/gundb/derive.d.ts +16 -1
  23. package/dist/types/gundb/gunInstance.d.ts +18 -14
  24. package/dist/types/index.d.ts +10 -13
  25. package/dist/types/plugins/base.d.ts +3 -1
  26. package/dist/types/plugins/index.d.ts +0 -4
  27. package/dist/types/plugins/nostr/index.d.ts +0 -1
  28. package/dist/types/plugins/nostr/nostrConnector.d.ts +45 -33
  29. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +1 -1
  30. package/dist/types/plugins/nostr/types.d.ts +3 -3
  31. package/dist/types/plugins/oauth/index.d.ts +0 -1
  32. package/dist/types/plugins/oauth/oauthConnector.d.ts +10 -11
  33. package/dist/types/plugins/oauth/oauthPlugin.d.ts +4 -3
  34. package/dist/types/plugins/oauth/types.d.ts +6 -1
  35. package/dist/types/plugins/web3/index.d.ts +0 -1
  36. package/dist/types/plugins/web3/types.d.ts +2 -2
  37. package/dist/types/plugins/web3/web3Connector.d.ts +3 -2
  38. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +3 -2
  39. package/dist/types/plugins/webauthn/index.d.ts +0 -1
  40. package/dist/types/plugins/webauthn/types.d.ts +8 -0
  41. package/dist/types/plugins/webauthn/webauthn.d.ts +25 -2
  42. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +3 -2
  43. package/dist/types/types/plugin.d.ts +1 -1
  44. package/dist/types/types/shogun.d.ts +3 -0
  45. package/dist/types/utils/validation.d.ts +27 -0
  46. package/dist/utils/validation.js +72 -0
  47. package/package.json +9 -5
  48. package/dist/browser/shogun-core.light.js +0 -1
  49. package/dist/browser/shogun-core.vendors.light.js +0 -1
  50. package/dist/plugins/nostr/nostrChain.js +0 -173
  51. package/dist/plugins/oauth/oauthChain.js +0 -161
  52. package/dist/plugins/web3/web3Chain.js +0 -108
  53. package/dist/plugins/webauthn/webauthnChain.js +0 -114
  54. package/dist/types/plugins/nostr/nostrChain.d.ts +0 -2
  55. package/dist/types/plugins/oauth/oauthChain.d.ts +0 -2
  56. package/dist/types/plugins/web3/web3Chain.d.ts +0 -2
  57. package/dist/types/plugins/webauthn/webauthnChain.d.ts +0 -2
package/README.md CHANGED
@@ -8,22 +8,6 @@
8
8
 
9
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 peer-to-peer networking with modern authentication standards and blockchain integration to provide a secure, user-friendly foundation for Web3 applications.
10
10
 
11
- ## Key Features
12
-
13
- - **[Multi-Method Authentication](wiki/core.md#authentication)**: Support for traditional passwords, WebAuthn biometrics, Ethereum wallets, and Nostr/Bitcoin protocols
14
- - **[Decentralized Storage](wiki/gundb.md)**: Built on GunDB with offline resilience, real-time sync, and peer-to-peer networking
15
- - **[Reactive Data Flows](wiki/gundb.md#reactive-programming-with-rxjs)**: RxJS integration for building responsive, real-time user interfaces
16
- - **[Enterprise Security](wiki/core.md#security)**: End-to-end encryption, secure key management, and modern cryptographic standards
17
- - **[Plugin Architecture](wiki/core.md#plugin-system)**: Extensible system for adding custom authentication methods and functionality
18
-
19
- ## Core Components
20
-
21
- - **[Core SDK](wiki/core.md)**: Main SDK entry point, configuration, and plugin management
22
- - **[GunDB Integration](wiki/gundb.md)**: Enhanced wrapper around GunDB with direct authentication and RxJS support
23
- - **[WebAuthn Plugin](wiki/webauthn.md)**: Passwordless authentication with biometrics and security keys
24
- - **[Web3 Plugin](wiki/web3.md)**: Ethereum wallet integration and blockchain authentication
25
- - **[Nostr Plugin](wiki/nostr.md)**: Bitcoin and Nostr protocol integration for decentralized identity
26
-
27
11
  ## Installation
28
12
 
29
13
  ```bash
@@ -34,113 +18,131 @@ yarn add shogun-core
34
18
 
35
19
  ## Quick Start
36
20
 
21
+ This example demonstrates how to initialize `ShogunCore` in a Node.js or browser project using a bundler like Webpack or Vite.
22
+
37
23
  ```typescript
38
24
  import { ShogunCore } from "shogun-core";
39
25
 
40
- // Initialize Shogun Core
26
+ // Define your list of Gun peers
27
+ const relays = [
28
+ "wss://ruling-mastodon-improved.ngrok-free.app/gun",
29
+ "https://gun-manhattan.herokuapp.com/gun",
30
+ "https://peer.wallie.io/gun",
31
+ ];
32
+
33
+ // Initialize Shogun Core with plugins
41
34
  const shogun = new ShogunCore({
42
- peers: ["https://your-gun-peer.com/gun"],
43
- scope: "my-app",
44
-
45
- // Configure logging
35
+ peers: relays,
36
+ scope: "my-awesome-app",
37
+ authToken: "YOUR_GUN_SUPER_PEER_SECRET", // Optional, for private peers
38
+
39
+ // Enable and configure logging
46
40
  logging: {
47
41
  enabled: true,
48
- level: "info"
49
- }
50
- });
51
-
52
- // Basic authentication
53
- const loginResult = await shogun.login("username", "password");
54
- if (loginResult.success) {
55
- console.log("User logged in:", loginResult.userPub);
56
- }
57
-
58
- // Access built-in plugins
59
- const webauthnPlugin = shogun.getPlugin("webauthn");
60
- const web3Plugin = shogun.getPlugin("web3");
61
- const nostrPlugin = shogun.getPlugin("nostr");
62
-
63
- // Work with decentralized data
64
- const gundb = shogun.gundb;
65
- await gundb.put("user/profile", { name: "John Doe", status: "online" });
66
- const profile = await gundb.get("user/profile");
67
-
68
- // Reactive data with RxJS
69
- shogun.observe("user/profile").subscribe(profile => {
70
- console.log("Profile updated:", profile);
71
- });
72
- ```
73
-
74
- ## Advanced Usage
42
+ level: "info", // "none", "error", "warn", "info", "debug", "verbose"
43
+ },
75
44
 
76
- ### Event Handling
45
+ // Enable and configure Web3 (e.g., MetaMask) authentication
46
+ web3: {
47
+ enabled: true
48
+ },
77
49
 
78
- ```typescript
79
- // Listen for authentication events
80
- shogun.on("auth:login", (data) => {
81
- console.log("User logged in:", data.userPub);
82
- });
50
+ // Enable and configure WebAuthn (biometrics, security keys)
51
+ webauthn: {
52
+ enabled: true,
53
+ rpName: "My Awesome App", // Name of your application
54
+ },
83
55
 
84
- shogun.on("auth:logout", () => {
85
- console.log("User logged out");
86
- });
56
+ // Enable and configure Nostr
57
+ nostr: {
58
+ enabled: true
59
+ },
87
60
 
88
- shogun.on("error", (error) => {
89
- console.error("SDK error:", error);
61
+ // Enable and configure OAuth providers
62
+ oauth: {
63
+ enabled: true,
64
+ usePKCE: true, // Recommended for SPAs
65
+ providers: {
66
+ google: {
67
+ clientId: "YOUR_GOOGLE_CLIENT_ID",
68
+ clientSecret: "YOUR_GOOGLE_CLIENT_SECRET", // For server-side flow
69
+ redirectUri: "http://localhost:3000/auth/callback",
70
+ scope: ["openid", "email", "profile"],
71
+ },
72
+ },
73
+ },
90
74
  });
91
- ```
92
-
93
- ## Documentation
94
-
95
- For detailed documentation on each component:
96
-
97
- ### Core Documentation
98
- - **[Core SDK API](wiki/core.md)** - Main SDK initialization, configuration, and authentication
99
- - **[GunDB Integration](wiki/gundb.md)** - Decentralized database operations and reactive data
100
-
101
- ### Plugin Documentation
102
- - **[WebAuthn Plugin](wiki/webauthn.md)** - Biometric and security key authentication
103
- - **[Web3 Plugin](wiki/web3.md)** - Ethereum wallet integration
104
- - **[Nostr Plugin](wiki/nostr.md)** - Bitcoin and Nostr protocol support
105
-
106
- ### Technical Documentation
107
- Full API documentation is available in the `/docs` directory after building.
108
-
109
- ## Use Cases
110
-
111
- Shogun Core is ideal for building:
112
-
113
- - **Decentralized Social Networks**: Chat apps, forums, and social platforms with user-owned data
114
- - **Web3 Wallets**: Browser-based cryptocurrency wallets with multiple authentication options
115
- - **Enterprise dApps**: Business applications requiring secure, decentralized data storage
116
- - **Gaming Platforms**: Real-time multiplayer games with decentralized leaderboards and assets
117
- - **Privacy-Focused Applications**: Apps requiring anonymous interactions and privacy features
118
- - **Collaborative Tools**: Real-time document editing, project management, and team coordination
119
75
 
120
- ## Browser Compatibility
121
-
122
- Shogun Core supports all modern browsers with:
123
- - WebAuthn API support (Chrome 67+, Firefox 60+, Safari 14+)
124
- - WebCrypto API support
125
- - IndexedDB support
126
- - WebSocket support for real-time synchronization
127
-
128
- ## Node.js Support
129
-
130
- Full Node.js support for server-side applications, testing, and automation.
76
+ // Basic authentication
77
+ const loginResult = await shogun.login("username", "password");
131
78
 
132
- ## Contributing
79
+ console.log("Shogun Core initialized!");
133
80
 
134
- We welcome contributions! Please follow our contribution guidelines:
81
+ // You can now use the instance to interact with plugins and data
82
+ // For example, to initiate a Web3 login:
83
+ // const web3Plugin = shogun.getPlugin("web3");
84
+ // if (web3Plugin) {
85
+ // const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
86
+ // await web3Plugin.login(accounts[0]);
87
+ // }
88
+ ```
135
89
 
136
- 1. Fork the repository
137
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
138
- 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
139
- 4. Push to the branch (`git push origin feature/amazing-feature`)
140
- 5. Open a Pull Request
90
+ ### Browser Usage (via CDN)
91
+
92
+ You can also use Shogun Core directly in the browser by including it from a CDN. This is ideal for static sites or lightweight applications.
93
+
94
+ ```html
95
+ <!DOCTYPE html>
96
+ <html>
97
+ <head>
98
+ <title>Shogun Core in Browser</title>
99
+ </head>
100
+ <body>
101
+ <h1>My dApp</h1>
102
+ <!-- Required dependencies for Shogun Core -->
103
+ <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
104
+ <script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
105
+
106
+ <!-- Shogun Core library -->
107
+ <script src="https://cdn.jsdelivr.net/npm/shogun-core/dist/browser/shogun-core.js"></script>
108
+
109
+ <script>
110
+ // The script exposes a global `initShogun` function
111
+ const shogun = initShogun({
112
+ peers: ['https://gun-manhattan.herokuapp.com/gun'],
113
+ scope: 'my-browser-app',
114
+ web3: { enabled: true },
115
+ webauthn: {
116
+ enabled: true,
117
+ rpName: 'My Browser dApp',
118
+ rpId: window.location.hostname,
119
+ }
120
+ });
121
+
122
+ console.log('Shogun Core initialized in browser!', shogun);
123
+
124
+ async function connectWallet() {
125
+ if (shogun.hasPlugin('web3')) {
126
+ const web3Plugin = shogun.getPlugin('web3');
127
+ try {
128
+ const provider = await web3Plugin.getProvider();
129
+ const signer = provider.getSigner();
130
+ const address = await signer.getAddress();
131
+ await web3Plugin.login(address);
132
+ console.log('Logged in with address:', address);
133
+ } catch (error) {
134
+ console.error('Web3 login failed:', error);
135
+ }
136
+ }
137
+ }
138
+ </script>
139
+ </body>
140
+ </html>
141
+ ```
141
142
 
142
- Please follow [Conventional Commits](https://conventionalcommits.org/) for commit messages.
143
+ ## Advanced Usage
143
144
 
144
- ## License
145
+ ### Event Handling
145
146
 
146
- MIT License - see [LICENSE](LICENSE) file for details.
147
+ ```
148
+ ```