shogun-button-react 6.1.0 → 6.2.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.
@@ -1,9 +1,9 @@
1
1
  import React from "react";
2
- import { ShogunCore, QuickStart } from "shogun-core";
2
+ import { ShogunCore } from "shogun-core";
3
3
  import { Observable } from "rxjs";
4
4
  import "../styles/index.css";
5
5
  type ShogunContextType = {
6
- core: ShogunCore | QuickStart | null;
6
+ core: ShogunCore | null;
7
7
  options: any;
8
8
  isLoggedIn: boolean;
9
9
  userPub: string | null;
@@ -25,7 +25,7 @@ type ShogunContextType = {
25
25
  export declare const useShogun: () => ShogunContextType;
26
26
  type ShogunButtonProviderProps = {
27
27
  children: React.ReactNode;
28
- core: ShogunCore | QuickStart;
28
+ core: ShogunCore;
29
29
  options: any;
30
30
  onLoginSuccess?: (data: {
31
31
  userPub: string;
@@ -5,10 +5,6 @@ import "../styles/index.css";
5
5
  function isShogunCore(core) {
6
6
  return core && typeof core.isLoggedIn === 'function' && typeof core.gun !== 'undefined';
7
7
  }
8
- // Helper type to check if core is QuickStart
9
- function isQuickStart(core) {
10
- return core && typeof core.api !== 'undefined' && typeof core.database !== 'undefined';
11
- }
12
8
  // Default context
13
9
  const defaultShogunContext = {
14
10
  core: null,
@@ -54,16 +50,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
54
50
  pub = (_b = (_a = core.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub;
55
51
  }
56
52
  }
57
- else if (isQuickStart(core)) {
58
- // QuickStart doesn't have built-in login state, so we check sessionStorage
59
- const pair = sessionStorage.getItem("gun/pair") || sessionStorage.getItem("pair");
60
- isLoggedIn = !!pair;
61
- if (isLoggedIn) {
62
- // Try to get user info from the database
63
- const userData = core.database.getCurrentUser();
64
- pub = (userData === null || userData === void 0 ? void 0 : userData.pub) || null;
65
- }
66
- }
67
53
  if (isLoggedIn && pub) {
68
54
  setIsLoggedIn(true);
69
55
  setUserPub(pub);
@@ -102,10 +88,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
102
88
  if (isShogunCore(core)) {
103
89
  result = await core.login(args[0], args[1]);
104
90
  }
105
- else if (isQuickStart(core)) {
106
- // Use QuickStart database directly
107
- result = await core.database.login(args[0], args[1]);
108
- }
109
91
  else {
110
92
  throw new Error("Unsupported core type");
111
93
  }
@@ -136,7 +118,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
136
118
  });
137
119
  }
138
120
  else {
139
- throw new Error("Pair authentication not supported with QuickStart");
121
+ throw new Error("Pair authentication requires ShogunCore");
140
122
  }
141
123
  username = result.alias;
142
124
  authMethod = "pair";
@@ -150,7 +132,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
150
132
  result = await webauthn.login(username);
151
133
  }
152
134
  else {
153
- throw new Error("WebAuthn not supported with QuickStart");
135
+ throw new Error("WebAuthn requires ShogunCore");
154
136
  }
155
137
  break;
156
138
  case "web3":
@@ -166,7 +148,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
166
148
  result = await web3.login(connectionResult.address);
167
149
  }
168
150
  else {
169
- throw new Error("Web3 not supported with QuickStart");
151
+ throw new Error("Web3 requires ShogunCore");
170
152
  }
171
153
  break;
172
154
  case "nostr":
@@ -185,7 +167,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
185
167
  result = await nostr.login(pubkey);
186
168
  }
187
169
  else {
188
- throw new Error("Nostr not supported with QuickStart");
170
+ throw new Error("Nostr requires ShogunCore");
189
171
  }
190
172
  break;
191
173
  case "zkproof":
@@ -203,7 +185,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
203
185
  authMethod = "zkproof";
204
186
  }
205
187
  else {
206
- throw new Error("ZK-Proof not supported with QuickStart");
188
+ throw new Error("ZK-Proof requires ShogunCore");
207
189
  }
208
190
  break;
209
191
  default:
@@ -257,9 +239,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
257
239
  if (isShogunCore(core)) {
258
240
  result = await core.signUp(args[0], args[1]);
259
241
  }
