shogun-core 1.1.4 → 1.2.2

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 (82) hide show
  1. package/README.md +61 -1327
  2. package/dist/browser/shogun-core.js +1 -1
  3. package/dist/browser/shogun-core.js.LICENSE.txt +0 -9
  4. package/dist/browser/shogun-core.light.js +1 -1
  5. package/dist/browser/shogun-core.vendors.light.js +1 -1
  6. package/dist/browser.js +27 -11
  7. package/dist/core.js +603 -0
  8. package/dist/{gun → gundb}/crypto.js +38 -8
  9. package/dist/gundb/gun.js +676 -0
  10. package/dist/{gun → gundb}/index.js +0 -5
  11. package/dist/{gun → gundb}/utils.js +6 -0
  12. package/dist/index.js +1 -807
  13. package/dist/plugins/index.js +15 -28
  14. package/dist/plugins/{stealth → nostr}/index.js +3 -4
  15. package/dist/plugins/nostr/nostrConnector.js +656 -0
  16. package/dist/plugins/nostr/nostrConnectorPlugin.js +259 -0
  17. package/dist/plugins/{metamask → web3}/index.js +2 -2
  18. package/dist/plugins/{metamask/metamask.js → web3/web3Connector.js} +8 -8
  19. package/dist/plugins/{metamask/metamaskPlugin.js → web3/web3ConnectorPlugin.js} +32 -42
  20. package/dist/plugins/webauthn/webauthnPlugin.js +4 -0
  21. package/dist/types/browser.d.ts +9 -4
  22. package/dist/types/core.d.ts +221 -0
  23. package/dist/types/{gun → gundb}/crypto.d.ts +20 -5
  24. package/dist/types/{gun → gundb}/gun.d.ts +56 -28
  25. package/dist/types/gundb/index.d.ts +1 -0
  26. package/dist/types/{gun → gundb}/utils.d.ts +1 -0
  27. package/dist/types/index.d.ts +1 -282
  28. package/dist/types/plugins/index.d.ts +7 -10
  29. package/dist/types/plugins/nostr/index.d.ts +3 -0
  30. package/dist/types/plugins/nostr/nostrConnector.d.ts +111 -0
  31. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +87 -0
  32. package/dist/types/plugins/nostr/types.d.ts +122 -0
  33. package/dist/types/plugins/web3/index.d.ts +3 -0
  34. package/dist/types/plugins/{metamask → web3}/types.d.ts +4 -4
  35. package/dist/types/plugins/{metamask/metamask.d.ts → web3/web3Connector.d.ts} +7 -7
  36. package/dist/types/plugins/{metamask/metamaskPlugin.d.ts → web3/web3ConnectorPlugin.d.ts} +4 -4
  37. package/dist/types/shogun.js +40 -15
  38. package/dist/types/types/shogun.d.ts +67 -67
  39. package/dist/types/utils/errorHandler.d.ts +39 -36
  40. package/dist/types/utils/utility.d.ts +0 -4
  41. package/dist/utils/errorHandler.js +43 -40
  42. package/dist/utils/utility.js +0 -8
  43. package/package.json +2 -2
  44. package/dist/config.js +0 -18
  45. package/dist/gun/gun.js +0 -542
  46. package/dist/plugins/stealth/stealth.js +0 -176
  47. package/dist/plugins/stealth/stealthPlugin.js +0 -113
  48. package/dist/plugins/stealth/types.js +0 -2
  49. package/dist/plugins/utils/stubs/didStub.js +0 -35
  50. package/dist/plugins/utils/stubs/stealthStub.js +0 -35
  51. package/dist/plugins/utils/stubs/webauthnStub.js +0 -29
  52. package/dist/plugins/wallet/index.js +0 -20
  53. package/dist/plugins/wallet/types.js +0 -15
  54. package/dist/plugins/wallet/walletManager.js +0 -1832
  55. package/dist/plugins/wallet/walletPlugin.js +0 -236
  56. package/dist/types/config.d.ts +0 -15
  57. package/dist/types/gun/index.d.ts +0 -6
  58. package/dist/types/gun/types.d.ts +0 -2
  59. package/dist/types/plugins/metamask/index.d.ts +0 -3
  60. package/dist/types/plugins/stealth/index.d.ts +0 -3
  61. package/dist/types/plugins/stealth/stealth.d.ts +0 -93
  62. package/dist/types/plugins/stealth/stealthPlugin.d.ts +0 -60
  63. package/dist/types/plugins/stealth/types.d.ts +0 -93
  64. package/dist/types/plugins/utils/stubs/didStub.d.ts +0 -15
  65. package/dist/types/plugins/utils/stubs/stealthStub.d.ts +0 -15
  66. package/dist/types/plugins/utils/stubs/webauthnStub.d.ts +0 -13
  67. package/dist/types/plugins/wallet/index.d.ts +0 -3
  68. package/dist/types/plugins/wallet/types.d.ts +0 -167
  69. package/dist/types/plugins/wallet/walletManager.d.ts +0 -306
  70. package/dist/types/plugins/wallet/walletPlugin.d.ts +0 -126
  71. package/dist/types/utils/stubs/didStub.d.ts +0 -15
  72. package/dist/types/utils/stubs/stealthStub.d.ts +0 -15
  73. package/dist/types/utils/stubs/webauthnStub.d.ts +0 -13
  74. package/dist/utils/stubs/didStub.js +0 -35
  75. package/dist/utils/stubs/stealthStub.js +0 -35
  76. package/dist/utils/stubs/webauthnStub.js +0 -29
  77. /package/dist/{gun → gundb}/errors.js +0 -0
  78. /package/dist/{gun → gundb}/rxjs-integration.js +0 -0
  79. /package/dist/{gun → plugins/nostr}/types.js +0 -0
  80. /package/dist/plugins/{metamask → web3}/types.js +0 -0
  81. /package/dist/types/{gun → gundb}/errors.d.ts +0 -0
  82. /package/dist/types/{gun → gundb}/rxjs-integration.d.ts +0 -0
