shogun-core 1.2.0 → 1.2.3

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 (37) hide show
  1. package/README.md +6 -6
  2. package/dist/browser/shogun-core.js +1 -1
  3. package/dist/browser/shogun-core.light.js +1 -0
  4. package/dist/browser/shogun-core.vendors.light.js +1 -0
  5. package/dist/browser.js +11 -11
  6. package/dist/core.js +46 -45
  7. package/dist/gundb/gun.js +112 -92
  8. package/dist/plugins/index.js +4 -4
  9. package/dist/plugins/{bitcoin → nostr}/nostrConnectorPlugin.js +7 -8
  10. package/dist/plugins/{ethereum → web3}/web3ConnectorPlugin.js +7 -7
  11. package/dist/types/browser.d.ts +4 -4
  12. package/dist/types/core.d.ts +1 -2
  13. package/dist/types/gundb/gun.d.ts +4 -10
  14. package/dist/types/plugins/index.d.ts +6 -6
  15. package/dist/types/shogun.js +2 -2
  16. package/dist/types/types/shogun.d.ts +5 -23
  17. package/package.json +1 -1
  18. package/dist/gundb/models/auth/auth.js +0 -207
  19. package/dist/gundb/models/auth/state-machine.js +0 -216
  20. package/dist/gundb/models/streams.js +0 -116
  21. package/dist/types/gundb/models/auth/auth.d.ts +0 -121
  22. package/dist/types/gundb/models/auth/state-machine.d.ts +0 -70
  23. package/dist/types/gundb/models/streams.d.ts +0 -67
  24. /package/dist/plugins/{bitcoin → nostr}/index.js +0 -0
  25. /package/dist/plugins/{bitcoin → nostr}/nostrConnector.js +0 -0
  26. /package/dist/plugins/{bitcoin → nostr}/types.js +0 -0
  27. /package/dist/plugins/{ethereum → web3}/index.js +0 -0
  28. /package/dist/plugins/{ethereum → web3}/types.js +0 -0
  29. /package/dist/plugins/{ethereum → web3}/web3Connector.js +0 -0
  30. /package/dist/types/plugins/{bitcoin → nostr}/index.d.ts +0 -0
  31. /package/dist/types/plugins/{bitcoin → nostr}/nostrConnector.d.ts +0 -0
  32. /package/dist/types/plugins/{bitcoin → nostr}/nostrConnectorPlugin.d.ts +0 -0
  33. /package/dist/types/plugins/{bitcoin → nostr}/types.d.ts +0 -0
  34. /package/dist/types/plugins/{ethereum → web3}/index.d.ts +0 -0
  35. /package/dist/types/plugins/{ethereum → web3}/types.d.ts +0 -0
  36. /package/dist/types/plugins/{ethereum → web3}/web3Connector.d.ts +0 -0
  37. /package/dist/types/plugins/{ethereum → web3}/web3ConnectorPlugin.d.ts +0 -0
package/dist/browser.js CHANGED
@@ -47,16 +47,16 @@ const lazyModules = {
47
47
  webauthn: () => Promise.resolve().then(() => __importStar(require("./plugins/webauthn/webauthn"))),
48
48
  },
49
49
  // Web3 connection modules