260
- else if (isQuickStart(core)) {
261
- result = await core.database.signUp(args[0], args[1]);
262
- }
263
242
  else {
264
243
  throw new Error("Unsupported core type");
265
244
  }
@@ -280,7 +259,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
280
259
  result = await webauthn.signUp(username, { generateSeedPhrase: true });
281
260
  }
282
261
  else {
283
- throw new Error("WebAuthn not supported with QuickStart");
262
+ throw new Error("WebAuthn requires ShogunCore");
284
263
  }
285
264
  break;
286
265
  case "web3":
@@ -296,7 +275,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
296
275
  result = await web3.signUp(connectionResult.address);
297
276
  }
298
277
  else {
299
- throw new Error("Web3 not supported with QuickStart");
278
+ throw new Error("Web3 requires ShogunCore");
300
279
  }
301
280
  break;
302
281
  case "nostr":
@@ -315,7 +294,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
315
294
  result = await nostr.signUp(pubkey);
316
295
  }
317
296
  else {
318
- throw new Error("Nostr not supported with QuickStart");
297
+ throw new Error("Nostr requires ShogunCore");
319
298
  }
320
299
  break;
321
300
  case "zkproof":
@@ -330,7 +309,7 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
330
309
  authMethod = "zkproof";
331
310
  }
332
311
  else {
333
- throw new Error("ZK-Proof not supported with QuickStart");
312
+ throw new Error("ZK-Proof requires ShogunCore");
334
313
  }
335
314
  break;
336
315
  default:
@@ -367,12 +346,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
367
346
  if (isShogunCore(core)) {
368
347
  core.logout();
369
348
  }
370
- else if (isQuickStart(core)) {
371
- // QuickStart doesn't have built-in logout, so we clear session storage
372
- sessionStorage.removeItem("gun/pair");
373
- sessionStorage.removeItem("gun/session");
374
- sessionStorage.removeItem("pair");
375
- }
376
349
  setIsLoggedIn(false);
377
350
  setUserPub(null);
378
351
  setUsername(null);
@@ -415,20 +388,12 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
415
388
  if (isShogunCore(core)) {
416
389
  return core.hasPlugin(name);
417
390
  }
418
- else if (isQuickStart(core)) {
419
- // QuickStart doesn't have plugins
420
- return false;
421
- }
422
391
  return false;
423
392
  };
424
393
  const getPlugin = (name) => {
425
394
  if (isShogunCore(core)) {
426
395
  return core.getPlugin(name);
427
396
  }
428
- else if (isQuickStart(core)) {
429
- // QuickStart doesn't have plugins
430
- return undefined;
431
- }
432
397
  return undefined;
433
398
  };
434
399
  // Export Gun pair functionality
@@ -527,18 +492,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
527
492
  });
528
493
  });
529
494
  }
530
- else if (isQuickStart(core)) {
531
- if (!core.database.gun)
532
- throw new Error('Gun instance not available');
533
- return new Promise((resolve, reject) => {
534
- core.database.gun.get(path).put(data, (ack) => {
535
- if (ack.err)
536
- reject(new Error(ack.err));
537
- else
538
- resolve();
539
- });
540
- });
541
- }
542
495
  else {
543
496
  throw new Error('Core not available');
544
497
  }
@@ -549,11 +502,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
549
502
  return null;
550
503
  return core.gun.get(path);
551
504
  }
552
- else if (isQuickStart(core)) {
553
- if (!core.database.gun)
554
- return null;
555
- return core.database.gun.get(path);
556
- }
557
505
  return null;
558
506
  },
559
507
  remove: async (path) => {
@@ -569,18 +517,6 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
569
517
  });
570
518
  });
571
519
  }
572
- else if (isQuickStart(core)) {
573
- if (!core.database.gun)
574
- throw new Error('Gun instance not available');
575
- return new Promise((resolve, reject) => {
576
- core.database.gun.get(path).put(null, (ack) => {
577
- if (ack.err)
578
- reject(new Error(ack.err));
579
- else
580
- resolve();
581
- });
582
- });
583
- }
584
520
  else {
585
521
  throw new Error('Core not available');
586
522
  }
