shogun-core 1.6.14 → 1.6.16
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/README.md +85 -49
- package/dist/browser/shogun-core.js +1217 -908
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/gundb/derive.js +1 -1
- package/dist/gundb/gun-Instance.js +1038 -706
- package/dist/index.js +113 -167
- package/dist/plugins/nostr/nostrConnectorPlugin.js +3 -4
- package/dist/plugins/oauth/oauthConnector.js +16 -16
- package/dist/plugins/oauth/oauthPlugin.js +5 -8
- package/dist/plugins/web3/web3ConnectorPlugin.js +3 -4
- package/dist/plugins/webauthn/webauthnPlugin.js +1 -1
- package/dist/types/gundb/gun-Instance.d.ts +102 -17
- package/dist/types/index.d.ts +24 -14
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +5 -6
- package/dist/types/plugins/nostr/types.d.ts +5 -5
- package/dist/types/plugins/oauth/oauthConnector.d.ts +2 -2
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +5 -8
- package/dist/types/plugins/oauth/types.d.ts +5 -3
- package/dist/types/plugins/web3/types.d.ts +5 -5
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +5 -6
- package/dist/types/plugins/webauthn/types.d.ts +2 -2
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +3 -3
- package/dist/types/types/shogun.d.ts +20 -0
- package/dist/types/utils/errorHandler.d.ts +4 -0
- package/dist/utils/errorHandler.js +39 -4
- package/package.json +1 -1
- package/dist/base.js +0 -1
- package/dist/types/base.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Shogun Core 📦
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/shogun-core)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
|
|
@@ -18,6 +18,15 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
|
|
|
18
18
|
- 🎯 **TypeScript**: Full TypeScript support with comprehensive type definitions
|
|
19
19
|
- 📡 **Event System**: Typed event system for monitoring authentication and data changes
|
|
20
20
|
- 🔑 **Cryptographic Wallets**: Automatic derivation of Bitcoin and Ethereum wallets from user keys
|
|
21
|
+
- ✅ **Type Consistency**: Unified return types across all authentication methods
|
|
22
|
+
|
|
23
|
+
## Recent Updates (v1.6.15)
|
|
24
|
+
|
|
25
|
+
### ✅ **Type System Fixes**
|
|
26
|
+
- **Unified Return Types**: All authentication methods now use consistent `AuthResult` and `SignUpResult` types
|
|
27
|
+
- **Enhanced SignUpResult**: Extended to support OAuth redirects and provider-specific data
|
|
28
|
+
- **Type Safety**: Fixed TypeScript inconsistencies across all plugins
|
|
29
|
+
- **API Standardization**: All plugins implement unified `login()` and `signUp()` interfaces
|
|
21
30
|
|
|
22
31
|
## Installation
|
|
23
32
|
|
|
@@ -87,12 +96,12 @@ console.log("Shogun Core initialized!");
|
|
|
87
96
|
|
|
88
97
|
## Plugin Authentication APIs
|
|
89
98
|
|
|
90
|
-
Shogun Core provides a unified plugin system for different authentication methods. Each plugin implements standardized `login()` and `signUp()` methods that return consistent `AuthResult` objects.
|
|
99
|
+
Shogun Core provides a unified plugin system for different authentication methods. Each plugin implements standardized `login()` and `signUp()` methods that return consistent `AuthResult` and `SignUpResult` objects.
|
|
91
100
|
|
|
92
|
-
### Core Types
|
|
101
|
+
### Core Types - ✅ **FIXED & UNIFIED**
|
|
93
102
|
|
|
94
103
|
```typescript
|
|
95
|
-
// Authentication result interface
|
|
104
|
+
// Authentication result interface - used by login methods
|
|
96
105
|
interface AuthResult {
|
|
97
106
|
success: boolean;
|
|
98
107
|
error?: string;
|
|
@@ -129,6 +138,26 @@ interface AuthResult {
|
|
|
129
138
|
};
|
|
130
139
|
}
|
|
131
140
|
|
|
141
|
+
// Sign up result interface - used by signUp methods ✅ ENHANCED
|
|
142
|
+
interface SignUpResult {
|
|
143
|
+
success: boolean;
|
|
144
|
+
userPub?: string;
|
|
145
|
+
username?: string;
|
|
146
|
+
pub?: string;
|
|
147
|
+
error?: string;
|
|
148
|
+
message?: string;
|
|
149
|
+
wallet?: any;
|
|
150
|
+
isNewUser?: boolean;
|
|
151
|
+
authMethod?: AuthMethod; // ✅ ADDED
|
|
152
|
+
sessionToken?: string; // ✅ ADDED
|
|
153
|
+
sea?: SEAPair; // SEA pair for session persistence
|
|
154
|
+
// OAuth flow support - ✅ ADDED
|
|
155
|
+
redirectUrl?: string;
|
|
156
|
+
pendingAuth?: boolean;
|
|
157
|
+
provider?: string;
|
|
158
|
+
user?: OAuthUserInfo; // ✅ ADDED
|
|
159
|
+
}
|
|
160
|
+
|
|
132
161
|
// Supported authentication methods
|
|
133
162
|
type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "oauth" | "bitcoin" | "pair";
|
|
134
163
|
```
|
|
@@ -138,16 +167,19 @@ type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "oauth" | "bitcoi
|
|
|
138
167
|
Direct username/password authentication using ShogunCore methods:
|
|
139
168
|
|
|
140
169
|
```typescript
|
|
141
|
-
// Sign up a new user
|
|
142
|
-
const signUpResult = await shogun.signUp("username", "password");
|
|
170
|
+
// Sign up a new user - Returns SignUpResult ✅
|
|
171
|
+
const signUpResult: SignUpResult = await shogun.signUp("username", "password");
|
|
143
172
|
if (signUpResult.success) {
|
|
144
173
|
console.log("User created:", signUpResult.username);
|
|
174
|
+
console.log("Is new user:", signUpResult.isNewUser);
|
|
175
|
+
console.log("Auth method:", signUpResult.authMethod);
|
|
145
176
|
}
|
|
146
177
|
|
|
147
|
-
// Login with username and password
|
|
148
|
-
const loginResult = await shogun.login("username", "password");
|
|
178
|
+
// Login with username and password - Returns AuthResult ✅
|
|
179
|
+
const loginResult: AuthResult = await shogun.login("username", "password");
|
|
149
180
|
if (loginResult.success) {
|
|
150
181
|
console.log("Logged in as:", loginResult.username);
|
|
182
|
+
console.log("User public key:", loginResult.userPub);
|
|
151
183
|
}
|
|
152
184
|
```
|
|
153
185
|
|
|
@@ -165,33 +197,34 @@ if (web3Plugin && web3Plugin.isAvailable()) {
|
|
|
165
197
|
if (connectionResult.success) {
|
|
166
198
|
const address = connectionResult.address!;
|
|
167
199
|
|
|
168
|
-
// Login with Web3 wallet
|
|
169
|
-
const loginResult = await web3Plugin.login(address);
|
|
200
|
+
// Login with Web3 wallet - Returns AuthResult ✅
|
|
201
|
+
const loginResult: AuthResult = await web3Plugin.login(address);
|
|
170
202
|
if (loginResult.success) {
|
|
171
203
|
console.log("Web3 login successful");
|
|
172
204
|
console.log("User public key:", loginResult.userPub);
|
|
173
205
|
}
|
|
174
206
|
|
|
175
|
-
// Register new user with Web3 wallet
|
|
176
|
-
const signUpResult = await web3Plugin.signUp(address);
|
|
207
|
+
// Register new user with Web3 wallet - Returns SignUpResult ✅
|
|
208
|
+
const signUpResult: SignUpResult = await web3Plugin.signUp(address);
|
|
177
209
|
if (signUpResult.success) {
|
|
178
210
|
console.log("Web3 registration successful");
|
|
211
|
+
console.log("Is new user:", signUpResult.isNewUser);
|
|
179
212
|
}
|
|
180
213
|
}
|
|
181
214
|
}
|
|
182
215
|
|
|
183
|
-
// Plugin Interface
|
|
216
|
+
// Plugin Interface - ✅ FIXED TYPES
|
|
184
217
|
interface Web3ConnectorPluginInterface {
|
|
185
218
|
// Authentication methods
|
|
186
|
-
login(address: string): Promise<AuthResult>;
|
|
187
|
-
signUp(address: string): Promise<
|
|
188
|
-
|
|
219
|
+
login(address: string): Promise<AuthResult>; // ✅ CORRECT
|
|
220
|
+
signUp(address: string): Promise<SignUpResult>; // ✅ FIXED
|
|
221
|
+
|
|
189
222
|
// Connection methods
|
|
190
223
|
isAvailable(): boolean;
|
|
191
224
|
connectMetaMask(): Promise<ConnectionResult>;
|
|
192
225
|
getProvider(): Promise<ethers.JsonRpcProvider | ethers.BrowserProvider>;
|
|
193
226
|
getSigner(): Promise<ethers.Signer>;
|
|
194
|
-
|
|
227
|
+
|
|
195
228
|
// Credential management
|
|
196
229
|
generateCredentials(address: string): Promise<ISEAPair>;
|
|
197
230
|
generatePassword(signature: string): Promise<string>;
|
|
@@ -207,28 +240,30 @@ Biometric and hardware key authentication:
|
|
|
207
240
|
const webauthnPlugin = shogun.getPlugin<WebauthnPlugin>("webauthn");
|
|
208
241
|
|
|
209
242
|
if (webauthnPlugin && webauthnPlugin.isSupported()) {
|
|
210
|
-
// Register new user with WebAuthn
|
|
211
|
-
const signUpResult = await webauthnPlugin.signUp("username");
|
|
243
|
+
// Register new user with WebAuthn - Returns SignUpResult ✅
|
|
244
|
+
const signUpResult: SignUpResult = await webauthnPlugin.signUp("username");
|
|
212
245
|
if (signUpResult.success) {
|
|
213
246
|
console.log("WebAuthn registration successful");
|
|
247
|
+
console.log("User public key:", signUpResult.userPub);
|
|
214
248
|
}
|
|
215
249
|
|
|
216
|
-
// Authenticate existing user
|
|
217
|
-
const loginResult = await webauthnPlugin.login("username");
|
|
250
|
+
// Authenticate existing user - Returns AuthResult ✅
|
|
251
|
+
const loginResult: AuthResult = await webauthnPlugin.login("username");
|
|
218
252
|
if (loginResult.success) {
|
|
219
253
|
console.log("WebAuthn authentication successful");
|
|
254
|
+
console.log("Auth method:", loginResult.authMethod); // "webauthn"
|
|
220
255
|
}
|
|
221
256
|
}
|
|
222
257
|
|
|
223
|
-
// Plugin Interface
|
|
258
|
+
// Plugin Interface - ✅ FIXED TYPES
|
|
224
259
|
interface WebauthnPluginInterface {
|
|
225
260
|
// Authentication methods
|
|
226
|
-
login(username: string): Promise<AuthResult>;
|
|
227
|
-
signUp(username: string): Promise<
|
|
228
|
-
|
|
261
|
+
login(username: string): Promise<AuthResult>; // ✅ CORRECT
|
|
262
|
+
signUp(username: string): Promise<SignUpResult>; // ✅ FIXED
|
|
263
|
+
|
|
229
264
|
// Capability checks
|
|
230
265
|
isSupported(): boolean;
|
|
231
|
-
|
|
266
|
+
|
|
232
267
|
// WebAuthn-specific methods
|
|
233
268
|
register(username: string, displayName?: string): Promise<WebAuthnCredential>;
|
|
234
269
|
authenticate(username?: string): Promise<WebAuthnCredential>;
|
|
@@ -250,31 +285,33 @@ if (nostrPlugin && nostrPlugin.isAvailable()) {
|
|
|
250
285
|
if (connectionResult.success) {
|
|
251
286
|
const address = connectionResult.address!;
|
|
252
287
|
|
|
253
|
-
// Login with Nostr/Bitcoin wallet
|
|
254
|
-
const loginResult = await nostrPlugin.login(address);
|
|
288
|
+
// Login with Nostr/Bitcoin wallet - Returns AuthResult ✅
|
|
289
|
+
const loginResult: AuthResult = await nostrPlugin.login(address);
|
|
255
290
|
if (loginResult.success) {
|
|
256
291
|
console.log("Nostr login successful");
|
|
292
|
+
console.log("Auth method:", loginResult.authMethod); // "nostr"
|
|
257
293
|
}
|
|
258
294
|
|
|
259
|
-
// Register with Nostr/Bitcoin wallet
|
|
260
|
-
const signUpResult = await nostrPlugin.signUp(address);
|
|
295
|
+
// Register with Nostr/Bitcoin wallet - Returns SignUpResult ✅
|
|
296
|
+
const signUpResult: SignUpResult = await nostrPlugin.signUp(address);
|
|
261
297
|
if (signUpResult.success) {
|
|
262
298
|
console.log("Nostr registration successful");
|
|
299
|
+
console.log("Is new user:", signUpResult.isNewUser);
|
|
263
300
|
}
|
|
264
301
|
}
|
|
265
302
|
}
|
|
266
303
|
|
|
267
|
-
// Plugin Interface
|
|
304
|
+
// Plugin Interface - ✅ FIXED TYPES
|
|
268
305
|
interface NostrConnectorPluginInterface {
|
|
269
306
|
// Authentication methods
|
|
270
|
-
login(address: string): Promise<AuthResult>;
|
|
271
|
-
signUp(address: string): Promise<
|
|
272
|
-
|
|
307
|
+
login(address: string): Promise<AuthResult>; // ✅ CORRECT
|
|
308
|
+
signUp(address: string): Promise<SignUpResult>; // ✅ FIXED
|
|
309
|
+
|
|
273
310
|
// Connection methods
|
|
274
311
|
isAvailable(): boolean;
|
|
275
312
|
connectBitcoinWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
276
313
|
connectNostrWallet(): Promise<ConnectionResult>;
|
|
277
|
-
|
|
314
|
+
|
|
278
315
|
// Credential and signature management
|
|
279
316
|
generateCredentials(address: string, signature: string, message: string): Promise<NostrConnectorCredentials>;
|
|
280
317
|
verifySignature(message: string, signature: string, address: string): Promise<boolean>;
|
|
@@ -293,15 +330,15 @@ if (oauthPlugin && oauthPlugin.isSupported()) {
|
|
|
293
330
|
// Get available providers
|
|
294
331
|
const providers = oauthPlugin.getAvailableProviders(); // ["google", "github", ...]
|
|
295
332
|
|
|
296
|
-
// Initiate
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
333
|
+
// Initiate signup with OAuth - Returns SignUpResult with redirect ✅
|
|
334
|
+
const signUpResult: SignUpResult = await oauthPlugin.signUp("google");
|
|
335
|
+
if (signUpResult.success && signUpResult.redirectUrl) {
|
|
299
336
|
// Redirect user to OAuth provider
|
|
300
|
-
window.location.href =
|
|
337
|
+
window.location.href = signUpResult.redirectUrl;
|
|
301
338
|
}
|
|
302
339
|
|
|
303
|
-
// Handle OAuth callback (after redirect back from provider)
|
|
304
|
-
const callbackResult = await oauthPlugin.handleOAuthCallback(
|
|
340
|
+
// Handle OAuth callback (after redirect back from provider) - Returns AuthResult ✅
|
|
341
|
+
const callbackResult: AuthResult = await oauthPlugin.handleOAuthCallback(
|
|
305
342
|
"google",
|
|
306
343
|
authCode, // From URL params
|
|
307
344
|
state // From URL params
|
|
@@ -316,19 +353,19 @@ if (oauthPlugin && oauthPlugin.isSupported()) {
|
|
|
316
353
|
}
|
|
317
354
|
}
|
|
318
355
|
|
|
319
|
-
// Plugin Interface
|
|
356
|
+
// Plugin Interface - ✅ FIXED TYPES
|
|
320
357
|
interface OAuthPluginInterface {
|
|
321
358
|
// Authentication methods
|
|
322
|
-
login(provider: OAuthProvider): Promise<AuthResult>;
|
|
323
|
-
signUp(provider: OAuthProvider): Promise<
|
|
324
|
-
|
|
359
|
+
login(provider: OAuthProvider): Promise<AuthResult>; // ✅ CORRECT
|
|
360
|
+
signUp(provider: OAuthProvider): Promise<SignUpResult>; // ✅ FIXED
|
|
361
|
+
|
|
325
362
|
// OAuth flow management
|
|
326
363
|
isSupported(): boolean;
|
|
327
364
|
getAvailableProviders(): OAuthProvider[];
|
|
328
365
|
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
329
366
|
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
330
367
|
handleOAuthCallback(provider: OAuthProvider, authCode: string, state: string): Promise<AuthResult>;
|
|
331
|
-
|
|
368
|
+
|
|
332
369
|
// Credential management
|
|
333
370
|
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
|
|
334
371
|
}
|
|
@@ -559,7 +596,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
559
596
|
|
|
560
597
|
## Support
|
|
561
598
|
|
|
562
|
-
- 📖 [Documentation](https://docs.
|
|
563
|
-
- 💬 [
|
|
599
|
+
- 📖 [Documentation](https://shogun-core-docs.vercel.app/)
|
|
600
|
+
- 💬 [Telegram Community](t.me/shogun_eco)
|
|
564
601
|
- 🐛 [Issue Tracker](https://github.com/scobru/shogun-core/issues)
|
|
565
|
-
- 📧 [Email Support](mailto:support@shogun.dev)
|