shogun-core 3.0.13 → 3.0.15

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 +27 -1
  2. package/dist/browser/shogun-core.js +103157 -84871
  3. package/dist/browser/shogun-core.js.map +1 -1
  4. package/dist/config/simplified-config.js +22 -16
  5. package/dist/core.js +18 -26
  6. package/dist/examples/api-test.js +273 -0
  7. package/dist/examples/simple-api-test.js +89 -0
  8. package/dist/gundb/api.js +126 -189
  9. package/dist/gundb/crypto.js +32 -17
  10. package/dist/gundb/db.js +89 -137
  11. package/dist/gundb/derive.js +20 -17
  12. package/dist/gundb/errors.js +17 -7
  13. package/dist/gundb/index.js +19 -3
  14. package/dist/gundb/rxjs.js +19 -17
  15. package/dist/gundb/types.js +2 -1
  16. package/dist/index.js +43 -12
  17. package/dist/interfaces/common.js +2 -1
  18. package/dist/interfaces/events.js +6 -2
  19. package/dist/interfaces/plugin.js +2 -1
  20. package/dist/interfaces/shogun.js +7 -4
  21. package/dist/managers/AuthManager.js +9 -7
  22. package/dist/managers/CoreInitializer.js +23 -20
  23. package/dist/managers/EventManager.js +7 -4
  24. package/dist/managers/PluginManager.js +6 -3
  25. package/dist/migration-test.js +13 -8
  26. package/dist/plugins/base.js +11 -8
  27. package/dist/plugins/index.js +36 -10
  28. package/dist/plugins/nostr/index.js +20 -4
  29. package/dist/plugins/nostr/nostrConnector.js +42 -36
  30. package/dist/plugins/nostr/nostrConnectorPlugin.js +36 -29
  31. package/dist/plugins/nostr/nostrSigner.js +17 -11
  32. package/dist/plugins/nostr/types.js +2 -1
  33. package/dist/plugins/oauth/index.js +7 -2
  34. package/dist/plugins/oauth/oauthConnector.js +75 -69
  35. package/dist/plugins/oauth/oauthPlugin.js +31 -27
  36. package/dist/plugins/oauth/types.js +2 -1
  37. package/dist/plugins/web3/index.js +20 -4
  38. package/dist/plugins/web3/types.js +2 -1
  39. package/dist/plugins/web3/web3Connector.js +38 -33
  40. package/dist/plugins/web3/web3ConnectorPlugin.js +29 -22
  41. package/dist/plugins/web3/web3Signer.js +24 -18
  42. package/dist/plugins/webauthn/index.js +19 -3
  43. package/dist/plugins/webauthn/types.js +5 -2
  44. package/dist/plugins/webauthn/webauthn.js +30 -25
  45. package/dist/plugins/webauthn/webauthnPlugin.js +21 -14
  46. package/dist/plugins/webauthn/webauthnSigner.js +20 -14
  47. package/dist/storage/storage.js +5 -4
  48. package/dist/types/events.js +8 -2
  49. package/dist/types/examples/api-test.d.ts +12 -0
  50. package/dist/types/examples/simple-api-test.d.ts +5 -0
  51. package/dist/types/gundb/api.d.ts +0 -26
  52. package/dist/types/gundb/db.d.ts +2 -35
  53. package/dist/types/shogun.js +7 -4
  54. package/dist/utils/errorHandler.js +13 -8
  55. package/dist/utils/eventEmitter.js +5 -2
  56. package/dist/utils/validation.js +14 -7
  57. package/package.json +2 -1
@@ -1,13 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Webauthn = void 0;
7
+ exports.deriveWebauthnKeys = deriveWebauthnKeys;
1
8
  /**
2
9
  * Constants for WebAuthn configuration
3
10
  */
4
11
  const MIN_USERNAME_LENGTH = 3;
5
12
  const MAX_USERNAME_LENGTH = 64;