@@ -5,7 +5,7 @@ exports.createError = createError;
5
5
  exports.handleError = handleError;
6
6
  const logger_1 = require("./logger");
7
7
  /**
8
- * Tipi di errore che possono verificarsi nell'applicazione
8
+ * Types of errors that can occur in the application
9
9
  */
10
10
  var ErrorType;
11
11
  (function (ErrorType) {
@@ -28,14 +28,17 @@ var ErrorType;
28
28
  ErrorType["CONNECTOR"] = "CONNECTOR";
29
29
  ErrorType["GENERAL"] = "GENERAL";
30
30
  ErrorType["CONTRACT"] = "CONTRACT";
31
+ ErrorType["BIP32"] = "BIP32Error";
32
+ ErrorType["ETHEREUM"] = "EthereumError";
33
+ ErrorType["BITCOIN"] = "BitcoinError";
31
34
  })(ErrorType || (exports.ErrorType = ErrorType = {}));
32
35
  /**
33
- * Wrapper per standardizzare gli errori
34
- * @param type - Tipo di errore
35
- * @param code - Codice errore
36
- * @param message - Messaggio errore
37
- * @param originalError - Errore originale
38
- * @returns Un oggetto di errore strutturato
36
+ * Wrapper to standardize errors
37
+ * @param type - Error type
38
+ * @param code - Error code
39
+ * @param message - Error message
40
+ * @param originalError - Original error
41
+ * @returns A structured error object
39
42
  */