@@ -753,17 +689,24 @@ export const ShogunButton = (() => {
753
689
  if (formMode === "signup") {
754
690
  const result = await signUp("password", formUsername, formPassword, formPasswordConfirm);
755
691
  if (result && result.success) {
756
- if (isShogunCore(core) && core.db) {
692
+ // Password hint functionality has been removed from shogun-core
693
+ // Users should store hints manually in their own data structures if needed
694
+ if (isShogunCore(core) && core.db && formHint) {
757
695
  try {
758
- const res = await core.db.setPasswordHintWithSecurity(formUsername, formPassword, formHint, [formSecurityQuestion], [formSecurityAnswer]);
759
- if (!(res === null || res === void 0 ? void 0 : res.success)) {
760
- // Fallback to legacy hint storage to avoid losing the hint
761
- await core.db.setPasswordHint(formHint);
696
+ // Store hint manually in user data
697
+ const user = core.gun.user();
698
+ if (user && user.is) {
699
+ core.db.gun.get('users').get(formUsername).get('hint').put(formHint);
700
+ if (formSecurityAnswer) {
701
+ core.db.gun.get('users').get(formUsername).get('security').put({
702
+ question: formSecurityQuestion,
703
+ answer: formSecurityAnswer
704
+ });
705
+ }
762
706
  }
763
707
  }
764
- catch {
765
- // Last-resort fallback
766
- await core.db.setPasswordHint(formHint);
708
+ catch (error) {
709
+ console.warn('Failed to store password hint:', error);
767
710
  }
768
711
  }
769
712
  setModalIsOpen(false);
@@ -846,19 +789,38 @@ export const ShogunButton = (() => {
846
789
  setLoading(true);
847
790
  try {
848
791
  if (isShogunCore(core) && core.db) {
849
- const result = await core.db.forgotPassword(formUsername, [
850
- formSecurityAnswer,
851
- ]);
852
- if (result.success && result.hint) {
853
- setRecoveredHint(result.hint);
854
- setAuthView("showHint");
792
+ // Password recovery functionality has been removed from shogun-core
793
+ // Users should implement their own recovery logic using Gun's get operations
794
+ try {
795
+ const hintNode = await new Promise((resolve) => {
796
+ core.db.gun.get('users').get(formUsername).get('hint').once((hint) => {
797
+ resolve(hint || null);
798
+ });
799
+ });
800
+ const securityNode = await new Promise((resolve) => {
801
+ core.db.gun.get('users').get(formUsername).get('security').once((security) => {
802
+ resolve(security || null);
803
+ });
804
+ });
805
+ if (securityNode && securityNode.answer === formSecurityAnswer) {
806
+ if (hintNode) {
807
+ setRecoveredHint(hintNode);
808
+ setAuthView("showHint");
809
+ }
810
+ else {
811
+ setError("No hint found for this user.");
812
+ }
813
+ }
814
+ else {
815
+ setError("Security answer is incorrect.");
816
+ }
855
817
  }
856
- else {
857
- setError(result.error || "Could not recover hint.");
818
+ catch (error) {
819
+ setError(error.message || "Could not recover hint.");
858
820
  }
859
821
  }
860
822
  else {
861
- setError("Password recovery not supported with QuickStart");
823
+ setError("Password recovery requires ShogunCore");
862
824
  }
863
825
  }
864
826
  catch (e) {
package/dist/connector.js CHANGED
@@ -1,23 +1,9 @@
1
- import { ShogunCore, quickStart } from "shogun-core";
1
+ import { ShogunCore } from "shogun-core";
2
2
  export async function shogunConnector(options) {
3
- const { gunInstance, appName, timeouts, webauthn, nostr, web3, zkproof, showWebauthn, showNostr, showMetamask, showZkProof, darkMode, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, useQuickStart = false, crypto, ...restOptions } = options;
3
+ const { gunInstance, appName, timeouts, webauthn, nostr, web3, zkproof, showWebauthn, showNostr, showMetamask, showZkProof, darkMode, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, crypto, ...restOptions } = options;
4
4
  let core = null;
5
5
  let gun = null;
6
6
  gun = gunInstance;
7
- // Use quickStart for simplified API if requested
8
- if (useQuickStart) {
9
- const quickStartInstance = quickStart(gun, appName || "shogun-app");
10
- await quickStartInstance.init();
11
- return {
12
- core: quickStartInstance, // Type assertion for compatibility
13
- options,
14
- setProvider: () => false, // Not applicable for quickStart
15
- getCurrentProviderUrl: () => null,
16
- registerPlugin: () => false,
17
- hasPlugin: () => false,
18
- gunPlugin: null,
19
- };
20
- }
21
7
  // Create ShogunCore with gunInstance (required in v2.0.0)
22
8
  core = new ShogunCore({
23
9
  gunInstance: gun,