50
- ethereum: {
51
- web3Connector: () => Promise.resolve().then(() => __importStar(require("./plugins/ethereum/web3ConnectorPlugin"))),
50
+ web3: {
51
+ web3Connector: () => Promise.resolve().then(() => __importStar(require("./plugins/web3/web3ConnectorPlugin"))),
52
52
  },
53
- bitcoin: {
54
- nostrConnector: () => Promise.resolve().then(() => __importStar(require("./plugins/bitcoin/nostrConnectorPlugin"))),
53
+ nostr: {
54
+ nostrConnector: () => Promise.resolve().then(() => __importStar(require("./plugins/nostr/nostrConnectorPlugin"))),
55
55
  },
56
56
  };
57
57
  // Instance tracking
58
58
  let shogunCoreInstance = null;
59
- let shogunG = null;
59
+ let gun = null;
60
60
  /**
61
61
  * Function to initialize Shogun in a browser environment
62
62
  *
@@ -75,11 +75,11 @@ function initShogunBrowser(config) {
75
75
  };
76
76
  // Create a new ShogunCore instance with browser-optimized configuration
77
77
  shogunCoreInstance = new index_1.ShogunCore(browserConfig);
78
- shogunG = shogunCoreInstance?.gun;
78
+ gun = shogunCoreInstance?.gun;
79
79
  // Support use as a global variable when included via <script>
80
80
  if (typeof window !== "undefined") {
81
81
  window.shogun = shogunCoreInstance;
82
- window.shogunGun = shogunG;
82
+ window.gun = gun;
83
83
  }
84
84
  return shogunCoreInstance;
85
85
  }
@@ -88,11 +88,11 @@ exports.modules = {
88
88
  webauthn: {
89
89
  loadWebAuthn: lazyModules.webauthn.webauthn,
90
90
  },
91
- ethereum: {
92
- loadMetaMask: lazyModules.ethereum.web3Connector,
91
+ web3: {
92
+ loadMetaMask: lazyModules.web3.web3Connector,
93
93
  },
94
- bitcoin: {
95
- loadNostrConnector: lazyModules.bitcoin.nostrConnector,
94
+ nostr: {
95
+ loadNostrConnector: lazyModules.nostr.nostrConnector,
96
96
  },
97
97
  };
98
98
  // Export types and interfaces
package/dist/core.js CHANGED
@@ -13,9 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
17
  exports.ShogunCore = exports.ShogunEventEmitter = exports.ShogunStorage = exports.Webauthn = exports.Web3Connector = exports.GunDB = exports.RelayVerifier = void 0;
21
18
  const gun_1 = require("./gundb/gun");
@@ -26,9 +23,8 @@ const errorHandler_1 = require("./utils/errorHandler");
26
23
  const storage_1 = require("./storage/storage");
27
24
  const shogun_1 = require("./types/shogun");
28
25
  const webauthnPlugin_1 = require("./plugins/webauthn/webauthnPlugin");
29
- const web3ConnectorPlugin_1 = require("./plugins/ethereum/web3ConnectorPlugin");
30
- const nostrConnectorPlugin_1 = require("./plugins/bitcoin/nostrConnectorPlugin");
31
- const gun_2 = __importDefault(require("gun"));
26
+ const web3ConnectorPlugin_1 = require("./plugins/web3/web3ConnectorPlugin");
27
+ const nostrConnectorPlugin_1 = require("./plugins/nostr/nostrConnectorPlugin");
32
28
  var utils_1 = require("./contracts/utils");
33
29
  Object.defineProperty(exports, "RelayVerifier", { enumerable: true, get: function () { return utils_1.RelayVerifier; } });
34
30
  __exportStar(require("./utils/errorHandler"), exports);
@@ -41,9 +37,9 @@ __exportStar(require("./contracts/relay"), exports);
41
37
  // Export all types
42
38
  __exportStar(require("./types/shogun"), exports);
43
39
  // Export classes
44
- var gun_3 = require("./gundb/gun");
45
- Object.defineProperty(exports, "GunDB", { enumerable: true, get: function () { return gun_3.GunDB; } });
46
- var web3Connector_1 = require("./plugins/ethereum/web3Connector");
40
+ var gun_2 = require("./gundb/gun");
41
+ Object.defineProperty(exports, "GunDB", { enumerable: true, get: function () { return gun_2.GunDB; } });
42
+ var web3Connector_1 = require("./plugins/web3/web3Connector");
47
43
  Object.defineProperty(exports, "Web3Connector", { enumerable: true, get: function () { return web3Connector_1.Web3Connector; } });
48
44
  var webauthn_1 = require("./plugins/webauthn/webauthn");
49
45
  Object.defineProperty(exports, "Webauthn", { enumerable: true, get: function () { return webauthn_1.Webauthn; } });
@@ -83,7 +79,6 @@ class ShogunCore {
83
79
  rx;
84
80
  /** Plugin registry */
85
81
  plugins = new Map();
86
- Gun;
87
82
  /** Current authentication method */
88
83
  currentAuthMethod;
89
84
  /**
@@ -102,7 +97,6 @@ class ShogunCore {
102
97
  }
103
98
  this.storage = new storage_1.ShogunStorage();
104
99
  this.eventEmitter = new eventEmitter_1.EventEmitter();
105
- this.Gun = gun_2.default;
106
100
  errorHandler_1.ErrorHandler.addListener((error) => {
107
101
  this.eventEmitter.emit("error", {
108
102
  action: error.code,
@@ -110,18 +104,45 @@ class ShogunCore {
110
104
  type: error.type,
111
105
  });
112
106
  });
113
- if (config.gunInstance) {
114
- this._gun = config.gunInstance;
107
+ (0, logger_1.log)("Creating Gun instance...");
108
+ try {
109
+ if (config.gunInstance) {
110
+ (0, logger_1.log)("Using provided Gun instance");
111
+ // Validate the provided instance
112
+ this._gun = config.gunInstance;
113
+ }
114
+ else {
115
+ (0, logger_1.log)(`Creating new Gun instance with peers: ${JSON.stringify(config.peers)}`);
116
+ // Use the factory to create a properly configured Gun instance
117
+ this._gun = Gun(config.peers || []);
118
+ }
119
+ (0, logger_1.log)(`Gun instance created and validated successfully`);
115
120
  }
116
- else {
117
- this._gun = this.Gun({ peers: config.peers });
121
+ catch (error) {
122
+ (0, logger_1.logError)("Error creating Gun instance:", error);
123
+ throw new Error(`Failed to create Gun instance: ${error}`);
118
124
  }
119
125
  // Then initialize GunDB with the Gun instance
120
- this.gundb = new gun_1.GunDB(this._gun, config.scope || "");
121
- this._gun = this.gundb.gun;
126
+ (0, logger_1.log)("Initializing GunDB...");
127
+ try {
128
+ this.gundb = new gun_1.GunDB(this._gun, config.scope || "");
129
+ this._gun = this.gundb.gun;
130
+ (0, logger_1.log)("GunDB initialized successfully");
131
+ }
132
+ catch (error) {
133
+ (0, logger_1.logError)("Error initializing GunDB:", error);
134
+ throw new Error(`Failed to initialize GunDB: ${error}`);
135
+ }
122
136
  (0, logger_1.log)("Initialized Gun instance");
123
- this._user = this.gun.user().recall({ sessionStorage: true });
124
- this.rx = new rxjs_integration_1.GunRxJS(this.gun);
137
+ try {
138
+ this._user = this._gun.user().recall({ sessionStorage: true });
139
+ (0, logger_1.log)("Gun user initialized successfully");
140
+ }
141
+ catch (error) {
142
+ (0, logger_1.logError)("Error initializing Gun user:", error);
143
+ throw new Error(`Failed to initialize Gun user: ${error}`);
144
+ }
145
+ this.rx = new rxjs_integration_1.GunRxJS(this._gun);
125
146
  this.registerBuiltinPlugins(config);
126
147
  if (config.plugins?.autoRegister &&
127
148
  config.plugins.autoRegister.length > 0) {
@@ -164,13 +185,13 @@ class ShogunCore {
164
185
  this.register(webauthnPlugin);
165
186
  (0, logger_1.log)("Webauthn plugin registered");
166
187
  }
167
- if (config.ethereum?.enabled) {
188
+ if (config.web3?.enabled) {
168
189
  const web3ConnectorPlugin = new web3ConnectorPlugin_1.Web3ConnectorPlugin();
169
190
  web3ConnectorPlugin._category = shogun_1.PluginCategory.Authentication;
170
191
  this.register(web3ConnectorPlugin);
171
192
  (0, logger_1.log)("Web3Connector plugin registered");
172
193
  }
173
- if (config.bitcoin?.enabled) {
194
+ if (config.nostr?.enabled) {
174
195
  const nostrConnectorPlugin = new nostrConnectorPlugin_1.NostrConnectorPlugin();
175
196
  nostrConnectorPlugin._category = shogun_1.PluginCategory.Authentication;
176
197
  this.register(nostrConnectorPlugin);
@@ -252,10 +273,10 @@ class ShogunCore {
252
273
  switch (type) {
253
274
  case "webauthn":
254
275
  return this.getPlugin(shogun_1.CorePlugins.WebAuthn);
255
- case "ethereum":
256
- return this.getPlugin(shogun_1.CorePlugins.Ethereum);
257
- case "bitcoin":
258
- return this.getPlugin(shogun_1.CorePlugins.Bitcoin);
276
+ case "web3":
277
+ return this.getPlugin(shogun_1.CorePlugins.Web3);
278
+ case "nostr":
279
+ return this.getPlugin(shogun_1.CorePlugins.Nostr);
259
280
  case "password":
260
281
  default:
261
282
  // Default authentication is provided by the core class
@@ -381,23 +402,6 @@ class ShogunCore {
381
402
  userPub: loginResult.userPub,
382
403
  username: loginResult.username,
383
404
  });
384
- // Then try to access wallet credentials after auth state is updated
385
- try {
386
- // Note: BIP44 plugin is now external - install @shogun/bip44 package separately
387
- // const walletPlugin = this.getPlugin<any>(CorePlugins.Bip44);
388
- // if (walletPlugin) {
389
- // const mainWallet = walletPlugin.getMainWalletCredentials();
390
- // this.storage.setItem(
391
- // "main-wallet",
392
- // JSON.stringify(mainWallet),
393
- // );
394
- // }
395
- (0, logger_1.log)("Wallet credentials access skipped - use external @shogun/bip44 plugin if needed");
396
- }
397
- catch (walletError) {
398
- // Just log the error but don't fail the login
399
- (0, logger_1.logError)("Error accessing wallet credentials after login:", walletError);
400
- }
401
405
  }
402
406
  }
403
407
  catch (error) {
@@ -416,9 +420,6 @@ class ShogunCore {
416
420
  // Automatically initialize wallet after successful login
417
421
  // Only for traditional password authentication
418
422
  (0, logger_1.log)(`Current auth method before wallet check: ${this.currentAuthMethod}`);
419
- // Note: Wallet initialization is now handled by external plugins
420
- // Users should register the @shogun/bip44 plugin if wallet functionality is needed
421
- (0, logger_1.log)("Wallet initialization skipped - use external @shogun/bip44 plugin if needed");
422
423
  }
423
424
  return result;
424
425
  }
package/dist/gundb/gun.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  /**
3
3
  * GunDB class with enhanced features:
4
- * - Dynamic auth token usage
5
- * - Concurrency-safe authentication
6
4
  * - Dynamic peer linking
7
5
  * - Support for remove/unset operations
6
+ * - Direct authentication through Gun.user()
8
7
  */
9
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
9
  if (k2 === undefined) k2 = k;
@@ -39,9 +38,6 @@ var __importStar = (this && this.__importStar) || (function () {
39
38
  return result;
40
39
  };
41
40
  })();
