shogun-core 6.2.4 → 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 +138979 -146789
  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 -392
  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
@@ -1,455 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Web3ConnectorPlugin = void 0;
4
- const base_1 = require("../base");
5
- const web3Connector_1 = require("./web3Connector");
6
- const web3Signer_1 = require("./web3Signer");
7
- const errorHandler_1 = require("../../utils/errorHandler");
8
- /**
9
- * Plugin per la gestione delle funzionalità Web3 in ShogunCore
10
- */
11
- class Web3ConnectorPlugin extends base_1.BasePlugin {
12
- constructor() {
13
- super(...arguments);
14
- this.name = "web3";
15
- this.version = "1.0.0";
16
- this.description = "Provides Ethereum wallet connection and authentication for ShogunCore";
17
- this.Web3 = null;
18
- this.signer = null;
19
- }
20
- /**
21
- * @inheritdoc
22
- */
23
- initialize(core) {
24
- super.initialize(core);
25
- // Inizializziamo il modulo Web3
26
- this.Web3 = new web3Connector_1.Web3Connector();
27
- this.signer = new web3Signer_1.Web3Signer(this.Web3);
28
- // Rimuovo i console.log superflui
29
- }
30
- /**
31
- * @inheritdoc
32
- */
33
- destroy() {
34
- if (this.Web3) {
35
- this.Web3.cleanup();
36
- }
37
- this.Web3 = null;
38
- this.signer = null;
39
- super.destroy();
40
- // Linea 50
41
- }
42
- /**
43
- * Assicura che il modulo Web3 sia inizializzato
44
- * @private
45
- */
46
- assertMetaMask() {
47
- this.assertInitialized();
48
- if (!this.Web3) {
49
- throw new Error("Web3 module not initialized");
50
- }
51
- return this.Web3;
52
- }
53
- /**
54
- * Assicura che il signer sia inizializzato
55
- * @private
56
- */
57
- assertSigner() {
58
- this.assertInitialized();
59
- if (!this.signer) {
60
- throw new Error("Web3 signer not initialized");
61
- }
62
- return this.signer;
63
- }
64
- /**
65
- * @inheritdoc
66
- */
67
- isAvailable() {
68
- return this.assertMetaMask().isAvailable();
69
- }
70
- /**
71
- * @inheritdoc
72
- */
73
- async connectMetaMask() {
74
- return this.assertMetaMask().connectMetaMask();
75
- }
76
- /**
77
- * @inheritdoc
78
- */
79
- async generateCredentials(address) {
80
- // Rimuovo i console.log superflui
81
- return this.assertMetaMask().generateCredentials(address);
82
- }
83
- /**
84
- * @inheritdoc
85
- */
86
- cleanup() {
87
- this.assertMetaMask().cleanup();
88
- }
89
- /**
90
- * @inheritdoc
91
- */
92
- setCustomProvider(rpcUrl, privateKey) {
93
- this.assertMetaMask().setCustomProvider(rpcUrl, privateKey);
94
- }
95
- /**
96
- * @inheritdoc
97
- */
98
- async getSigner() {
99
- return this.assertMetaMask().getSigner();
100
- }
101
- /**
102
- * @inheritdoc
103
- */
104
- async getProvider() {
105
- return this.assertMetaMask().getProvider();
106
- }
107
- /**
108
- * @inheritdoc
109
- */
110
- async generatePassword(signature) {
111
- return this.assertMetaMask().generatePassword(signature);
112
- }
113
- /**
114
- * @inheritdoc
115
- */
116
- async verifySignature(message, signature) {
117
- return this.assertMetaMask().verifySignature(message, signature);
118
- }
119
- // === WEB3 SIGNER METHODS ===
120
- /**
121
- * Creates a new Web3 signing credential
122
- * CONSISTENT with normal Web3 approach
123
- */
124
- async createSigningCredential(address) {
125
- try {
126
- const conn = this.assertMetaMask();
127
- if (typeof conn.createSigningCredential === "function") {
128
- return await conn.createSigningCredential(address);
129
- }
130
- return await this.assertSigner().createSigningCredential(address);
131
- }
132
- catch (error) {
133
- console.error(`Error creating Web3 signing credential: ${error.message}`);
134
- throw error;
135
- }
136
- }
137
- /**
138
- * Creates an authenticator function for Web3 signing
139
- */
140
- createAuthenticator(address) {
141
- try {
142
- const conn = this.assertMetaMask();
143
- if (typeof conn.createAuthenticator === "function") {
144
- return conn.createAuthenticator(address);
145
- }
146
- return this.assertSigner().createAuthenticator(address);
147
- }
148
- catch (error) {
149
- console.error(`Error creating Web3 authenticator: ${error.message}`);
150
- throw error;
151
- }
152
- }
153
- /**
154
- * Creates a derived key pair from Web3 credential
155
- */
156
- async createDerivedKeyPair(address, extra) {
157
- try {
158
- const conn = this.assertMetaMask();
159
- if (typeof conn.createDerivedKeyPair === "function") {
160
- return await conn.createDerivedKeyPair(address, extra);
161
- }
162
- return await this.assertSigner().createDerivedKeyPair(address, extra);
163
- }
164
- catch (error) {
165
- console.error(`Error creating derived key pair: ${error.message}`);
166
- throw error;
167
- }
168
- }
169
- /**
170
- * Signs data with derived keys after Web3 verification
171
- */
172
- async signWithDerivedKeys(data, address, extra) {
173
- try {
174
- const conn = this.assertMetaMask();
175
- if (typeof conn.signWithDerivedKeys === "function") {
176
- return await conn.signWithDerivedKeys(data, address, extra);
177
- }
178
- return await this.assertSigner().signWithDerivedKeys(data, address, extra);
179
- }
180
- catch (error) {
181
- console.error(`Error signing with derived keys: ${error.message}`);
182
- throw error;
183
- }
184
- }
185
- /**
186
- * Get signing credential by address
187
- */
188
- getSigningCredential(address) {
189
- const conn = this.assertMetaMask();
190
- if (typeof conn.getSigningCredential === "function") {
191
- return conn.getSigningCredential(address);
192
- }
193
- return this.assertSigner().getCredential(address);
194
- }
195
- /**
196
- * List all signing credentials
197
- */
198
- listSigningCredentials() {
199
- const conn = this.assertMetaMask();
200
- if (typeof conn.listSigningCredentials === "function") {
201
- return conn.listSigningCredentials();
202
- }
203
- return this.assertSigner().listCredentials();
204
- }
205
- /**
206
- * Remove a signing credential
207
- */
208
- removeSigningCredential(address) {
209
- const conn = this.assertMetaMask();
210
- if (typeof conn.removeSigningCredential === "function") {
211
- return conn.removeSigningCredential(address);
212
- }
213
- return this.assertSigner().removeCredential(address);
214
- }
215
- // === CONSISTENCY METHODS ===
216
- /**
217
- * Creates a Gun user from Web3 signing credential
218
- * This ensures the SAME user is created as with normal approach
219
- */
220
- async createGunUserFromSigningCredential(address) {
221
- try {
222
- console.log(`🔧 createGunUserFromSigningCredential called with address:`, address);
223
- const conn = this.assertMetaMask();
224
- if (typeof conn.createGunUserFromSigningCredential === "function") {
225
- console.log(`🔧 Using connector's createGunUserFromSigningCredential`);
226
- const result = await conn.createGunUserFromSigningCredential(address);
227
- console.log(`🔧 Connector result:`, result);
228
- return result;
229
- }
230
- console.log(`🔧 Using fallback createGunUser`);
231
- const core = this.assertInitialized();
232
- // FIX: Use deterministic approach - try to authenticate first, then create if needed
233
- console.log(`🔧 Attempting authentication with deterministic pair`);
234
- const authResult = await this.assertSigner().authenticateWithExistingPair(address, core.gun);
235
- if (authResult.success) {
236
- console.log(`🔧 Authentication successful with existing user`);
237
- return authResult;
238
- }
239
- console.log(`🔧 Authentication failed, creating new user`);
240
- // If authentication failed, create new user
241
- const result = await this.assertSigner().createGunUser(address, core.gun);
242
- console.log(`🔧 User creation result:`, result);
243
- return result;
244
- }
245
- catch (error) {
246
- console.error(`Error creating Gun user from Web3 signing credential: ${error.message}`);
247
- throw error;
248
- }
249
- }
250
- /**
251
- * Get the Gun user public key for a signing credential
252
- */
253
- async getGunUserPubFromSigningCredential(address) {
254
- const conn = this.assertMetaMask();
255
- if (typeof conn.getGunUserPubFromSigningCredential === "function") {
256
- return await conn.getGunUserPubFromSigningCredential(address);
257
- }
258
- return await this.assertSigner().getGunUserPub(address);
259
- }
260
- /**
261
- * Get the password (for consistency checking)
262
- */
263
- getPassword(address) {
264
- const conn = this.assertMetaMask();
265
- if (typeof conn.getPassword === "function") {
266
- return conn.getPassword(address);
267
- }
268
- return this.assertSigner().getPassword(address);
269
- }
270
- /**
271
- * Verify consistency between oneshot and normal approaches
272
- * This ensures both approaches create the same Gun user
273
- */
274
- async verifyConsistency(address, expectedUserPub) {
275
- try {
276
- const conn = this.assertMetaMask();
277
- if (typeof conn.verifyConsistency === "function") {
278
- return await conn.verifyConsistency(address, expectedUserPub);
279
- }
280
- return await this.assertSigner().verifyConsistency(address, expectedUserPub);
281
- }
282
- catch (error) {
283
- console.error(`Error verifying Web3 consistency: ${error.message}`);
284
- return { consistent: false };
285
- }
286
- }
287
- /**
288
- * Complete oneshot workflow that creates the SAME Gun user as normal approach
289
- * This is the recommended method for oneshot signing with full consistency
290
- */
291
- async setupConsistentOneshotSigning(address) {
292
- try {
293
- const conn = this.assertMetaMask();
294
- if (typeof conn.setupConsistentOneshotSigning === "function") {
295
- return await conn.setupConsistentOneshotSigning(address);
296
- }
297
- // Fallback implementation when connector doesn't have the method
298
- const credential = await this.createSigningCredential(address);
299
- const authenticator = this.createAuthenticator(address);
300
- const gunUser = await this.createGunUserFromSigningCredential(address);
301
- return {
302
- credential,
303
- authenticator,
304
- gunUser,
305
- username: address,
306
- password: "web3-generated-password",
307
- };
308
- }
309
- catch (error) {
310
- console.error(`Error setting up consistent Web3 oneshot signing: ${error.message}`);
311
- throw error;
312
- }
313
- }
314
- // === EXISTING METHODS ===
315
- /**
316
- * Login con Web3
317
- * @param address - Indirizzo Ethereum
318
- * @returns {Promise<AuthResult>} Risultato dell'autenticazione
319
- * @description Autentica l'utente usando le credenziali del wallet Web3 dopo la verifica della firma
320
- */
321
- async login(address) {
322
- try {
323
- const core = this.assertInitialized();
324
- if (!address) {
325
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 login");
326
- }
327
- if (!this.isAvailable()) {
328
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
329
- }
330
- console.log(`🔧 Web3 login - starting login for address:`, address);
331
- // FIX: Use deterministic pair instead of generating new credentials
332
- // Get the existing credential if available
333
- const existingCredential = this.getSigningCredential(address);
334
- if (existingCredential) {
335
- console.log(`🔧 Web3 login - found existing credential, using it`);
336
- // Use existing credential to get Gun user
337
- const gunUser = await this.createGunUserFromSigningCredential(address);
338
- console.log(`🔧 Web3 login - existing credential result:`, gunUser);
339
- if (gunUser.success && gunUser.userPub) {
340
- // Set authentication method to web3
341
- core.setAuthMethod("web3");
342
- const loginResult = {
343
- success: true,
344
- user: {
345
- userPub: gunUser.userPub,
346
- username: address,
347
- },
348
- userPub: gunUser.userPub,
349
- };
350
- console.log(`🔧 Web3 login - returning result:`, {
351
- success: loginResult.success,
352
- userPub: loginResult.userPub
353
- ? loginResult.userPub.slice(0, 8) + "..."
354
- : "null",
355
- username: loginResult.user?.username,
356
- });
357
- // Emit login event
358
- core.emit("auth:login", {
359
- userPub: gunUser.userPub || "",
360
- username: address,
361
- method: "web3",
362
- });
363
- return loginResult;
364
- }
365
- }
366
- // If no existing credential or it failed, create a new one (for first-time login)
367
- console.log(`🔧 Web3 login - no existing credential, creating new one`);
368
- // Use setupConsistentOneshotSigning for first-time login
369
- const { gunUser } = await this.setupConsistentOneshotSigning(address);
370
- console.log(`🔧 Web3 login - setupConsistentOneshotSigning result:`, {
371
- gunUser,
372
- address,
373
- });
374
- if (!gunUser.success) {
375
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "WEB3_LOGIN_FAILED", gunUser.error || "Failed to log in with Web3 credentials");
376
- }
377
- console.log(`🔧 Web3 login - gunUser success, userPub:`, gunUser.userPub ? gunUser.userPub.slice(0, 8) + "..." : "null");
378
- // Set authentication method to web3
379
- core.setAuthMethod("web3");
380
- // Return success result
381
- const loginResult = {
382
- success: true,
383
- user: {
384
- userPub: gunUser.userPub,
385
- username: address,
386
- },
387
- userPub: gunUser.userPub,
388
- };
389
- console.log(`🔧 Web3 login - returning result:`, {
390
- success: loginResult.success,
391
- userPub: loginResult.userPub
392
- ? loginResult.userPub.slice(0, 8) + "..."
393
- : "null",
394
- username: loginResult.user?.username,
395
- });
396
- // Emit login event
397
- core.emit("auth:login", {
398
- userPub: gunUser.userPub || "",
399
- username: address,
400
- method: "web3",
401
- });
402
- return loginResult;
403
- }
404
- catch (error) {
405
- // Handle both ShogunError and generic errors
406
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
407
- const errorCode = error?.code || "WEB3_LOGIN_ERROR";
408
- const errorMessage = error?.message || "Unknown error during Web3 login";
409
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
410
- return { success: false, error: errorMessage };
411
- }
412
- }
413
- /**
414
- * Register new user with Web3 wallet
415
- * @param address - Ethereum address
416
- * @returns {Promise<SignUpResult>} Registration result
417
- */
418
- async signUp(address) {
419
- try {
420
- const core = this.assertInitialized();
421
- if (!address) {
422
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 registration");
423
- }
424
- if (!this.isAvailable()) {
425
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
426
- }
427
- // Use setupConsistentOneshotSigning for signup
428
- const { gunUser } = await this.setupConsistentOneshotSigning(address);
429
- if (!gunUser.success) {
430
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "WEB3_SIGNUP_FAILED", gunUser.error || "Failed to sign up with Web3 credentials");
431
- }
432
- // Set authentication method to web3
433
- core.setAuthMethod("web3");
434
- // Return success result
435
- const signupResult = {
436
- success: true,
437
- user: {
438
- userPub: gunUser.userPub,
439
- username: address,
440
- },
441
- userPub: gunUser.userPub,
442
- };
443
- return signupResult;
444
- }
445
- catch (error) {
446
- // Handle both ShogunError and generic errors
447
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
448
- const errorCode = error?.code || "WEB3_SIGNUP_ERROR";
449
- const errorMessage = error?.message || "Unknown error during Web3 registration";
450
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
451
- return { success: false, error: errorMessage };
452
- }
453
- }
454
- }
455
- exports.Web3ConnectorPlugin = Web3ConnectorPlugin;