6
- import { ethers } from "ethers";
7
- import { ErrorHandler, ErrorType } from "../../utils/errorHandler";
8
- import { EventEmitter } from "../../utils/eventEmitter";
9
- import { WebAuthnEventType, } from "./types";
10
- import derive from "../../gundb/derive";
13
+ const ethers_1 = require("ethers");
14
+ const errorHandler_1 = require("../../utils/errorHandler");
15
+ const eventEmitter_1 = require("../../utils/eventEmitter");
16
+ const types_1 = require("./types");
17
+ const derive_1 = __importDefault(require("../../gundb/derive"));
11
18
  /**
12
19
  * Constants for WebAuthn configuration
13
20
  */
@@ -22,16 +29,13 @@ const DEFAULT_CONFIG = {
22
29
  /**
23
30
  * Main WebAuthn class for authentication management
24
31
  */
25
- export class Webauthn extends EventEmitter {
26
- config;
27
- gunInstance;
28
- credential;
29
- abortController = null;
32
+ class Webauthn extends eventEmitter_1.EventEmitter {
30
33
  /**
31
34
  * Creates a new WebAuthn instance
32
35
  */
33
36
  constructor(gunInstance, config) {
34
37
  super();
38
+ this.abortController = null;
35
39
  this.gunInstance = gunInstance;
36
40
  this.credential = null;
37
41
  // Merge default config with provided config
@@ -73,8 +77,8 @@ export class Webauthn extends EventEmitter {
73
77
  try {
74
78
  const result = await this.generateCredentials(username, credentials, isNewDevice);
75
79
  if (result.success) {
76
- this.emit(WebAuthnEventType.DEVICE_REGISTERED, {
77
- type: WebAuthnEventType.DEVICE_REGISTERED,
80
+ this.emit(types_1.WebAuthnEventType.DEVICE_REGISTERED, {
81
+ type: types_1.WebAuthnEventType.DEVICE_REGISTERED,
78
82
  data: { username },
79
83
  timestamp: Date.now(),
80
84
  });
@@ -93,8 +97,8 @@ export class Webauthn extends EventEmitter {
93
97
  throw lastError || new Error("Failed to create account after retries");
94
98
  }
95
99
  catch (error) {
96
- this.emit(WebAuthnEventType.ERROR, {
97
- type: WebAuthnEventType.ERROR,
100
+ this.emit(types_1.WebAuthnEventType.ERROR, {
101
+ type: types_1.WebAuthnEventType.ERROR,
98
102
  data: { error: error.message },
99
103
  timestamp: Date.now(),
100
104
  });
@@ -109,7 +113,7 @@ export class Webauthn extends EventEmitter {
109
113
  this.validateUsername(username);
110
114
  if (!salt) {
111
115
  const error = new Error("No WebAuthn credentials found for this username");
112
- ErrorHandler.handle(ErrorType.WEBAUTHN, "NO_CREDENTIALS", error.message, error);
116
+ errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "NO_CREDENTIALS", error.message, error);
113
117
  return { success: false, error: error.message };
114
118
  }
115
119
  // Cancel any existing authentication attempt
@@ -143,8 +147,8 @@ export class Webauthn extends EventEmitter {
143
147
  credentialId: this.bufferToBase64(assertion.rawId),
144
148
  deviceInfo,
145
149
  };
146
- this.emit(WebAuthnEventType.AUTHENTICATION_SUCCESS, {
147
- type: WebAuthnEventType.AUTHENTICATION_SUCCESS,
150
+ this.emit(types_1.WebAuthnEventType.AUTHENTICATION_SUCCESS, {
151
+ type: types_1.WebAuthnEventType.AUTHENTICATION_SUCCESS,
148
152
  data: { username, deviceInfo },
149
153
  timestamp: Date.now(),
150
154
  });
@@ -157,12 +161,12 @@ export class Webauthn extends EventEmitter {
157
161
  }
158
162
  catch (error) {
159
163
  const errorMessage = error instanceof Error ? error.message : "Unknown WebAuthn error";
160
- this.emit(WebAuthnEventType.AUTHENTICATION_FAILED, {
161
- type: WebAuthnEventType.AUTHENTICATION_FAILED,
164
+ this.emit(types_1.WebAuthnEventType.AUTHENTICATION_FAILED, {
165
+ type: types_1.WebAuthnEventType.AUTHENTICATION_FAILED,
162
166
  data: { username, error: errorMessage },
163
167
  timestamp: Date.now(),
164
168
  });
165
- ErrorHandler.handle(ErrorType.WEBAUTHN, "AUTH_ERROR", errorMessage, error);
169
+ errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "AUTH_ERROR", errorMessage, error);
166
170
  return { success: false, error: errorMessage };
167
171
  }
168
172
  }
@@ -255,9 +259,9 @@ export class Webauthn extends EventEmitter {
255
259
  * Generates credentials from username and salt
256
260
  */
257
261
  generateCredentialsFromSalt(username, salt) {
258
- const data = ethers.toUtf8Bytes(username + salt);
262
+ const data = ethers_1.ethers.toUtf8Bytes(username + salt);
259
263
  return {
260
- password: ethers.sha256(data),
264
+ password: ethers_1.ethers.sha256(data),
261
265
  };
262
266
  }
263
267
  /**
@@ -461,6 +465,7 @@ export class Webauthn extends EventEmitter {
461
465
  return signature;
462
466
  }
463
467
  }
468
+ exports.Webauthn = Webauthn;
464
469
  // Add to global scope if available
465
470
  if (typeof window !== "undefined") {
466
471
  window.Webauthn = Webauthn;
@@ -469,10 +474,10 @@ else if (typeof global !== "undefined") {
469
474
  global.Webauthn = Webauthn;
470
475
  }
471
476
  // Funzione helper per derivare chiavi WebAuthn (come per Web3)
472
- export async function deriveWebauthnKeys(username, credentialId) {
473
- const hashedCredentialId = ethers.keccak256(ethers.toUtf8Bytes(credentialId));
477
+ async function deriveWebauthnKeys(username, credentialId) {
478
+ const hashedCredentialId = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(credentialId));
474
479
  const salt = `${username}_${credentialId}`;
475
- return await derive(hashedCredentialId, salt, {
480
+ return await (0, derive_1.default)(hashedCredentialId, salt, {
476
481
  includeP256: true,
477
482
  });
478
483
  }
@@ -1,16 +1,22 @@
1
- import { BasePlugin } from "../base";
2
- import { Webauthn } from "./webauthn";
3
- import { WebAuthnSigner } from "./webauthnSigner";
4
- import { ErrorHandler, ErrorType } from "../../utils/errorHandler";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebauthnPlugin = void 0;
4
+ const base_1 = require("../base");
5
+ const webauthn_1 = require("./webauthn");
6
+ const webauthnSigner_1 = require("./webauthnSigner");
7
+ const errorHandler_1 = require("../../utils/errorHandler");
5
8
  /**
6
9
  * Plugin per la gestione delle funzionalità WebAuthn in ShogunCore
7
10
  */
8
- export class WebauthnPlugin extends BasePlugin {
9
- name = "webauthn";
10
- version = "1.0.0";
11
- description = "Provides WebAuthn authentication functionality for ShogunCore";
12
- webauthn = null;
13
- signer = null;
11
+ class WebauthnPlugin extends base_1.BasePlugin {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.name = "webauthn";
15
+ this.version = "1.0.0";
16
+ this.description = "Provides WebAuthn authentication functionality for ShogunCore";
17
+ this.webauthn = null;
18
+ this.signer = null;
19
+ }
14
20
  /**
15
21
  * @inheritdoc
16
22
  */
@@ -27,8 +33,8 @@ export class WebauthnPlugin extends BasePlugin {
27
33
  return;
28
34
  }
29
35
  // Inizializziamo il modulo WebAuthn
30
- this.webauthn = new Webauthn(core.gun);
31
- this.signer = new WebAuthnSigner(this.webauthn);
36
+ this.webauthn = new webauthn_1.Webauthn(core.gun);
37
+ this.signer = new webauthnSigner_1.WebAuthnSigner(this.webauthn);
32
38
  console.log("[webauthnPlugin] WebAuthn plugin initialized with signer support");
33
39
  }
34
40
  /**
@@ -342,7 +348,7 @@ export class WebauthnPlugin extends BasePlugin {
342
348
  catch (error) {
343
349
  console.error(`Error during WebAuthn login: ${error}`);
344
350
  // Log but do not depend on handler return value
345
- ErrorHandler.handle(ErrorType.WEBAUTHN, "WEBAUTHN_LOGIN_ERROR", error.message || "Error during WebAuthn login", error);
351
+ errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "WEBAUTHN_LOGIN_ERROR", error.message || "Error during WebAuthn login", error);
346
352
  return {
347
353
  success: false,
348
354
  error: error.message || "Error during WebAuthn login",
@@ -388,7 +394,7 @@ export class WebauthnPlugin extends BasePlugin {
388
394
  }
389
395
  catch (error) {
390
396
  console.error(`Error during WebAuthn registration: ${error}`);
391
- ErrorHandler.handle(ErrorType.WEBAUTHN, "WEBAUTHN_SIGNUP_ERROR", error.message || "Error during WebAuthn registration", error);
397
+ errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "WEBAUTHN_SIGNUP_ERROR", error.message || "Error during WebAuthn registration", error);
392
398
  return {
393
399
  success: false,
394
400
  error: error.message || "Error during WebAuthn registration",
@@ -396,3 +402,4 @@ export class WebauthnPlugin extends BasePlugin {
396
402
  }
397
403
  }
398
404
  }
405
+ exports.WebauthnPlugin = WebauthnPlugin;
@@ -1,8 +1,14 @@
1
- import { Webauthn } from "./webauthn";
2
- import { p256 } from "@noble/curves/p256";
3
- import { sha256 } from "@noble/hashes/sha256";
4
- import derive from "../../gundb/derive";
5
- import { ethers } from "ethers";
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebAuthnSigner = void 0;
7
+ const webauthn_1 = require("./webauthn");
8
+ const p256_1 = require("@noble/curves/p256");
9
+ const sha256_1 = require("@noble/hashes/sha256");
10
+ const derive_1 = __importDefault(require("../../gundb/derive"));
11
+ const ethers_1 = require("ethers");
6
12
  /**
7
13
  * Base64URL encoding utilities
8
14
  */
@@ -27,11 +33,10 @@ const base64url = {
27
33
  * Similar to webauthn.js but integrated with our architecture
28
34
  * CONSISTENT with normal WebAuthn approach
29
35
  */
30
- export class WebAuthnSigner {
31
- webauthn;
32
- credentials = new Map();
36
+ class WebAuthnSigner {
33
37
  constructor(webauthn) {
34
- this.webauthn = webauthn || new Webauthn();
38
+ this.credentials = new Map();
39
+ this.webauthn = webauthn || new webauthn_1.Webauthn();
35
40
  }
36
41
  /**
37
42
  * Creates a new WebAuthn credential for signing
@@ -83,7 +88,7 @@ export class WebAuthnSigner {
83
88
  const y = base64url.encode(yCoord);
84
89
  const pub = `${x}.${y}`;
85
90
  // CONSISTENCY: Use the same hashing approach as normal WebAuthn
86
- const hashedCredentialId = ethers.keccak256(ethers.toUtf8Bytes(credential.id));
91
+ const hashedCredentialId = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(credential.id));
87
92
  const signingCredential = {
88
93
  id: credential.id,
89
94
  rawId: credential.rawId,
@@ -152,7 +157,7 @@ export class WebAuthnSigner {
152
157
  try {
153
158
  // CONSISTENCY: Use the same approach as normal WebAuthn
154
159
  // Use hashedCredentialId as password (same as normal approach)
155
- const derivedKeys = await derive(credential.hashedCredentialId, // This is the key change!
160
+ const derivedKeys = await (0, derive_1.default)(credential.hashedCredentialId, // This is the key change!
156
161
  extra, { includeP256: true });
157
162
  return {
158
163
  pub: derivedKeys.pub,
@@ -234,11 +239,11 @@ export class WebAuthnSigner {
234
239
  const keyPair = await this.createDerivedKeyPair(credentialId, username, extra);
235
240
  // Create signature using P-256 (same as SEA)
236
241
  const message = JSON.stringify(data);
237
- const messageHash = sha256(new TextEncoder().encode(message));
242
+ const messageHash = (0, sha256_1.sha256)(new TextEncoder().encode(message));
238
243
  // Convert base64url private key to bytes
239
244
  const privKeyBytes = base64url.decode(keyPair.priv);
240
245
  // Sign with P-256
241
- const signature = p256.sign(messageHash, privKeyBytes);
246
+ const signature = p256_1.p256.sign(messageHash, privKeyBytes);
242
247
  // Format like SEA signature
243
248
  const seaSignature = {
244
249
  m: message,
@@ -301,4 +306,5 @@ export class WebAuthnSigner {
301
306
  return this.credentials.delete(credentialId);
302
307
  }
303
308
  }
304
- export default WebAuthnSigner;
309
+ exports.WebAuthnSigner = WebAuthnSigner;
310
+ exports.default = WebAuthnSigner;
@@ -1,12 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShogunStorage = void 0;
1
4
  /**
2
5
  * Storage implementation based on StorageMock
3
6
  * Provides a unified storage interface that works in both browser and non-browser environments
4
7
  * In browser environments, data is persisted to localStorage as a backup
5
8
  */
6
- export class ShogunStorage {
7
- store;
8
- isTestMode;
9
- useLocalStorage;
9
+ class ShogunStorage {
10
10
  /**
11
11
  * Initializes storage and loads any existing keypair from localStorage if available
12
12
  */
@@ -145,3 +145,4 @@ export class ShogunStorage {
145
145
  }
146
146
  }
147
147
  }
148
+ exports.ShogunStorage = ShogunStorage;
@@ -1,11 +1,16 @@
1
+ "use strict";
1
2
  /**
2
3
  * Event types and interfaces for Shogun SDK
3
4
  */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ShogunEventEmitter = void 0;
4
7
  /**
5
8
  * Event emitter class for Shogun SDK
6
9
  */
7
- export class ShogunEventEmitter {
8
- listeners = new Map();
10
+ class ShogunEventEmitter {
11
+ constructor() {
12
+ this.listeners = new Map();
13
+ }
9
14
  on(eventName, listener) {
10
15
  if (!this.listeners.has(eventName)) {
11
16
  this.listeners.set(eventName, []);
@@ -62,3 +67,4 @@ export class ShogunEventEmitter {
62
67
  return Array.from(this.listeners.keys());
63
68
  }
64
69
  }
70
+ exports.ShogunEventEmitter = ShogunEventEmitter;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Esempio completo che mostra le differenze tra i vari metodi dell'API ShogunCore
3
+ *
4
+ * Questo esempio dimostra:
5
+ * - get() vs getData() vs getNode() vs node() vs chain()
6
+ * - put() vs set() vs putUserData() vs setUserData()
7
+ * - remove() vs removeUserData()
8
+ * - Operazioni globali vs operazioni utente
9
+ */
10
+ declare function demonstrateAPIDifferences(): Promise<void>;
11
+ declare function showAPIDifferences(): void;
12
+ export { demonstrateAPIDifferences, showAPIDifferences };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Esempio semplice che mostra le differenze principali tra i metodi API
3
+ */
4
+ declare function simpleAPITest(): Promise<void>;
5
+ export { simpleAPITest };
@@ -56,32 +56,6 @@ export declare class SimpleGunAPI {
56
56
  id: string | number;
57
57
  }>(arr: T[]): Record<string, T>;
58
58
  indexedObjectToArray<T>(indexedObj: Record<string, T> | null): T[];
59
- putUserArray<T extends {
60
- id: string | number;
61
- }>(path: string, arr: T[]): Promise<boolean>;
62
- getUserArray<T>(path: string): Promise<T[]>;
63
- addToUserArray<T extends {
64
- id: string | number;
65
- }>(path: string, item: T): Promise<boolean>;
66
- removeFromUserArray<T extends {
67
- id: string | number;
68
- }>(path: string, itemId: string | number): Promise<boolean>;
69
- updateInUserArray<T extends {
70
- id: string | number;
71
- }>(path: string, itemId: string | number, updates: Partial<T>): Promise<boolean>;
72
- putArray<T extends {
73
- id: string | number;
74
- }>(path: string, arr: T[]): Promise<boolean>;
75
- getArray<T>(path: string): Promise<T[]>;
76
- addToArray<T extends {
77
- id: string | number;
78
- }>(path: string, item: T): Promise<boolean>;
79
- removeFromArray<T extends {
80
- id: string | number;
81
- }>(path: string, itemId: string | number): Promise<boolean>;
82
- updateInArray<T extends {
83
- id: string | number;
84
- }>(path: string, itemId: string | number, updates: Partial<T>): Promise<boolean>;
85
59
  /**
86
60
  * Path utilities
87
61
  */
@@ -4,7 +4,7 @@
4
4
  * - Support for remove/unset operations
5
5
  * - Direct authentication through Gun.user()
6
6
  */
7
- import type { GunUser, UserInfo, AuthCallback, GunData, GunNode, EventData, EventListener, GunOperationResult } from "./types";
7
+ import type { GunUser, UserInfo, AuthCallback, GunData, EventData, EventListener, GunOperationResult } from "./types";
8
8
  import type { GunInstance, GunUserInstance, GunChain } from "./types";
9
9
  import type { AuthResult, SignUpResult } from "../interfaces/shogun";
10
10
  import Gun from "gun/gun";
@@ -91,20 +91,6 @@ declare class DataBase {
91
91
  * @returns Gun node at the specified path
92
92
  */
93
93
  private navigateToPath;
94
- /**
95
- * Deconstruct path for GunDB navigation in user space
96
- * Converts "todos/1234" to user.get("todos").get("1234")
97
- * @param path Path string to deconstruct
98
- * @returns Gun node at the specified path in user space
99
- */
100
- deconstructUserPath(path: string): GunNode;
101
- /**
102
- * Deconstruct path for GunDB navigation in global space
103
- * Converts "todos/1234" to gun.get("todos").get("1234")
104
- * @param path Path string to deconstruct
105
- * @returns Gun node at the specified path in global space
106
- */
107
- deconstructGlobalPath(path: string): GunNode;
108
94
  /**
109
95
  * Gets the Gun instance
110
96
  * @returns Gun instance
@@ -324,25 +310,6 @@ declare class DataBase {
324
310
  hint?: string;
325
311
  error?: string;
326
312
  }>;
327
- /**
328
- * Saves user data at the specified path
329
- * @param path Path to save the data (supports nested paths like "test/data/marco")
330
- * @param data Data to save
331
- * @returns Promise that resolves when the data is saved
332
- */
333
- putUserData(path: string, data: any): Promise<void>;
334
- /**
335
- * Gets user data from the specified path
336
- * @param path Path to get the data from (supports nested paths like "test/data/marco")
337
- * @returns Promise that resolves with the data
338
- */
339
- getUserData(path: string): Promise<any>;
340
- /**
341
- * Removes user data at the specified path
342
- * @param path Path to remove the data from (supports nested paths like "test/data/marco")
343
- * @returns Promise that resolves when the data is removed
344
- */
345
- removeUserData(path: string): Promise<void>;
346
313
  static Errors: typeof GunErrors;
347
314
  /**
348
315
  * Adds an event listener
@@ -413,7 +380,7 @@ declare class DataBase {
413
380
  */
414
381
  isAuthenticated(): boolean;
415
382
  }
416
- declare const createGun: (config: any) => import("gun").IGunInstance<any>;
383
+ declare const createGun: (config: any) => import("gun/types").IGunInstance<any>;
417
384
  export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, createGun };
418
385
  export default Gun;
419
386
  export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
@@ -1,18 +1,21 @@
1
+ "use strict";
1
2
  /**
2
3
  * Core types and interfaces for Shogun SDK
3
4
  */
4
- export var PluginCategory;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CorePlugins = exports.PluginCategory = void 0;
7
+ var PluginCategory;
5
8
  (function (PluginCategory) {
6
9
  PluginCategory["Authentication"] = "authentication";
7
10
  PluginCategory["Wallet"] = "wallet";
8
11
  PluginCategory["Privacy"] = "privacy";
9
12
  PluginCategory["Identity"] = "identity";
10
13
  PluginCategory["Utility"] = "utility";
11
- })(PluginCategory || (PluginCategory = {}));
12
- export var CorePlugins;
14
+ })(PluginCategory || (exports.PluginCategory = PluginCategory = {}));
15
+ var CorePlugins;
13
16
  (function (CorePlugins) {
14
17
  CorePlugins["WebAuthn"] = "webauthn";
15
18
  CorePlugins["Web3"] = "web3";
16
19
  CorePlugins["Nostr"] = "nostr";
17
20
  CorePlugins["OAuth"] = "oauth";
18
- })(CorePlugins || (CorePlugins = {}));
21
+ })(CorePlugins || (exports.CorePlugins = CorePlugins = {}));
@@ -1,7 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorHandler = exports.ErrorType = void 0;
4
+ exports.createError = createError;
1
5
  /**
2
6
  * Types of errors that can occur in the application
3
7
  */
4
- export var ErrorType;
8
+ var ErrorType;
5
9
  (function (ErrorType) {
6
10
  ErrorType["AUTHENTICATION"] = "AuthenticationError";
7
11
  ErrorType["AUTHORIZATION"] = "AuthorizationError";
@@ -25,7 +29,7 @@ export var ErrorType;
25
29
  ErrorType["BIP32"] = "BIP32Error";
26
30
  ErrorType["ETHEREUM"] = "EthereumError";
27
31
  ErrorType["BITCOIN"] = "BitcoinError";
28
- })(ErrorType || (ErrorType = {}));
32
+ })(ErrorType || (exports.ErrorType = ErrorType = {}));
29
33
  /**
30
34
  * Wrapper to standardize errors
31
35
  * @param type - Error type
@@ -34,7 +38,7 @@ export var ErrorType;
34
38
  * @param originalError - Original error
35
39
  * @returns A structured error object
36
40
  */
37
- export function createError(type, code, message, originalError) {
41
+ function createError(type, code, message, originalError) {
38
42
  return {
39
43
  type,
40
44
  code,
@@ -46,11 +50,7 @@ export function createError(type, code, message, originalError) {
46
50
  /**
47
51
  * Centralized error handler
48
52
  */
49
- export class ErrorHandler {
50
- static errors = [];
51
- static maxErrors = 100;
52
- static listeners = [];
53
- static externalLogger = null;
53
+ class ErrorHandler {
54
54
  /**
55
55
  * Set an external logging service for production error monitoring
56
56
  * @param logger - External logger function to send errors to a monitoring service
@@ -239,3 +239,8 @@ export class ErrorHandler {
239
239
  this.errors = [];
240
240
  }
241
241
  }
242
+ exports.ErrorHandler = ErrorHandler;
243
+ ErrorHandler.errors = [];
244
+ ErrorHandler.maxErrors = 100;
245
+ ErrorHandler.listeners = [];
246
+ ErrorHandler.externalLogger = null;
@@ -1,8 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventEmitter = void 0;
1
4
  /**
2
5
  * Simple event emitter implementation with generic event types
3
6
  */
4
- export class EventEmitter {
5
- events;
7
+ class EventEmitter {
6
8
  constructor() {
7
9
  this.events = new Map();
8
10
  }
@@ -74,3 +76,4 @@ export class EventEmitter {
74
76
  }
75
77
  }
76
78
  }
79
+ exports.EventEmitter = EventEmitter;
@@ -1,9 +1,16 @@
1
+ "use strict";
1
2
  // Utility di validazione e generazione credenziali per ShogunCore
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateUsername = validateUsername;
5
+ exports.validateEmail = validateEmail;
6
+ exports.validateProvider = validateProvider;
7
+ exports.generateUsernameFromIdentity = generateUsernameFromIdentity;
8
+ exports.generateDeterministicPassword = generateDeterministicPassword;
2
9
  // --- VALIDAZIONE ---
3
10
  /**
4
11
  * Valida uno username secondo le regole comuni
5
12
  */
6
- export function validateUsername(username) {
13
+ function validateUsername(username) {
7
14
  if (!username || typeof username !== "string")
8
15
  return false;
9
16
  if (username.length < 3 || username.length > 64)
@@ -15,7 +22,7 @@ export function validateUsername(username) {
15
22
  /**
16
23
  * Valida una email
17
24
  */
18
- export function validateEmail(email) {
25
+ function validateEmail(email) {
19
26
  if (!email || typeof email !== "string")
20
27
  return false;
21
28
  // Regex semplice per email
@@ -24,7 +31,7 @@ export function validateEmail(email) {
24
31
  /**
25
32
  * Valida un provider OAuth supportato
26
33
  */
27
- export function validateProvider(provider) {
34
+ function validateProvider(provider) {
28
35
  return ["google", "github", "discord", "twitter", "custom"].includes(provider);
29
36
  }
30
37
  // --- GENERAZIONE USERNAME ---
@@ -32,7 +39,7 @@ export function validateProvider(provider) {
32
39
  * Genera uno username uniforme a partire da provider e userInfo
33
40
  * Esempio: google_utente, github_12345, nostr_pubkey, web3_0xabc...
34
41
  */
35
- export function generateUsernameFromIdentity(provider, userInfo) {
42
+ function generateUsernameFromIdentity(provider, userInfo) {
36
43
  if (provider === "web3" && userInfo.id) {
37
44
  return `web3_${userInfo.id.toLowerCase()}`;
38
45
  }
@@ -54,15 +61,15 @@ export function generateUsernameFromIdentity(provider, userInfo) {
54
61
  return `${provider}_user`;
55
62
  }
56
63
  // --- GENERAZIONE PASSWORD DETERMINISTICA ---
57
- import { ethers } from "ethers";
64
+ const ethers_1 = require("ethers");
58
65
  /**
59
66
  * Genera una password deterministica sicura a partire da un salt
60
67
  * Usare per OAuth, Web3, Nostr, ecc.
61
68
  */
62
- export function generateDeterministicPassword(salt) {
69
+ function generateDeterministicPassword(salt) {
63
70
  try {
64
71
  // Restituisce una stringa hex di 32 caratteri
65
- return ethers.keccak256(ethers.toUtf8Bytes(salt)).slice(2, 34);
72
+ return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(salt)).slice(2, 34);
66
73
  }
67
74
  catch (error) {
68
75
  // Fallback in case ethers is not available
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -56,6 +56,7 @@
56
56
  "nostr-tools": "^2.15.0",
57
57
  "qs": "^6.14.0",
58
58
  "rxjs": "^7.8.2",
59
+ "ts-node": "^10.9.2",
59
60
  "url": "^0.11.4",
60
61
  "uuid": "^11.1.0",
61
62
  "vm-browserify": "^1.1.2",