40
43
  function createError(type, code, message, originalError) {
41
44
  return {
@@ -47,23 +50,23 @@ function createError(type, code, message, originalError) {
47
50
  };
48
51
  }
49
52
  /**
50
- * Funzione di utilità per gestire gli errori in modo consistente
51
- * @param error - L'errore da gestire
52
- * @param options - Opzioni di configurazione
53
- * @returns Risultato dell'operazione o il risultato della callback
53
+ * Utility function to handle errors consistently
54
+ * @param error - The error to handle
55
+ * @param options - Configuration options
56
+ * @returns Operation result or callback result
54
57
  */
55
58
  function handleError(error, options = {}) {
56
- // Impostazioni di default
59
+ // Default settings
57
60
  const { message = error instanceof Error ? error.message : String(error), throwError = false, logError = true, callback, } = options;
58
- // Log dell'errore se richiesto
61
+ // Log the error if requested
59
62
  if (logError) {
60
63
  console.error(`[ERROR] ${message}`, error);
61
64
  }
62
- // Se è stata fornita una callback, la eseguiamo e restituiamo il suo risultato
65
+ // If a callback was provided, execute it and return its result
63
66
  if (typeof callback === "function") {
64
67
  return callback(error);
65
68
  }
66
- // Se è richiesto di lanciare l'errore, lo lanciamo
69
+ // If requested to throw the error, throw it
67
70
  if (throwError) {
68
71
  if (error instanceof Error) {
69
72
  throw error;
@@ -72,7 +75,7 @@ function handleError(error, options = {}) {
72
75
  throw new Error(message);
73
76
  }
74
77
  }
75
- // Altrimenti restituiamo un oggetto di risultato standard
78
+ // Otherwise return a standard result object
76
79
  return {
77
80
  success: false,
78
81
  message,
@@ -80,34 +83,34 @@ function handleError(error, options = {}) {
80
83
  };
81
84
  }
82
85
  /**
83
- * Gestore centralizzato per errori
86
+ * Centralized error handler
84
87
  */
85
88
  class ErrorHandler {
86
89
  static errors = [];
87
90
  static maxErrors = 100;
88
91
  static listeners = [];
89
92
  /**
90
- * Gestisce un errore registrandolo e notificando gli ascoltatori
91
- * @param error - L'errore da gestire
93
+ * Handles an error by logging it and notifying listeners
94
+ * @param error - The error to handle
92
95
  */
93
96
  static handleError(error) {
94
- // Log l'errore
97
+ // Log the error
95
98
  (0, logger_1.logError)(`[${error.type}] ${error.code}: ${error.message}`);
96
- // Conserva l'errore nella memoria
99
+ // Store the error in memory
97
100
  this.errors.push(error);
98
- // Mantiene solo gli ultimi maxErrors
101
+ // Keep only the last maxErrors
99
102
  if (this.errors.length > this.maxErrors) {
100
103
  this.errors = this.errors.slice(-this.maxErrors);
101
104
  }
102
- // Notifica gli ascoltatori
105
+ // Notify listeners
103
106
  this.notifyListeners(error);
104
107
  }
105
108
  /**
106
- * Gestisce un errore grezzo convertendolo in ShogunError
107
- * @param type - Tipo errore
108
- * @param code - Codice errore
109
- * @param message - Messaggio errore
110
- * @param originalError - Errore originale
109
+ * Handles a raw error by converting it to ShogunError
110
+ * @param type - Error type
111
+ * @param code - Error code
112
+ * @param message - Error message
113
+ * @param originalError - Original error
111
114
  */
112
115
  static handle(type, code, message, originalError, logLevel = "error") {
113
116
  // Create a formatted error message
@@ -138,23 +141,23 @@ class ErrorHandler {
138
141
  return error;
139
142
  }
140
143
  /**
141
- * Recupera gli ultimi N errori
142
- * @param count - Numero di errori da recuperare
143
- * @returns Lista degli errori più recenti
144
+ * Retrieves the last N errors
145
+ * @param count - Number of errors to retrieve
146
+ * @returns List of most recent errors
144
147
  */
145
148
  static getRecentErrors(count = 10) {
146
149
  return this.errors.slice(-Math.min(count, this.errors.length));
147
150
  }
148
151
  /**
149
- * Aggiunge un ascoltatore per gli errori
150
- * @param listener - Funzione che verrà chiamata quando si verifica un errore
152
+ * Adds a listener for errors
153
+ * @param listener - Function that will be called when an error occurs
151
154
  */
152
155
  static addListener(listener) {
153
156
  this.listeners.push(listener);
154
157
  }
155
158
  /**
156
- * Rimuove un ascoltatore per gli errori
157
- * @param listener - Funzione da rimuovere
159
+ * Removes an error listener
160
+ * @param listener - Function to remove
158
161
  */
159
162
  static removeListener(listener) {
160
163
  const index = this.listeners.indexOf(listener);
@@ -163,8 +166,8 @@ class ErrorHandler {
163
166
  }
164
167
  }
165
168
  /**
166
- * Notifica tutti gli ascoltatori di un errore
167
- * @param error - Errore da notificare
169
+ * Notifies all listeners of an error
170
+ * @param error - Error to notify
168
171
  */
169
172
  static notifyListeners(error) {
170
173
  for (const listener of this.listeners) {
@@ -177,9 +180,9 @@ class ErrorHandler {
177
180
  }
178
181
  }
179
182
  /**
180
- * Funzione helper per formattare messaggi di errore dagli errori nativi
181
- * @param error - Errore da formattare
182
- * @returns Messaggio di errore formattato
183
+ * Helper function to format error messages from native errors
184
+ * @param error - Error to format
185
+ * @returns Formatted error message
183
186
  */
184
187
  static formatError(error) {
185
188
  if (!error) {
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPlatformWeb = void 0;
4
3
  exports.delay = delay;
5
4
  exports.errorAfter = errorAfter;
6
5
  exports.randomString = randomString;
7
- /**
8
- * Checks if the application is running in a web environment
9
- */
10
- const isPlatformWeb = () => {
11
- return typeof window !== "undefined";
12
- };
13
- exports.isPlatformWeb = isPlatformWeb;
14
6
  /**
15
7
  * Delays execution for the specified time
16
8
  * @param ms - Milliseconds to delay
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "1.1.4",
4
- "description": "SHOGUN SDK - Libreria semplificata per la gestione di wallet crypto con GunDB",
3
+ "version": "1.2.2",
4
+ "description": "SHOGUN SDK - Core library for Shogun SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/types/index.d.ts",
package/dist/config.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG = void 0;
4
- exports.CONFIG = {
5
- TIMEOUT: {
6
- AUTH: 60000,
7
- GUN: 5000,
8
- WALLET: 30000,
9
- },
10
- PATHS: {
11
- DERIVATION_BASE: "m/44'/60'/0'/0/",
12
- DEFAULT_INDEX: 0,
13
- },
14
- PREFIX: "⚔️ ShogunSDK:",
15
- PEERS: [],
16
- MESSAGE_TO_SIGN: "Access With Shogun",
17
- };
18
- exports.default = exports.CONFIG;