42
- var __importDefault = (this && this.__importDefault) || function (mod) {
43
- return (mod && mod.__esModule) ? mod : { "default": mod };
44
- };
45
41
  Object.defineProperty(exports, "__esModule", { value: true });
46
42
  exports.GunDB = void 0;
47
43
  const logger_1 = require("../utils/logger");
@@ -50,28 +46,45 @@ const rxjs_integration_1 = require("./rxjs-integration");
50
46
  const GunErrors = __importStar(require("./errors"));
51
47
  const crypto = __importStar(require("./crypto"));
52
48
  const utils = __importStar(require("./utils"));
53
- const auth_1 = __importDefault(require("./models/auth/auth"));
54
49
  class GunDB {
55
50
  gun;
56
51
  user = null;
57
52
  crypto;
58
53
  utils;
59
- auth;
60
54
  node;
61
55
  onAuthCallbacks = [];
62
- _authenticating = false;
63
56
  // Integrated modules
64
57
  _rxjs;
65
58
  constructor(gun, appScope = "shogun") {
66
59
  (0, logger_1.log)("Initializing GunDB");
60
+ // Validate Gun instance
61
+ if (!gun) {
62
+ throw new Error("Gun instance is required but was not provided");
63
+ }
64
+ if (typeof gun !== "object") {
65
+ throw new Error(`Gun instance must be an object, received: ${typeof gun}`);
66
+ }
67
+ if (typeof gun.user !== "function") {
68
+ throw new Error(`Gun instance is invalid: gun.user is not a function. Received gun.user type: ${typeof gun.user}`);
69
+ }
70
+ if (typeof gun.get !== "function") {
71
+ throw new Error(`Gun instance is invalid: gun.get is not a function. Received gun.get type: ${typeof gun.get}`);
72
+ }
73
+ if (typeof gun.on !== "function") {
74
+ throw new Error(`Gun instance is invalid: gun.on is not a function. Received gun.on type: ${typeof gun.on}`);
75
+ }
67
76
  this.gun = gun;
68
- this.user = this.gun.user().recall({ sessionStorage: true });
77
+ try {
78
+ this.user = this.gun.user().recall({ sessionStorage: true });
79
+ }
80
+ catch (error) {
81
+ (0, logger_1.logError)("Error initializing Gun user:", error);
82
+ throw new Error(`Failed to initialize Gun user: ${error}`);
83
+ }
69
84
  this.subscribeToAuthEvents();
70
85
  // bind crypto and utils
71
86
  this.crypto = crypto;
72
87
  this.utils = utils;
73
- // initialize auth manager
74
- this.auth = new auth_1.default(this, appScope);
75
88
  this.node = this.gun.get(appScope);
76
89
  }
77
90
  subscribeToAuthEvents() {
@@ -311,34 +324,56 @@ class GunDB {
311
324
  });
312
325
  }
