shogun-core 6.2.3 → 6.3.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.
Files changed (233) hide show
  1. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
  2. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
  3. package/dist/browser/shogun-core.js +138850 -146638
  4. package/dist/browser/shogun-core.js.map +1 -1
  5. package/dist/{core.js → src/core.js} +167 -107
  6. package/dist/src/crypto/asymmetric.js +168 -0
  7. package/dist/src/crypto/double-ratchet.js +908 -0
  8. package/dist/src/crypto/file-encryption.js +352 -0
  9. package/dist/src/crypto/hashing.js +160 -0
  10. package/dist/src/crypto/index.js +18 -0
  11. package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
  12. package/dist/src/crypto/mls.js +734 -0
  13. package/dist/src/crypto/pgp.js +619 -0
  14. package/dist/{crypto → src/crypto}/random-generation.js +125 -103
  15. package/dist/src/crypto/sframe.js +466 -0
  16. package/dist/src/crypto/signal-protocol.js +943 -0
  17. package/dist/src/crypto/symmetric.js +165 -0
  18. package/dist/src/crypto/utils.js +220 -0
  19. package/dist/src/examples/auth-test.js +535 -0
  20. package/dist/src/examples/crypto-identity-example.js +294 -0
  21. package/dist/src/examples/crypto-working-test.js +149 -0
  22. package/dist/src/examples/double-ratchet-test.js +240 -0
  23. package/dist/src/examples/mls-3-member-test.js +183 -0
  24. package/dist/src/examples/mls-multi-member.js +439 -0
  25. package/dist/src/examples/mls-sframe-test.js +491 -0
  26. package/dist/src/examples/mls-simple-test.js +122 -0
  27. package/dist/src/examples/pgp-example.js +354 -0
  28. package/dist/src/examples/random-generation-test.js +191 -0
  29. package/dist/src/examples/shogun-core-example.js +204 -0
  30. package/dist/src/examples/signal-protocol-test.js +82 -0
  31. package/dist/src/examples/zkproof-credentials-example.js +357 -0
  32. package/dist/src/examples/zkproof-example.js +357 -0
  33. package/dist/src/gundb/crypto.js +420 -0
  34. package/dist/src/gundb/db.js +728 -0
  35. package/dist/src/gundb/derive.js +327 -0
  36. package/dist/src/gundb/errors.js +115 -0
  37. package/dist/src/gundb/gun-es.js +8 -0
  38. package/dist/src/gundb/index.js +5 -0
  39. package/dist/{gundb → src/gundb}/rxjs.js +147 -111
  40. package/dist/{gundb → src/gundb}/types.js +1 -2
  41. package/dist/src/index.js +19 -0
  42. package/dist/src/interfaces/events.js +57 -0
  43. package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
  44. package/dist/src/managers/AuthManager.js +301 -0
  45. package/dist/src/managers/CoreInitializer.js +304 -0
  46. package/dist/src/managers/CryptoIdentityManager.js +230 -0
  47. package/dist/{managers → src/managers}/EventManager.js +19 -21
  48. package/dist/{managers → src/managers}/PluginManager.js +123 -89
  49. package/dist/src/plugins/base.js +90 -0
  50. package/dist/src/plugins/index.js +17 -0
  51. package/dist/src/plugins/nostr/index.js +4 -0
  52. package/dist/src/plugins/nostr/nostrConnector.js +539 -0
  53. package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
  54. package/dist/src/plugins/nostr/nostrSigner.js +414 -0
  55. package/dist/src/plugins/smartwallet/index.js +2 -0
  56. package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
  57. package/dist/src/plugins/web3/index.js +4 -0
  58. package/dist/src/plugins/web3/types.js +1 -0
  59. package/dist/src/plugins/web3/web3Connector.js +738 -0
  60. package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
  61. package/dist/src/plugins/web3/web3Signer.js +432 -0
  62. package/dist/src/plugins/webauthn/index.js +3 -0
  63. package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
  64. package/dist/src/plugins/webauthn/webauthn.js +647 -0
  65. package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
  66. package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
  67. package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
  68. package/dist/src/plugins/zkproof/types.js +1 -0
  69. package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
  70. package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
  71. package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
  72. package/dist/src/storage/storage.js +189 -0
  73. package/dist/src/utils/errorHandler.js +339 -0
  74. package/dist/{utils → src/utils}/eventEmitter.js +26 -26
  75. package/dist/{utils → src/utils}/seedPhrase.js +23 -32
  76. package/dist/{utils → src/utils}/validation.js +14 -21
  77. package/dist/tsconfig.tsbuildinfo +1 -0
  78. package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
  79. package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
  80. package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
  81. package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
  82. package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
  83. package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
  84. package/dist/types/src/examples/random-generation-test.d.ts +1 -0
  85. package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
  86. package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
  87. package/dist/types/src/gundb/gun-es.d.ts +8 -0
  88. package/dist/types/src/gundb/min.d.ts +3 -0
  89. package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
  90. package/package.json +14 -11
  91. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
  92. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
  93. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
  94. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
  95. package/dist/crypto/asymmetric.js +0 -99
  96. package/dist/crypto/double-ratchet.js +0 -370
  97. package/dist/crypto/file-encryption.js +0 -213
  98. package/dist/crypto/hashing.js +0 -87
  99. package/dist/crypto/index.js +0 -34
  100. package/dist/crypto/mls.js +0 -569
  101. package/dist/crypto/pgp.js +0 -390
  102. package/dist/crypto/sframe.js +0 -352
  103. package/dist/crypto/signal-protocol.js +0 -456
  104. package/dist/crypto/symmetric.js +0 -91
  105. package/dist/crypto/types.js +0 -2
  106. package/dist/crypto/utils.js +0 -140
  107. package/dist/examples/auth-test.js +0 -453
  108. package/dist/examples/crypto-identity-example.js +0 -196
  109. package/dist/examples/crypto-working-test.js +0 -83
  110. package/dist/examples/double-ratchet-test.js +0 -155
  111. package/dist/examples/mls-3-member-test.js +0 -97
  112. package/dist/examples/mls-multi-member.js +0 -153
  113. package/dist/examples/mls-sframe-test.js +0 -307
  114. package/dist/examples/mls-simple-test.js +0 -58
  115. package/dist/examples/pgp-example.js +0 -200
  116. package/dist/examples/random-generation-test.js +0 -151
  117. package/dist/examples/shogun-core-example.js +0 -150
  118. package/dist/examples/signal-protocol-test.js +0 -38
  119. package/dist/examples/zkproof-credentials-example.js +0 -217
  120. package/dist/examples/zkproof-example.js +0 -242
  121. package/dist/gundb/crypto.js +0 -306
  122. package/dist/gundb/db.js +0 -485
  123. package/dist/gundb/derive.js +0 -232
  124. package/dist/gundb/errors.js +0 -76
  125. package/dist/gundb/gun-es.js +0 -12
  126. package/dist/gundb/index.js +0 -21
  127. package/dist/gundb/min.js +0 -10
  128. package/dist/index.esm.js +0 -22
  129. package/dist/index.js +0 -47
  130. package/dist/interfaces/common.js +0 -2
  131. package/dist/interfaces/events.js +0 -40
  132. package/dist/interfaces/plugin.js +0 -2
  133. package/dist/managers/AuthManager.js +0 -226
  134. package/dist/managers/CoreInitializer.js +0 -250
  135. package/dist/managers/CryptoIdentityManager.js +0 -138
  136. package/dist/plugins/base.js +0 -50
  137. package/dist/plugins/index.js +0 -32
  138. package/dist/plugins/nostr/index.js +0 -20
  139. package/dist/plugins/nostr/nostrConnector.js +0 -419
  140. package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
  141. package/dist/plugins/nostr/nostrSigner.js +0 -319
  142. package/dist/plugins/nostr/types.js +0 -2
  143. package/dist/plugins/smartwallet/index.js +0 -18
  144. package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
  145. package/dist/plugins/smartwallet/types.js +0 -2
  146. package/dist/plugins/web3/index.js +0 -20
  147. package/dist/plugins/web3/types.js +0 -2
  148. package/dist/plugins/web3/web3Connector.js +0 -533
  149. package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
  150. package/dist/plugins/web3/web3Signer.js +0 -314
  151. package/dist/plugins/webauthn/index.js +0 -19
  152. package/dist/plugins/webauthn/webauthn.js +0 -496
  153. package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
  154. package/dist/plugins/webauthn/webauthnSigner.js +0 -310
  155. package/dist/plugins/zkproof/types.js +0 -2
  156. package/dist/plugins/zkproof/zkCredentials.js +0 -216
  157. package/dist/plugins/zkproof/zkProofConnector.js +0 -198
  158. package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
  159. package/dist/storage/storage.js +0 -145
  160. package/dist/types/gundb/gun-es.d.ts +0 -8
  161. package/dist/utils/errorHandler.js +0 -246
  162. /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
  163. /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
  164. /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
  165. /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
  166. /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
  167. /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
  168. /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
  169. /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
  170. /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
  171. /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
  172. /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
  173. /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
  174. /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
  175. /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
  176. /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
  177. /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
  178. /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
  179. /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
  180. /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
  181. /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
  182. /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
  183. /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
  184. /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
  185. /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
  186. /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
  187. /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
  188. /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
  189. /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
  190. /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
  191. /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
  192. /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
  193. /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
  194. /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
  195. /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
  196. /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
  197. /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
  198. /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
  199. /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
  200. /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
  201. /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
  202. /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
  203. /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
  204. /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
  205. /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
  206. /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
  207. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
  208. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  209. /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
  210. /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
  211. /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
  212. /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
  213. /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
  214. /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
  215. /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
  216. /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
  217. /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  218. /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
  219. /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
  220. /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
  221. /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
  222. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  223. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
  224. /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
  225. /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
  226. /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
  227. /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
  228. /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
  229. /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
  230. /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
  231. /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
  232. /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
  233. /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