313
326
  /**
314
- * Signs up a new user using AuthManager
327
+ * Signs up a new user using direct Gun authentication
315
328
  * @param username Username
316
329
  * @param password Password
317
330
  * @returns Promise resolving to signup result
318
331
  */
319
332
  async signUp(username, password) {
320
- (0, logger_1.log)("Attempting user registration using AuthManager:", username);
333
+ (0, logger_1.log)("Attempting user registration:", username);
321
334
  try {
322
- // Validate credentials with AuthManager
323
- const validatedCreds = await this.auth.validate(username, password);
324
- // Create user with AuthManager
325
- const createResult = await this.auth.create({
326
- alias: validatedCreds.alias,
327
- password: validatedCreds.password,
328
- });
329
- if ("err" in createResult) {
330
- (0, logger_1.logError)(`User creation error: ${createResult.err}`);
331
- return { success: false, error: createResult.err };
335
+ // Validate credentials
336
+ if (password.length < 8) {
337
+ const err = "Passwords must be more than 8 characters long!";
338
+ (0, logger_1.log)(err);
339
+ return { success: false, error: err };
340
+ }
341
+ if (username.length < 1) {
342
+ const err = "Username must be more than 0 characters long!";
343
+ (0, logger_1.log)(err);
344
+ return { success: false, error: err };
332
345
  }
333
- // Store user metadata
334
- const user = this.gun.get(createResult.pub).put({
335
- username: username,
346
+ // Create user directly with Gun
347
+ const createResult = await new Promise((resolve) => {
348
+ this.gun.user().create(username, password, (ack) => {
349
+ if (ack.err) {
350
+ (0, logger_1.logError)(`User creation error: ${ack.err}`);
351
+ resolve({ success: false, error: ack.err });
352
+ }
353
+ else {
354
+ (0, logger_1.log)(`User created successfully: ${username}`);
355
+ resolve({ success: true, pub: ack.pub });
356
+ }
357
+ });
336
358
  });
337
- this.gun.get("users").set(user);
359
+ if (!createResult.success) {
360
+ return createResult;
361
+ }
362
+ // Store user metadata with improved safety
363
+ try {
364
+ const user = this.gun.get(createResult.pub).put({
365
+ username: username,
366
+ pub: createResult.pub,
367
+ });
368
+ this.gun.get("users").set(user);
369
+ }
370
+ catch (metadataError) {
371
+ (0, logger_1.logError)(`Warning: Could not store user metadata: ${metadataError}`);
372
+ // Continue with login attempt even if metadata storage fails
373
+ }
338
374
  // Login after creation
339
375
  (0, logger_1.log)(`Attempting login after registration for: ${username}`);
340
376
  try {
341
- // Login with the same credentials
342
377
  const loginResult = await this.login(username, password);
343
378
  if (!loginResult.success) {
344
379
  (0, logger_1.logError)(`Login after registration failed: ${loginResult.error}`);
@@ -367,47 +402,63 @@ class GunDB {
367
402
  }
368
403
  }
369
404
  /**
370
- * Logs in a user using AuthManager
405
+ * Logs in a user using direct Gun authentication
371
406
  * @param username Username
372
407
  * @param password Password
373
408
  * @param callback Optional callback for login result
374
409
  * @returns Promise resolving to login result
375
410
  */
376
411
  async login(username, password, callback) {
377
- if (this.isAuthenticating()) {
378
- const err = "Authentication already in progress";
379
- (0, logger_1.log)(err);
380
- return { success: false, error: err };
381
- }
382
- this._setAuthenticating(true);
383
- (0, logger_1.log)(`Attempting login with AuthManager for user: ${username}`);
412
+ (0, logger_1.log)(`Attempting login for user: ${username}`);
384
413
  try {
385
- // Validate credentials
386
- const validatedCreds = await this.auth.validate(username, password);
387
- // Authenticate with AuthManager
388
- const authResult = await this.auth.auth({
389
- alias: validatedCreds.alias,
390
- password: validatedCreds.password,
414
+ // Authenticate with Gun directly
415
+ const authResult = await new Promise((resolve) => {
416
+ this.gun.user().auth(username, password, (ack) => {
417
+ if (ack.err) {
418
+ (0, logger_1.logError)(`Login error for ${username}: ${ack.err}`);
419
+ resolve({ success: false, error: ack.err });
420
+ }
421
+ else {
422
+ (0, logger_1.log)(`Login successful for: ${username}`);
423
+ resolve({ success: true, ack });
424
+ }
425
+ });
391
426
  });
392
- this._setAuthenticating(false);
393
- if ("err" in authResult) {
394
- (0, logger_1.logError)(`Login error for ${username}: ${authResult.err}`);
427
+ if (!authResult.success) {
428
+ const result = { success: false, error: authResult.error };
395
429
  if (callback)
396
- callback({ success: false, error: authResult.err });
397
- return { success: false, error: authResult.err };
430
+ callback(result);
431
+ return result;
398
432
  }
399
433
  const userPub = this.gun.user().is?.pub;
400
- // Update users collection if needed
401
- const user = this.gun.get("users").map((user) => {
402
- if (user.pub === userPub) {
403
- return user;
404
- }
405
- });
406
- if (!user) {
407
- const user = this.gun.get(userPub).put({
408
- username: username,
434
+ // Update users collection if needed - improved null safety
435
+ try {
436
+ let userExists = false;
437
+ // Check if user already exists in the collection
438
+ await new Promise((resolve) => {
439
+ this.gun
440
+ .get("users")
441
+ .map()
442
+ .once((userData, key) => {
443
+ if (userData && userData.pub === userPub) {
444
+ userExists = true;
445
+ }
446
+ });
447
+ // Give it a moment to check all users
448
+ setTimeout(() => resolve(), 100);
409
449
  });
410
- this.gun.get("users").set(user);
450
+ // Only add user if not already in collection
451
+ if (!userExists && userPub) {
452
+ const newUser = this.gun.get(userPub).put({
453
+ username: username,
454
+ pub: userPub,
455
+ });
456
+ this.gun.get("users").set(newUser);
457
+ }
458
+ }
459
+ catch (collectionError) {
460
+ // Log but don't fail the login for collection errors
461
+ (0, logger_1.logError)(`Warning: Could not update user collection: ${collectionError}`);
411
462
  }
412
463
  (0, logger_1.log)(`Login successful for: ${username} (${userPub})`);
413
464
  this._savePair();
@@ -421,7 +472,6 @@ class GunDB {
421
472
  return result;
422
473
  }
423
474
  catch (error) {
424
- this._setAuthenticating(false);
425
475
  (0, logger_1.logError)(`Exception during login for ${username}: ${error}`);
426
476
  const result = { success: false, error: String(error) };
427
477
  if (callback)
@@ -440,14 +490,8 @@ class GunDB {
440
490
  console.error("Error saving auth pair:", error);
441
491
  }
442
492
  }
443
- isAuthenticating() {
444
- return this._authenticating;
445
- }
446
- _setAuthenticating(value) {
447
- this._authenticating = value;
448
- }
449
493
  /**
450
- * Logs out the current user using AuthManager
494
+ * Logs out the current user using direct Gun authentication
451
495
  */
452
496
  logout() {
453
497
  try {
@@ -456,36 +500,12 @@ class GunDB {
456
500
  (0, logger_1.log)("No user logged in, skipping logout");
457
501
  return;
458
502
  }
459
- // Check if auth state machine is in the correct state for logout
460
- const currentState = auth_1.default.state.getCurrentState();
461
- if (currentState !== "authorized") {
462
- (0, logger_1.log)(`User in invalid state for logout: ${currentState}, using direct logout instead of AuthManager`);
463
- // Still perform Gun's direct logout for cleanup
464
- this.gun.user().leave();
465
- return;
466
- }
467
- // Use AuthManager for logout if state is correct
468
- this.auth
469
- .leave()
470
- .then(() => {
471
- (0, logger_1.log)("Logout completed via AuthManager");
472
- })
473
- .catch((err) => {
474
- (0, logger_1.logError)("Error during logout via AuthManager:", err);
475
- // Fallback to direct logout if AuthManager fails
476
- (0, logger_1.log)("Falling back to direct logout method");
477
- this.gun.user().leave();
478
- });
503
+ // Direct logout using Gun
504
+ this.gun.user().leave();
505
+ (0, logger_1.log)("Logout completed");
479
506
  }
480
507
  catch (error) {
481
508
  (0, logger_1.logError)("Error during logout:", error);
482
- // Last resort fallback
483
- try {
484
- this.gun.user().leave();
485
- }
486
- catch (fallbackError) {
487
- (0, logger_1.logError)("Fallback logout also failed:", fallbackError);
488
- }
489
509
  }
490
510
  }
491
511
  /**
@@ -10,12 +10,12 @@ Object.defineProperty(exports, "Webauthn", { enumerable: true, get: function ()
10
10
  var webauthnPlugin_1 = require("./webauthn/webauthnPlugin");
11
11
  Object.defineProperty(exports, "WebauthnPlugin", { enumerable: true, get: function () { return webauthnPlugin_1.WebauthnPlugin; } });
12
12
  // Ethereum plugin exports
13
- var web3Connector_1 = require("./ethereum/web3Connector");
13
+ var web3Connector_1 = require("./web3/web3Connector");
14
14
  Object.defineProperty(exports, "Web3Connector", { enumerable: true, get: function () { return web3Connector_1.Web3Connector; } });
15
- var web3ConnectorPlugin_1 = require("./ethereum/web3ConnectorPlugin");
15
+ var web3ConnectorPlugin_1 = require("./web3/web3ConnectorPlugin");
16
16
  Object.defineProperty(exports, "Web3ConnectorPlugin", { enumerable: true, get: function () { return web3ConnectorPlugin_1.Web3ConnectorPlugin; } });
17
17
  // Bitcoin plugin exports
18
- var nostrConnector_1 = require("./bitcoin/nostrConnector");
18
+ var nostrConnector_1 = require("./nostr/nostrConnector");
19
19
  Object.defineProperty(exports, "NostrConnector", { enumerable: true, get: function () { return nostrConnector_1.NostrConnector; } });
20
- var nostrConnectorPlugin_1 = require("./bitcoin/nostrConnectorPlugin");
20
+ var nostrConnectorPlugin_1 = require("./nostr/nostrConnectorPlugin");
21
21
  Object.defineProperty(exports, "NostrConnectorPlugin", { enumerable: true, get: function () { return nostrConnectorPlugin_1.NostrConnectorPlugin; } });
@@ -10,7 +10,7 @@ const errorHandler_1 = require("../../utils/errorHandler");
10
10
  * Supports Alby, Nostr extensions, or direct key management
11
11
  */
12
12
  class NostrConnectorPlugin extends base_1.BasePlugin {
13
- name = "bitcoin";
13
+ name = "nostr";
14
14
  version = "1.0.0";
15
15
  description = "Provides Bitcoin wallet connection and authentication for ShogunCore";
16
16
  bitcoinConnector = null;
@@ -142,9 +142,9 @@ class NostrConnectorPlugin extends base_1.BasePlugin {
142
142
  throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
143
143
  }
144
144
  (0, logger_1.log)("Bitcoin wallet signature verified successfully.");
145
- // Set authentication method to bitcoin before login
146
- core.setAuthMethod("bitcoin");
147
- // Use core's login method directly - simplified approach similar to MetaMask
145
+ // Set authentication method to nostr before login
146
+ core.setAuthMethod("nostr");
147
+ // Use core's login method with direct GunDB authentication
148
148
  (0, logger_1.log)("Logging in using core login method...");
149
149
  const loginResult = await core.login(credentials.username, credentials.password);
150
150
  if (!loginResult.success) {
@@ -187,7 +187,6 @@ class NostrConnectorPlugin extends base_1.BasePlugin {
187
187
  if (!this.isAvailable()) {
188
188
  throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "BITCOIN_WALLET_UNAVAILABLE", "No Bitcoin wallet available in the browser");
189
189
  }
190
- // Generate credentials similar to login
191
190
  (0, logger_1.log)("Generating credentials for Bitcoin wallet signup...");
192
191
  const credentials = await this.generateCredentials(address);
193
192
  if (!credentials?.username ||
@@ -205,9 +204,9 @@ class NostrConnectorPlugin extends base_1.BasePlugin {
205
204
  throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
206
205
  }
207
206
  (0, logger_1.log)("Bitcoin wallet signature verified successfully.");
208
- // Set authentication method to bitcoin before signup
209
- core.setAuthMethod("bitcoin");
210
- // Use core's signUp method directly - simplified approach similar to MetaMask
207
+ // Set authentication method to nostr before signup
208
+ core.setAuthMethod("nostr");
209
+ // Use core's signUp method with direct GunDB authentication
211
210
  (0, logger_1.log)("Signing up using core signUp method...");
212
211
  const signUpResult = await core.signUp(credentials.username, credentials.password);
213
212
  if (!signUpResult.success) {
@@ -10,7 +10,7 @@ const errorHandler_1 = require("../../utils/errorHandler");
10
10
  * Plugin per la gestione delle funzionalità MetaMask in ShogunCore
11
11
  */
12
12
  class Web3ConnectorPlugin extends base_1.BasePlugin {
13
- name = "ethereum";
13
+ name = "web3";
14
14
  version = "1.0.0";
15
15
  description = "Provides Ethereum wallet connection and authentication for ShogunCore";
16
16
  metamask = null;
@@ -133,9 +133,9 @@ class Web3ConnectorPlugin extends base_1.BasePlugin {
133
133
  throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "MetaMask signature verification failed. Address mismatch.");
134
134
  }
135
135
  (0, logger_1.log)("MetaMask signature verified successfully.");
136
- // Set authentication method to ethereum before login
137
- core.setAuthMethod("ethereum");
138
- // Use core's login method directly instead of core.gun.login
136
+ // Set authentication method to web3 before login
137
+ core.setAuthMethod("web3");
138
+ // Use core's login method with direct GunDB authentication
139
139
  (0, logger_1.log)("Logging in using core login method...");
140
140
  const loginResult = await core.login(credentials.username, credentials.password);
141
141
  if (!loginResult.success) {
@@ -194,9 +194,9 @@ class Web3ConnectorPlugin extends base_1.BasePlugin {
194
194
  throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "MetaMask signature verification failed. Address mismatch.");
195
195
  }
196
196
  (0, logger_1.log)("MetaMask signature verified successfully.");
197
- // Set authentication method to ethereum before signup
198
- core.setAuthMethod("ethereum");
199
- // Use core's signUp method directly instead of core.gun.signUp
197
+ // Set authentication method to web3 before signup
198
+ core.setAuthMethod("web3");
199
+ // Use core's signUp method with direct GunDB authentication
200
200
  (0, logger_1.log)("Signing up using core signUp method...");
201
201
  const signUpResult = await core.signUp(credentials.username, credentials.password);
202
202
  if (!signUpResult.success) {
@@ -16,11 +16,11 @@ export declare const modules: {
16
16
  webauthn: {
17
17
  loadWebAuthn: () => Promise<typeof import("./plugins/webauthn/webauthn")>;
18
18
  };
19
- ethereum: {
20
- loadMetaMask: () => Promise<typeof import("./plugins/ethereum/web3ConnectorPlugin")>;
19
+ web3: {
20
+ loadMetaMask: () => Promise<typeof import("./plugins/web3/web3ConnectorPlugin")>;
21
21
  };
22
- bitcoin: {
23
- loadNostrConnector: () => Promise<typeof import("./plugins/bitcoin/nostrConnectorPlugin")>;
22
+ nostr: {
23
+ loadNostrConnector: () => Promise<typeof import("./plugins/nostr/nostrConnectorPlugin")>;
24
24
  };
25
25
  };
26
26
  export { ShogunCore };
@@ -23,7 +23,7 @@ export type * from "./types/plugin";
23
23
  export type * from "./utils/errorHandler";
24
24
  export * from "./types/shogun";
25
25
  export { GunDB } from "./gundb/gun";
26
- export { Web3Connector } from "./plugins/ethereum/web3Connector";
26
+ export { Web3Connector } from "./plugins/web3/web3Connector";
27
27
  export { Webauthn } from "./plugins/webauthn/webauthn";
28
28
  export { ShogunStorage } from "./storage/storage";
29
29
  export { ShogunEventEmitter } from "./types/events";
@@ -59,7 +59,6 @@ export declare class ShogunCore implements IShogunCore {
59
59
  rx: GunRxJS;
60
60
  /** Plugin registry */
61
61
  private readonly plugins;
62
- private Gun;
63
62
  /** Current authentication method */
64
63
  private currentAuthMethod?;
65
64
  /**