@@ -0,0 +1,639 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ var __read = (this && this.__read) || function (o, n) {
53
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
54
+ if (!m) return o;
55
+ var i = m.call(o), r, ar = [], e;
56
+ try {
57
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
58
+ }
59
+ catch (error) { e = { error: error }; }
60
+ finally {
61
+ try {
62
+ if (r && !r.done && (m = i["return"])) m.call(i);
63
+ }
64
+ finally { if (e) throw e.error; }
65
+ }
66
+ return ar;
67
+ };
68
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
69
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
70
+ if (ar || !(i in from)) {
71
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
+ ar[i] = from[i];
73
+ }
74
+ }
75
+ return to.concat(ar || Array.prototype.slice.call(from));
76
+ };
77
+ import { BasePlugin } from "../base.js";
78
+ import { Web3Connector } from "./web3Connector.js";
79
+ import { Web3Signer } from "./web3Signer.js";
80
+ import { ErrorHandler, ErrorType, createError } from "../../utils/errorHandler.js";
81
+ /**
82
+ * Plugin per la gestione delle funzionalità Web3 in ShogunCore
83
+ */
84
+ var Web3ConnectorPlugin = /** @class */ (function (_super) {
85
+ __extends(Web3ConnectorPlugin, _super);
86
+ function Web3ConnectorPlugin() {
87
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
88
+ _this.name = "web3";
89
+ _this.version = "1.0.0";
90
+ _this.description = "Provides Ethereum wallet connection and authentication for ShogunCore";
91
+ _this.Web3 = null;
92
+ _this.signer = null;
93
+ return _this;
94
+ }
95
+ /**
96
+ * @inheritdoc
97
+ */
98
+ Web3ConnectorPlugin.prototype.initialize = function (core) {
99
+ _super.prototype.initialize.call(this, core);
100
+ // Inizializziamo il modulo Web3
101
+ this.Web3 = new Web3Connector();
102
+ this.signer = new Web3Signer(this.Web3);
103
+ // Rimuovo i console.log superflui
104
+ };
105
+ /**
106
+ * @inheritdoc
107
+ */
108
+ Web3ConnectorPlugin.prototype.destroy = function () {
109
+ if (this.Web3) {
110
+ this.Web3.cleanup();
111
+ }
112
+ this.Web3 = null;
113
+ this.signer = null;
114
+ _super.prototype.destroy.call(this);
115
+ // Linea 50
116
+ };
117
+ /**
118
+ * Assicura che il modulo Web3 sia inizializzato
119
+ * @private
120
+ */
121
+ Web3ConnectorPlugin.prototype.assertMetaMask = function () {
122
+ this.assertInitialized();
123
+ if (!this.Web3) {
124
+ throw new Error("Web3 module not initialized");
125
+ }
126
+ return this.Web3;
127
+ };
128
+ /**
129
+ * Assicura che il signer sia inizializzato
130
+ * @private
131
+ */
132
+ Web3ConnectorPlugin.prototype.assertSigner = function () {
133
+ this.assertInitialized();
134
+ if (!this.signer) {
135
+ throw new Error("Web3 signer not initialized");
136
+ }
137
+ return this.signer;
138
+ };
139
+ /**
140
+ * @inheritdoc
141
+ */
142
+ Web3ConnectorPlugin.prototype.isAvailable = function () {
143
+ return this.assertMetaMask().isAvailable();
144
+ };
145
+ /**
146
+ * @inheritdoc
147
+ */
148
+ Web3ConnectorPlugin.prototype.connectMetaMask = function () {
149
+ return __awaiter(this, void 0, void 0, function () {
150
+ return __generator(this, function (_a) {
151
+ return [2 /*return*/, this.assertMetaMask().connectMetaMask()];
152
+ });
153
+ });
154
+ };
155
+ /**
156
+ * @inheritdoc
157
+ */
158
+ Web3ConnectorPlugin.prototype.generateCredentials = function (address) {
159
+ return __awaiter(this, void 0, void 0, function () {
160
+ return __generator(this, function (_a) {
161
+ // Rimuovo i console.log superflui
162
+ return [2 /*return*/, this.assertMetaMask().generateCredentials(address)];
163
+ });
164
+ });
165
+ };
166
+ /**
167
+ * @inheritdoc
168
+ */
169
+ Web3ConnectorPlugin.prototype.cleanup = function () {
170
+ this.assertMetaMask().cleanup();
171
+ };
172
+ /**
173
+ * @inheritdoc
174
+ */
175
+ Web3ConnectorPlugin.prototype.setCustomProvider = function (rpcUrl, privateKey) {
176
+ this.assertMetaMask().setCustomProvider(rpcUrl, privateKey);
177
+ };
178
+ /**
179
+ * @inheritdoc
180
+ */
181
+ Web3ConnectorPlugin.prototype.getSigner = function () {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ return __generator(this, function (_a) {
184
+ return [2 /*return*/, this.assertMetaMask().getSigner()];
185
+ });
186
+ });
187
+ };
188
+ /**
189
+ * @inheritdoc
190
+ */
191
+ Web3ConnectorPlugin.prototype.getProvider = function () {
192
+ return __awaiter(this, void 0, void 0, function () {
193
+ return __generator(this, function (_a) {
194
+ return [2 /*return*/, this.assertMetaMask().getProvider()];
195
+ });
196
+ });
197
+ };
198
+ /**
199
+ * @inheritdoc
200
+ */
201
+ Web3ConnectorPlugin.prototype.generatePassword = function (signature) {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ return __generator(this, function (_a) {
204
+ return [2 /*return*/, this.assertMetaMask().generatePassword(signature)];
205
+ });
206
+ });
207
+ };
208
+ /**
209
+ * @inheritdoc
210
+ */
211
+ Web3ConnectorPlugin.prototype.verifySignature = function (message, signature) {
212
+ return __awaiter(this, void 0, void 0, function () {
213
+ return __generator(this, function (_a) {
214
+ return [2 /*return*/, this.assertMetaMask().verifySignature(message, signature)];
215
+ });
216
+ });
217
+ };
218
+ // === WEB3 SIGNER METHODS ===
219
+ /**
220
+ * Creates a new Web3 signing credential
221
+ * CONSISTENT with normal Web3 approach
222
+ */
223
+ Web3ConnectorPlugin.prototype.createSigningCredential = function (address) {
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var conn, error_1;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0:
229
+ _a.trys.push([0, 4, , 5]);
230
+ conn = this.assertMetaMask();
231
+ if (!(typeof conn.createSigningCredential === "function")) return [3 /*break*/, 2];
232
+ return [4 /*yield*/, conn.createSigningCredential(address)];
233
+ case 1: return [2 /*return*/, _a.sent()];
234
+ case 2: return [4 /*yield*/, this.assertSigner().createSigningCredential(address)];
235
+ case 3: return [2 /*return*/, _a.sent()];
236
+ case 4:
237
+ error_1 = _a.sent();
238
+ console.error("Error creating Web3 signing credential: ".concat(error_1.message));
239
+ throw error_1;
240
+ case 5: return [2 /*return*/];
241
+ }
242
+ });
243
+ });
244
+ };
245
+ /**
246
+ * Creates an authenticator function for Web3 signing
247
+ */
248
+ Web3ConnectorPlugin.prototype.createAuthenticator = function (address) {
249
+ try {
250
+ var conn = this.assertMetaMask();
251
+ if (typeof conn.createAuthenticator === "function") {
252
+ return conn.createAuthenticator(address);
253
+ }
254
+ return this.assertSigner().createAuthenticator(address);
255
+ }
256
+ catch (error) {
257
+ console.error("Error creating Web3 authenticator: ".concat(error.message));
258
+ throw error;
259
+ }
260
+ };
261
+ /**
262
+ * Creates a derived key pair from Web3 credential
263
+ */
264
+ Web3ConnectorPlugin.prototype.createDerivedKeyPair = function (address, extra) {
265
+ return __awaiter(this, void 0, void 0, function () {
266
+ var conn, error_2;
267
+ return __generator(this, function (_a) {
268
+ switch (_a.label) {
269
+ case 0:
270
+ _a.trys.push([0, 4, , 5]);
271
+ conn = this.assertMetaMask();
272
+ if (!(typeof conn.createDerivedKeyPair === "function")) return [3 /*break*/, 2];
273
+ return [4 /*yield*/, conn.createDerivedKeyPair(address, extra)];
274
+ case 1: return [2 /*return*/, _a.sent()];
275
+ case 2: return [4 /*yield*/, this.assertSigner().createDerivedKeyPair(address, extra)];
276
+ case 3: return [2 /*return*/, _a.sent()];
277
+ case 4:
278
+ error_2 = _a.sent();
279
+ console.error("Error creating derived key pair: ".concat(error_2.message));
280
+ throw error_2;
281
+ case 5: return [2 /*return*/];
282
+ }
283
+ });
284
+ });
285
+ };
286
+ /**
287
+ * Signs data with derived keys after Web3 verification
288
+ */
289
+ Web3ConnectorPlugin.prototype.signWithDerivedKeys = function (data, address, extra) {
290
+ return __awaiter(this, void 0, void 0, function () {
291
+ var conn, error_3;
292
+ return __generator(this, function (_a) {
293
+ switch (_a.label) {
294
+ case 0:
295
+ _a.trys.push([0, 4, , 5]);
296
+ conn = this.assertMetaMask();
297
+ if (!(typeof conn.signWithDerivedKeys === "function")) return [3 /*break*/, 2];
298
+ return [4 /*yield*/, conn.signWithDerivedKeys(data, address, extra)];
299
+ case 1: return [2 /*return*/, _a.sent()];
300
+ case 2: return [4 /*yield*/, this.assertSigner().signWithDerivedKeys(data, address, extra)];
301
+ case 3: return [2 /*return*/, _a.sent()];
302
+ case 4:
303
+ error_3 = _a.sent();
304
+ console.error("Error signing with derived keys: ".concat(error_3.message));
305
+ throw error_3;
306
+ case 5: return [2 /*return*/];
307
+ }
308
+ });
309
+ });
310
+ };
311
+ /**
312
+ * Get signing credential by address
313
+ */
314
+ Web3ConnectorPlugin.prototype.getSigningCredential = function (address) {
315
+ var conn = this.assertMetaMask();
316
+ if (typeof conn.getSigningCredential === "function") {
317
+ return conn.getSigningCredential(address);
318
+ }
319
+ return this.assertSigner().getCredential(address);
320
+ };
321
+ /**
322
+ * List all signing credentials
323
+ */
324
+ Web3ConnectorPlugin.prototype.listSigningCredentials = function () {
325
+ var conn = this.assertMetaMask();
326
+ if (typeof conn.listSigningCredentials === "function") {
327
+ return conn.listSigningCredentials();
328
+ }
329
+ return this.assertSigner().listCredentials();
330
+ };
331
+ /**
332
+ * Remove a signing credential
333
+ */
334
+ Web3ConnectorPlugin.prototype.removeSigningCredential = function (address) {
335
+ var conn = this.assertMetaMask();
336
+ if (typeof conn.removeSigningCredential === "function") {
337
+ return conn.removeSigningCredential(address);
338
+ }
339
+ return this.assertSigner().removeCredential(address);
340
+ };
341
+ // === CONSISTENCY METHODS ===
342
+ /**
343
+ * Creates a Gun user from Web3 signing credential
344
+ * This ensures the SAME user is created as with normal approach
345
+ */
346
+ Web3ConnectorPlugin.prototype.createGunUserFromSigningCredential = function (address) {
347
+ return __awaiter(this, void 0, void 0, function () {
348
+ var conn, result_1, core, authResult, result, error_4;
349
+ return __generator(this, function (_a) {
350
+ switch (_a.label) {
351
+ case 0:
352
+ _a.trys.push([0, 5, , 6]);
353
+ console.log("\uD83D\uDD27 createGunUserFromSigningCredential called with address:", address);
354
+ conn = this.assertMetaMask();
355
+ if (!(typeof conn.createGunUserFromSigningCredential === "function")) return [3 /*break*/, 2];
356
+ console.log("\uD83D\uDD27 Using connector's createGunUserFromSigningCredential");
357
+ return [4 /*yield*/, conn.createGunUserFromSigningCredential(address)];
358
+ case 1:
359
+ result_1 = _a.sent();
360
+ console.log("\uD83D\uDD27 Connector result:", result_1);
361
+ return [2 /*return*/, result_1];
362
+ case 2:
363
+ console.log("\uD83D\uDD27 Using fallback createGunUser");
364
+ core = this.assertInitialized();
365
+ // FIX: Use deterministic approach - try to authenticate first, then create if needed
366
+ console.log("\uD83D\uDD27 Attempting authentication with deterministic pair");
367
+ return [4 /*yield*/, this.assertSigner().authenticateWithExistingPair(address, core.gun)];
368
+ case 3:
369
+ authResult = _a.sent();
370
+ if (authResult.success) {
371
+ console.log("\uD83D\uDD27 Authentication successful with existing user");
372
+ return [2 /*return*/, authResult];
373
+ }
374
+ console.log("\uD83D\uDD27 Authentication failed, creating new user");
375
+ return [4 /*yield*/, this.assertSigner().createGunUser(address, core.gun)];
376
+ case 4:
377
+ result = _a.sent();
378
+ console.log("\uD83D\uDD27 User creation result:", result);
379
+ return [2 /*return*/, result];
380
+ case 5:
381
+ error_4 = _a.sent();
382
+ console.error("Error creating Gun user from Web3 signing credential: ".concat(error_4.message));
383
+ throw error_4;
384
+ case 6: return [2 /*return*/];
385
+ }
386
+ });
387
+ });
388
+ };
389
+ /**
390
+ * Get the Gun user public key for a signing credential
391
+ */
392
+ Web3ConnectorPlugin.prototype.getGunUserPubFromSigningCredential = function (address) {
393
+ return __awaiter(this, void 0, void 0, function () {
394
+ var conn;
395
+ return __generator(this, function (_a) {
396
+ switch (_a.label) {
397
+ case 0:
398
+ conn = this.assertMetaMask();
399
+ if (!(typeof conn.getGunUserPubFromSigningCredential === "function")) return [3 /*break*/, 2];
400
+ return [4 /*yield*/, conn.getGunUserPubFromSigningCredential(address)];
401
+ case 1: return [2 /*return*/, _a.sent()];
402
+ case 2: return [4 /*yield*/, this.assertSigner().getGunUserPub(address)];
403
+ case 3: return [2 /*return*/, _a.sent()];
404
+ }
405
+ });
406
+ });
407
+ };
408
+ /**
409
+ * Get the password (for consistency checking)
410
+ */
411
+ Web3ConnectorPlugin.prototype.getPassword = function (address) {
412
+ var conn = this.assertMetaMask();
413
+ if (typeof conn.getPassword === "function") {
414
+ return conn.getPassword(address);
415
+ }
416
+ return this.assertSigner().getPassword(address);
417
+ };
418
+ /**
419
+ * Verify consistency between oneshot and normal approaches
420
+ * This ensures both approaches create the same Gun user
421
+ */
422
+ Web3ConnectorPlugin.prototype.verifyConsistency = function (address, expectedUserPub) {
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ var conn, error_5;
425
+ return __generator(this, function (_a) {
426
+ switch (_a.label) {
427
+ case 0:
428
+ _a.trys.push([0, 4, , 5]);
429
+ conn = this.assertMetaMask();
430
+ if (!(typeof conn.verifyConsistency === "function")) return [3 /*break*/, 2];
431
+ return [4 /*yield*/, conn.verifyConsistency(address, expectedUserPub)];
432
+ case 1: return [2 /*return*/, _a.sent()];
433
+ case 2: return [4 /*yield*/, this.assertSigner().verifyConsistency(address, expectedUserPub)];
434
+ case 3: return [2 /*return*/, _a.sent()];
435
+ case 4:
436
+ error_5 = _a.sent();
437
+ console.error("Error verifying Web3 consistency: ".concat(error_5.message));
438
+ return [2 /*return*/, { consistent: false }];
439
+ case 5: return [2 /*return*/];
440
+ }
441
+ });
442
+ });
443
+ };
444
+ /**
445
+ * Complete oneshot workflow that creates the SAME Gun user as normal approach
446
+ * This is the recommended method for oneshot signing with full consistency
447
+ */
448
+ Web3ConnectorPlugin.prototype.setupConsistentOneshotSigning = function (address) {
449
+ return __awaiter(this, void 0, void 0, function () {
450
+ var conn, credential, authenticator, gunUser, error_6;
451
+ return __generator(this, function (_a) {
452
+ switch (_a.label) {
453
+ case 0:
454
+ _a.trys.push([0, 5, , 6]);
455
+ conn = this.assertMetaMask();
456
+ if (!(typeof conn.setupConsistentOneshotSigning === "function")) return [3 /*break*/, 2];
457
+ return [4 /*yield*/, conn.setupConsistentOneshotSigning(address)];
458
+ case 1: return [2 /*return*/, _a.sent()];
459
+ case 2: return [4 /*yield*/, this.createSigningCredential(address)];
460
+ case 3:
461
+ credential = _a.sent();
462
+ authenticator = this.createAuthenticator(address);
463
+ return [4 /*yield*/, this.createGunUserFromSigningCredential(address)];
464
+ case 4:
465
+ gunUser = _a.sent();
466
+ return [2 /*return*/, {
467
+ credential: credential,
468
+ authenticator: authenticator,
469
+ gunUser: gunUser,
470
+ username: address,
471
+ password: "web3-generated-password",
472
+ }];
473
+ case 5:
474
+ error_6 = _a.sent();
475
+ console.error("Error setting up consistent Web3 oneshot signing: ".concat(error_6.message));
476
+ throw error_6;
477
+ case 6: return [2 /*return*/];
478
+ }
479
+ });
480
+ });
481
+ };
482
+ // === EXISTING METHODS ===
483
+ /**
484
+ * Login con Web3
485
+ * @param address - Indirizzo Ethereum
486
+ * @returns {Promise<AuthResult>} Risultato dell'autenticazione
487
+ * @description Autentica l'utente usando le credenziali del wallet Web3 dopo la verifica della firma
488
+ */
489
+ Web3ConnectorPlugin.prototype.login = function (address) {
490
+ return __awaiter(this, void 0, void 0, function () {
491
+ var core, existingCredential, gunUser_1, loginResult_1, gunUser, loginResult, error_7, errorType, errorCode, errorMessage;
492
+ var _a, _b;
493
+ return __generator(this, function (_c) {
494
+ switch (_c.label) {
495
+ case 0:
496
+ _c.trys.push([0, 4, , 5]);
497
+ core = this.assertInitialized();
498
+ if (!address) {
499
+ throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 login");
500
+ }
501
+ if (!this.isAvailable()) {
502
+ throw createError(ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
503
+ }
504
+ console.log("\uD83D\uDD27 Web3 login - starting login for address:", address);
505
+ existingCredential = this.getSigningCredential(address);
506
+ if (!existingCredential) return [3 /*break*/, 2];
507
+ console.log("\uD83D\uDD27 Web3 login - found existing credential, using it");
508
+ return [4 /*yield*/, this.createGunUserFromSigningCredential(address)];
509
+ case 1:
510
+ gunUser_1 = _c.sent();
511
+ console.log("\uD83D\uDD27 Web3 login - existing credential result:", gunUser_1);
512
+ if (gunUser_1.success && gunUser_1.userPub) {
513
+ // Set authentication method to web3
514
+ core.setAuthMethod("web3");
515
+ loginResult_1 = {
516
+ success: true,
517
+ user: {
518
+ userPub: gunUser_1.userPub,
519
+ username: address,
520
+ },
521
+ userPub: gunUser_1.userPub,
522
+ };
523
+ console.log("\uD83D\uDD27 Web3 login - returning result:", {
524
+ success: loginResult_1.success,
525
+ userPub: loginResult_1.userPub
526
+ ? loginResult_1.userPub.slice(0, 8) + "..."
527
+ : "null",
528
+ username: (_a = loginResult_1.user) === null || _a === void 0 ? void 0 : _a.username,
529
+ });
530
+ // Emit login event
531
+ core.emit("auth:login", {
532
+ userPub: gunUser_1.userPub || "",
533
+ username: address,
534
+ method: "web3",
535
+ });
536
+ return [2 /*return*/, loginResult_1];
537
+ }
538
+ _c.label = 2;
539
+ case 2:
540
+ // If no existing credential or it failed, create a new one (for first-time login)
541
+ console.log("\uD83D\uDD27 Web3 login - no existing credential, creating new one");
542
+ return [4 /*yield*/, this.setupConsistentOneshotSigning(address)];
543
+ case 3:
544
+ gunUser = (_c.sent()).gunUser;
545
+ console.log("\uD83D\uDD27 Web3 login - setupConsistentOneshotSigning result:", {
546
+ gunUser: gunUser,
547
+ address: address,
548
+ });
549
+ if (!gunUser.success) {
550
+ throw createError(ErrorType.AUTHENTICATION, "WEB3_LOGIN_FAILED", gunUser.error || "Failed to log in with Web3 credentials");
551
+ }
552
+ console.log("\uD83D\uDD27 Web3 login - gunUser success, userPub:", gunUser.userPub ? gunUser.userPub.slice(0, 8) + "..." : "null");
553
+ // Set authentication method to web3
554
+ core.setAuthMethod("web3");
555
+ loginResult = {
556
+ success: true,
557
+ user: {
558
+ userPub: gunUser.userPub,
559
+ username: address,
560
+ },
561
+ userPub: gunUser.userPub,
562
+ };
563
+ console.log("\uD83D\uDD27 Web3 login - returning result:", {
564
+ success: loginResult.success,
565
+ userPub: loginResult.userPub
566
+ ? loginResult.userPub.slice(0, 8) + "..."
567
+ : "null",
568
+ username: (_b = loginResult.user) === null || _b === void 0 ? void 0 : _b.username,
569
+ });
570
+ // Emit login event
571
+ core.emit("auth:login", {
572
+ userPub: gunUser.userPub || "",
573
+ username: address,
574
+ method: "web3",
575
+ });
576
+ return [2 /*return*/, loginResult];
577
+ case 4:
578
+ error_7 = _c.sent();
579
+ errorType = (error_7 === null || error_7 === void 0 ? void 0 : error_7.type) || ErrorType.AUTHENTICATION;
580
+ errorCode = (error_7 === null || error_7 === void 0 ? void 0 : error_7.code) || "WEB3_LOGIN_ERROR";
581
+ errorMessage = (error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || "Unknown error during Web3 login";
582
+ ErrorHandler.handle(errorType, errorCode, errorMessage, error_7);
583
+ return [2 /*return*/, { success: false, error: errorMessage }];
584
+ case 5: return [2 /*return*/];
585
+ }
586
+ });
587
+ });
588
+ };
589
+ /**
590
+ * Register new user with Web3 wallet
591
+ * @param address - Ethereum address
592
+ * @returns {Promise<SignUpResult>} Registration result
593
+ */
594
+ Web3ConnectorPlugin.prototype.signUp = function (address) {
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ var core, gunUser, signupResult, error_8, errorType, errorCode, errorMessage;
597
+ return __generator(this, function (_a) {
598
+ switch (_a.label) {
599
+ case 0:
600
+ _a.trys.push([0, 2, , 3]);
601
+ core = this.assertInitialized();
602
+ if (!address) {
603
+ throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 registration");
604
+ }
605
+ if (!this.isAvailable()) {
606
+ throw createError(ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
607
+ }
608
+ return [4 /*yield*/, this.setupConsistentOneshotSigning(address)];
609
+ case 1:
610
+ gunUser = (_a.sent()).gunUser;
611
+ if (!gunUser.success) {
612
+ throw createError(ErrorType.AUTHENTICATION, "WEB3_SIGNUP_FAILED", gunUser.error || "Failed to sign up with Web3 credentials");
613
+ }
614
+ // Set authentication method to web3
615
+ core.setAuthMethod("web3");
616
+ signupResult = {
617
+ success: true,
618
+ user: {
619
+ userPub: gunUser.userPub,
620
+ username: address,
621
+ },
622
+ userPub: gunUser.userPub,
623
+ };
624
+ return [2 /*return*/, signupResult];
625
+ case 2:
626
+ error_8 = _a.sent();
627
+ errorType = (error_8 === null || error_8 === void 0 ? void 0 : error_8.type) || ErrorType.AUTHENTICATION;
628
+ errorCode = (error_8 === null || error_8 === void 0 ? void 0 : error_8.code) || "WEB3_SIGNUP_ERROR";
629
+ errorMessage = (error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || "Unknown error during Web3 registration";
630
+ ErrorHandler.handle(errorType, errorCode, errorMessage, error_8);
631
+ return [2 /*return*/, { success: false, error: errorMessage }];
632
+ case 3: return [2 /*return*/];
633
+ }
634
+ });
635
+ });
636
+ };
637
+ return Web3ConnectorPlugin;
638
+ }(BasePlugin));
639
+ export { Web3ConnectorPlugin };