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
@@ -1,196 +0,0 @@
1
- "use strict";
2
- /**
3
- * Esempio di utilizzo del CryptoIdentityManager
4
- * Mostra come generare le identità crypto
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.runCryptoIdentityExamples = runCryptoIdentityExamples;
8
- // Import SEA as side-effect to load it globally
9
- require("gun/sea");
10
- require("gun/lib/then");
11
- require("gun/axe");
12
- // Ensure Gun.SEA is available globally
13
- // In Node.js, SEA should attach to Gun.SEA or globalThis.SEA
14
- if (typeof window === "undefined") {
15
- // Node.js environment
16
- const GunModule = require("gun");
17
- if (GunModule && GunModule.SEA) {
18
- globalThis.Gun = GunModule;
19
- globalThis.SEA = GunModule.SEA;
20
- }
21
- }
22
- // Suppress expected Gun.js SEA verification errors globally
23
- // These errors are normal when verifying non-existent or corrupted data
24
- const originalLog = console.log;
25
- const originalError = console.error;
26
- let errorSuppressionActive = false;
27
- const suppressedLog = (...args) => {
28
- if (!errorSuppressionActive) {
29
- originalLog.apply(console, args);
30
- return;
31
- }
32
- const message = args.join(" ");
33
- // Suppress expected SEA verification errors
34
- if (message.includes("Signature did not match") ||
35
- message.includes("base64Text") ||
36
- message.includes("Could not decrypt") ||
37
- message.includes("Argument 'base64Text' is not Base64 encoded")) {
38
- return; // Suppress these expected errors
39
- }
40
- originalLog.apply(console, args);
41
- };
42
- const suppressedError = (...args) => {
43
- if (!errorSuppressionActive) {
44
- originalError.apply(console, args);
45
- return;
46
- }
47
- const message = args.join(" ");
48
- if (message.includes("Signature did not match") ||
49
- message.includes("base64Text") ||
50
- message.includes("Could not decrypt") ||
51
- message.includes("Argument 'base64Text' is not Base64 encoded")) {
52
- return;
53
- }
54
- originalError.apply(console, args);
55
- };
56
- // Enable error suppression
57
- errorSuppressionActive = true;
58
- console.log = suppressedLog;
59
- console.error = suppressedError;
60
- const index_1 = require("../index");
61
- // Esempio base di generazione identità
62
- async function basicIdentityExample() {
63
- console.log("🚀 Avvio esempio CryptoIdentityManager");
64
- // Assicurati che SEA sia disponibile
65
- if (!globalThis.SEA && !globalThis.Gun?.SEA) {
66
- await new Promise((resolve) => setTimeout(resolve, 100));
67
- }
68
- // Genera un SEA pair di esempio per il test
69
- // In un'app reale, questo verrebbe dall'autenticazione
70
- const SEA = globalThis.SEA || globalThis.Gun?.SEA;
71
- if (!SEA) {
72
- console.error("❌ SEA non disponibile. Assicurati che gun/sea sia importato.");
73
- return;
74
- }
75
- console.log("✅ SEA disponibile");
76
- // Genera un SEA pair di esempio
77
- const exampleUser = "example_user_" + Date.now();
78
- const examplePassword = "example_password";
79
- console.log(`🔐 Generazione SEA pair di esempio per: ${exampleUser}`);
80
- const seaPair = await SEA.pair();
81
- if (!seaPair) {
82
- console.error("❌ Impossibile generare SEA pair di esempio");
83
- return;
84
- }
85
- console.log("✅ SEA pair generato");
86
- // Inizializza CryptoIdentityManager
87
- const cryptoManager = new index_1.CryptoIdentityManager();
88
- // Genera le identità crypto
89
- console.log("🔐 Generazione delle identità crypto...");
90
- const generateResult = await cryptoManager.generateAllIdentities(exampleUser, seaPair);
91
- if (generateResult.success && generateResult.identities) {
92
- const identities = generateResult.identities;
93
- console.log("✅ Identità crypto generate con successo!");
94
- console.log("🔐 Identità crypto generate:");
95
- console.log("- RSA Key Pair:", !!identities.rsa);
96
- console.log("- AES Symmetric Key:", !!identities.aes);
97
- console.log("- Signal Protocol Identity:", !!identities.signal);
98
- console.log("- PGP Key Pair:", !!identities.pgp);
99
- console.log("- MLS Group:", !!identities.mls);
100
- console.log("- SFrame Key:", !!identities.sframe);
101
- console.log("- Created At:", new Date(identities.createdAt).toISOString());
102
- console.log("- Version:", identities.version);
103
- console.log("\nℹ️ Nota: Le identità generate dovranno essere salvate lato frontend se necessario.");
104
- // Esempio di come serializzare le identità per il salvataggio
105
- const identitiesJson = JSON.stringify(identities);
106
- console.log(`\n📦 Identità serializzate (${identitiesJson.length} caratteri)`);
107
- console.log("💡 Puoi criptare e salvare questa stringa usando SEA.encrypt() lato frontend");
108
- }
109
- else {
110
- console.warn("⚠️ Impossibile generare le identità crypto:", generateResult.error);
111
- }
112
- console.log("\n🎉 Esempio completato!");
113
- // Restore original console methods at the end
114
- errorSuppressionActive = false;
115
- console.log = originalLog;
116
- console.error = originalError;
117
- }
118
- // Esempio di rigenerazione delle identità
119
- async function regenerateIdentityExample() {
120
- console.log("\n🔄 Esempio di rigenerazione identità");
121
- const SEA = globalThis.SEA || globalThis.Gun?.SEA;
122
- if (!SEA) {
123
- console.error("❌ SEA non disponibile");
124
- return;
125
- }
126
- const exampleUser = "example_user_regenerate";
127
- const seaPair = await SEA.pair();
128
- const cryptoManager = new index_1.CryptoIdentityManager();
129
- console.log("🔐 Prima generazione...");
130
- const firstResult = await cryptoManager.generateAllIdentities(exampleUser, seaPair);
131
- if (firstResult.success && firstResult.identities) {
132
- console.log("✅ Prima generazione completata");
133
- console.log("- RSA:", !!firstResult.identities.rsa);
134
- console.log("- AES:", !!firstResult.identities.aes);
135
- }
136
- console.log("\n🔐 Seconda generazione (nuove identità)...");
137
- const secondResult = await cryptoManager.generateAllIdentities(exampleUser, seaPair);
138
- if (secondResult.success && secondResult.identities) {
139
- console.log("✅ Seconda generazione completata");
140
- console.log("- RSA:", !!secondResult.identities.rsa);
141
- console.log("- AES:", !!secondResult.identities.aes);
142
- console.log("ℹ️ Nota: Ogni generazione crea nuove identità uniche");
143
- }
144
- // Restore original console methods at the end
145
- errorSuppressionActive = false;
146
- console.log = originalLog;
147
- console.error = originalError;
148
- }
149
- // Esempio usando setupCryptoIdentities (wrapper)
150
- async function setupIdentityExample() {
151
- console.log("\n🔧 Esempio usando setupCryptoIdentities");
152
- const SEA = globalThis.SEA || globalThis.Gun?.SEA;
153
- if (!SEA) {
154
- console.error("❌ SEA non disponibile");
155
- return;
156
- }
157
- const exampleUser = "example_user_setup";
158
- const seaPair = await SEA.pair();
159
- const cryptoManager = new index_1.CryptoIdentityManager();
160
- console.log("🔐 Usando setupCryptoIdentities (wrapper)...");
161
- const result = await cryptoManager.setupCryptoIdentities(exampleUser, seaPair, false);
162
- if (result.success && result.identities) {
163
- console.log("✅ Identità generate usando setupCryptoIdentities");
164
- console.log("- RSA:", !!result.identities.rsa);
165
- console.log("- AES:", !!result.identities.aes);
166
- console.log("- Signal:", !!result.identities.signal);
167
- console.log("- PGP:", !!result.identities.pgp);
168
- console.log("- MLS:", !!result.identities.mls);
169
- console.log("- SFrame:", !!result.identities.sframe);
170
- }
171
- // Restore original console methods at the end
172
- errorSuppressionActive = false;
173
- console.log = originalLog;
174
- console.error = originalError;
175
- }
176
- // Funzione principale per eseguire gli esempi
177
- async function runCryptoIdentityExamples() {
178
- try {
179
- await basicIdentityExample();
180
- await regenerateIdentityExample();
181
- await setupIdentityExample();
182
- }
183
- catch (error) {
184
- console.error("❌ Errore durante l'esecuzione degli esempi:", error);
185
- }
186
- finally {
187
- // Always restore console methods
188
- errorSuppressionActive = false;
189
- console.log = originalLog;
190
- console.error = originalError;
191
- }
192
- }
193
- // Esegui gli esempi se il file viene eseguito direttamente
194
- if (typeof window === "undefined" && require.main === module) {
195
- runCryptoIdentityExamples();
196
- }
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // Simple crypto test that actually works
4
- const crypto_1 = require("../crypto");
5
- // Simple test function
6
- async function testCrypto() {
7
- try {
8
- console.log("🔐 Starting crypto test...");
9
- // Test 1: Random string generation
10
- console.log("\n1. Testing random string generation...");
11
- const randomStr = (0, crypto_1.randomString)("test-");
12
- console.log("✅ Random string:", randomStr);
13
- // Test 2: Hashing
14
- console.log("\n2. Testing hashing...");
15
- const hash = await (0, crypto_1.sha256Hash)({
16
- message: "Hello Crypto!",
17
- timestamp: Date.now(),
18
- });
19
- console.log("✅ SHA-256 hash:", hash.substring(0, 20) + "...");
20
- // Test 3: RSA key generation and encryption
21
- console.log("\n3. Testing RSA encryption...");
22
- const keyPair = await (0, crypto_1.generateKeyPair)();
23
- console.log("✅ RSA key pair generated");
24
- const publicKey = await (0, crypto_1.deserializePublicKey)(keyPair.publicKey);
25
- const privateKey = await (0, crypto_1.deserializePrivateKey)(keyPair.privateKey);
26
- const encryptedMessage = await (0, crypto_1.encrypt)("Secret RSA message", publicKey);
27
- const decryptedMessage = await (0, crypto_1.decrypt)(encryptedMessage, privateKey);
28
- console.log("✅ RSA encrypted:", encryptedMessage.substring(0, 30) + "...");
29
- console.log("✅ RSA decrypted:", decryptedMessage);
30
- // Test 4: AES symmetric encryption
31
- console.log("\n4. Testing AES symmetric encryption...");
32
- const symmetricKey = await (0, crypto_1.generateSymmetricKey)();
33
- const deserializedKey = await (0, crypto_1.deserializeSymmetricKey)(symmetricKey);
34
- const encryptedData = await (0, crypto_1.encryptWithSymmetricKey)("Secret AES message", deserializedKey);
35
- const decryptedData = await (0, crypto_1.decryptWithSymmetricKey)(encryptedData, deserializedKey);
36
- console.log("✅ AES encrypted:", encryptedData.ciphertext.substring(0, 30) + "...");
37
- console.log("✅ AES decrypted:", decryptedData);
38
- // Test 5: File encryption
39
- console.log("\n5. Testing file encryption...");
40
- const fileContent = "This is a secret file content for testing!";
41
- const password = "testPassword123";
42
- const encryptedFile = await (0, crypto_1.encryptTextFile)(fileContent, password, "test.txt");
43
- const decryptedFile = await (0, crypto_1.decryptTextFile)(encryptedFile, password);
44
- console.log("✅ File encrypted:", encryptedFile.fileName);
45
- console.log("✅ File decrypted:", decryptedFile.textContent);
46
- console.log("\n🎉 All crypto tests completed successfully!");
47
- return {
48
- success: true,
49
- tests: {
50
- randomString: randomStr,
51
- hash: hash.substring(0, 20) + "...",
52
- rsaEncryption: {
53
- encrypted: encryptedMessage.substring(0, 30) + "...",
54
- decrypted: decryptedMessage,
55
- },
56
- aesEncryption: {
57
- encrypted: encryptedData.ciphertext.substring(0, 30) + "...",
58
- decrypted: decryptedData,
59
- },
60
- fileEncryption: {
61
- fileName: encryptedFile.fileName,
62
- decrypted: decryptedFile.textContent,
63
- },
64
- },
65
- };
66
- }
67
- catch (error) {
68
- console.error("❌ Crypto test failed:", error);
69
- return {
70
- success: false,
71
- error: error instanceof Error ? error.message : "Unknown error",
72
- };
73
- }
74
- }
75
- // Run the test
76
- testCrypto()
77
- .then((result) => {
78
- console.log("\n📊 Final Result:");
79
- console.log(JSON.stringify(result, null, 2));
80
- })
81
- .catch((error) => {
82
- console.error("💥 Test execution failed:", error);
83
- });
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // Double Ratchet Protocol test
4
- const crypto_1 = require("../crypto");
5
- // Test Double Ratchet Protocol
6
- async function testDoubleRatchet() {
7
- try {
8
- console.log("🔄 Starting Double Ratchet Protocol test...");
9
- const result = await (0, crypto_1.demonstrateDoubleRatchet)();
10
- if (result.success) {
11
- console.log("✅ Double Ratchet Protocol test successful!");
12
- console.log("Messages exchanged:", result.messagesExchanged);
13
- console.log("Forward secrecy:", result.demonstration.forwardSecrecy);
14
- console.log("Out-of-order handling:", result.demonstration.outOfOrderHandling);
15
- console.log("DH ratcheting:", result.demonstration.dhRatcheting);
16
- console.log("Chain key updating:", result.demonstration.chainKeyUpdating);
17
- // Test individual functions
18
- console.log("\n🧪 Testing individual Double Ratchet functions...");
19
- // Test state serialization
20
- const aliceStateSerialized = result.aliceState;
21
- console.log("✅ Alice state serialized:", aliceStateSerialized.substring(0, 100) + "...");
22
- // Test conversation
23
- console.log("✅ Conversation messages:", result.conversation.length);
24
- result.conversation.forEach((msg, index) => {
25
- console.log(` Message ${index + 1}: ${msg.from} → Message #${msg.envelope.messageNumber}`);
26
- });
27
- }
28
- else {
29
- console.log("❌ Double Ratchet Protocol test failed");
30
- }
31
- return result;
32
- }
33
- catch (error) {
34
- console.error("❌ Double Ratchet Protocol test error:", error);
35
- return {
36
- success: false,
37
- error: error instanceof Error ? error.message : "Unknown error",
38
- };
39
- }
40
- }
41
- // Test interactive Double Ratchet messaging
42
- async function testInteractiveDoubleRatchet() {
43
- try {
44
- console.log("🔄 Starting Interactive Double Ratchet test...");
45
- // Initialize X3DH for shared secret
46
- const { initializeSignalUser, getSignalPublicKeyBundle, performSignalX3DHKeyExchange, } = await import("../crypto/signal-protocol.js");
47
- const alice = await initializeSignalUser("Alice");
48
- const bob = await initializeSignalUser("Bob");
49
- const bobBundle = await getSignalPublicKeyBundle(bob);
50
- const exchangeResult = await performSignalX3DHKeyExchange(alice, bobBundle);
51
- console.log("✅ X3DH key exchange completed");
52
- // Initialize Double Ratchet states
53
- const aliceState = await (0, crypto_1.initializeDoubleRatchet)(exchangeResult.masterSecret, true);
54
- const bobState = await (0, crypto_1.initializeDoubleRatchet)(exchangeResult.masterSecret, false);
55
- console.log("✅ Double Ratchet states initialized");
56
- // Test message exchange
57
- const messages = [
58
- "Hello Bob! This is our first Double Ratchet message! 🔒",
59
- "Hi Alice! The Double Ratchet is working perfectly! 🎉",
60
- "This is message 3 with forward secrecy! 🛡️",
61
- "And this is message 4 - each with a unique key! 🔑",
62
- ];
63
- const conversation = [];
64
- for (let i = 0; i < messages.length; i++) {
65
- const sender = i % 2 === 0 ? "Alice" : "Bob";
66
- const senderState = sender === "Alice" ? aliceState : bobState;
67
- const receiverState = sender === "Alice" ? bobState : aliceState;
68
- console.log(`\n📤 ${sender} sending message ${i + 1}: "${messages[i]}"`);
69
- // Encrypt
70
- const envelope = await (0, crypto_1.doubleRatchetEncrypt)(senderState, messages[i]);
71
- console.log(`✅ ${sender} encrypted message #${envelope.messageNumber}`);
72
- // Decrypt
73
- const decrypted = await (0, crypto_1.doubleRatchetDecrypt)(receiverState, envelope);
74
- console.log(`✅ ${sender === "Alice" ? "Bob" : "Alice"} decrypted: "${decrypted}"`);
75
- // Verify
76
- if (decrypted === messages[i]) {
77
- console.log(`✅ Message ${i + 1} verified successfully`);
78
- conversation.push({
79
- sender,
80
- receiver: sender === "Alice" ? "Bob" : "Alice",
81
- original: messages[i],
82
- decrypted,
83
- messageNumber: envelope.messageNumber,
84
- verified: true,
85
- });
86
- }
87
- else {
88
- console.log(`❌ Message ${i + 1} verification failed`);
89
- conversation.push({
90
- sender,
91
- receiver: sender === "Alice" ? "Bob" : "Alice",
92
- original: messages[i],
93
- decrypted,
94
- messageNumber: envelope.messageNumber,
95
- verified: false,
96
- });
97
- }
98
- }
99
- // Test state serialization
100
- const aliceSerialized = await (0, crypto_1.serializeDoubleRatchetState)(aliceState);
101
- const bobSerialized = await (0, crypto_1.serializeDoubleRatchetState)(bobState);
102
- console.log("\n📊 Interactive Double Ratchet test results:");
103
- console.log(`Messages exchanged: ${conversation.length}`);
104
- console.log(`All messages verified: ${conversation.every((msg) => msg.verified)}`);
105
- console.log(`Alice state serialized: ${aliceSerialized.length} characters`);
106
- console.log(`Bob state serialized: ${bobSerialized.length} characters`);
107
- return {
108
- success: true,
109
- messagesExchanged: conversation.length,
110
- allVerified: conversation.every((msg) => msg.verified),
111
- conversation,
112
- aliceState: aliceSerialized,
113
- bobState: bobSerialized,
114
- };
115
- }
116
- catch (error) {
117
- console.error("❌ Interactive Double Ratchet test error:", error);
118
- return {
119
- success: false,
120
- error: error instanceof Error ? error.message : "Unknown error",
121
- };
122
- }
123
- }
124
- // Run the tests
125
- async function runAllTests() {
126
- console.log("🚀 Running all Double Ratchet tests...\n");
127
- // Test 1: Basic demonstration
128
- console.log("=== Test 1: Basic Double Ratchet Demonstration ===");
129
- const basicResult = await testDoubleRatchet();
130
- console.log("\n=== Test 2: Interactive Double Ratchet Messaging ===");
131
- const interactiveResult = await testInteractiveDoubleRatchet();
132
- console.log("\n📊 Final Results:");
133
- console.log("Basic test:", basicResult.success ? "✅ PASSED" : "❌ FAILED");
134
- console.log("Interactive test:", interactiveResult.success ? "✅ PASSED" : "❌ FAILED");
135
- if (basicResult.success && interactiveResult.success) {
136
- console.log("\n🎉 All Double Ratchet tests completed successfully!");
137
- }
138
- else {
139
- console.log("\n❌ Some tests failed");
140
- }
141
- return {
142
- basic: basicResult,
143
- interactive: interactiveResult,
144
- allPassed: basicResult.success && interactiveResult.success,
145
- };
146
- }
147
- // Run the tests
148
- runAllTests()
149
- .then((result) => {
150
- console.log("\n📊 Final Test Summary:");
151
- console.log(JSON.stringify(result, null, 2));
152
- })
153
- .catch((error) => {
154
- console.error("💥 Test execution failed:", error);
155
- });
@@ -1,97 +0,0 @@
1
- "use strict";
2
- /**
3
- * MLS 3-Member Test
4
- * Test specifico per gruppi di 3 membri
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.testMLS3Members = testMLS3Members;
8
- const crypto_1 = require("../crypto");
9
- async function testMLS3Members() {
10
- console.log("🚀 Starting MLS 3-Member Test");
11
- console.log("=".repeat(50));
12
- try {
13
- // Create managers
14
- const alice = new crypto_1.MLSManager("alice");
15
- const bob = new crypto_1.MLSManager("bob");
16
- const charlie = new crypto_1.MLSManager("charlie");
17
- // Initialize
18
- await alice.initialize();
19
- await bob.initialize();
20
- await charlie.initialize();
21
- console.log("✅ All managers initialized");
22
- // Alice creates group
23
- const groupId = "test-3-members";
24
- await alice.createGroup(groupId);
25
- console.log("✅ Group created by Alice");
26
- // Add Bob and Charlie together
27
- const bobKeyPackage = bob.getKeyPackage();
28
- const charlieKeyPackage = charlie.getKeyPackage();
29
- console.log("➕ Adding Bob and Charlie to group...");
30
- const addResult = await alice.addMembers(groupId, [
31
- bobKeyPackage,
32
- charlieKeyPackage,
33
- ]);
34
- console.log("✅ Members added by Alice");
35
- // Bob and Charlie join via welcome
36
- await bob.processWelcome(addResult.welcome, addResult.ratchetTree);
37
- await charlie.processWelcome(addResult.welcome, addResult.ratchetTree);
38
- console.log("✅ Bob and Charlie joined group");
39
- // Verify all members are synchronized
40
- const aliceInfo = await alice.getGroupKeyInfo(groupId);
41
- const bobInfo = await bob.getGroupKeyInfo(groupId);
42
- const charlieInfo = await charlie.getGroupKeyInfo(groupId);
43
- console.log(`📊 Epoch verification - Alice: ${aliceInfo?.epoch}, Bob: ${bobInfo?.epoch}, Charlie: ${charlieInfo?.epoch}`);
44
- if (aliceInfo?.epoch === bobInfo?.epoch &&
45
- bobInfo?.epoch === charlieInfo?.epoch) {
46
- console.log(`✅ All 3 members synchronized at epoch ${aliceInfo?.epoch}`);
47
- }
48
- else {
49
- console.log(`⚠️ WARNING: Members at different epochs`);
50
- }
51
- // Test message exchange
52
- console.log("\n📋 Testing message exchange with 3 members");
53
- // Alice sends message
54
- console.log("💬 Alice sending message...");
55
- const envelope1 = await alice.encryptMessage(groupId, "Hello from Alice to Bob and Charlie!");
56
- console.log("✅ Alice encrypted message");
57
- // Bob and Charlie decrypt
58
- const bobDecrypted1 = await bob.decryptMessage(envelope1);
59
- console.log(`✅ Bob decrypted: "${bobDecrypted1}"`);
60
- const charlieDecrypted1 = await charlie.decryptMessage(envelope1);
61
- console.log(`✅ Charlie decrypted: "${charlieDecrypted1}"`);
62
- // Bob sends message
63
- console.log("\n💬 Bob sending message...");
64
- const envelope2 = await bob.encryptMessage(groupId, "Hello from Bob to Alice and Charlie!");
65
- console.log("✅ Bob encrypted message");
66
- // Alice and Charlie decrypt
67
- const aliceDecrypted2 = await alice.decryptMessage(envelope2);
68
- console.log(`✅ Alice decrypted: "${aliceDecrypted2}"`);
69
- const charlieDecrypted2 = await charlie.decryptMessage(envelope2);
70
- console.log(`✅ Charlie decrypted: "${charlieDecrypted2}"`);
71
- // Charlie sends message
72
- console.log("\n💬 Charlie sending message...");
73
- const envelope3 = await charlie.encryptMessage(groupId, "Hello from Charlie to Alice and Bob!");
74
- console.log("✅ Charlie encrypted message");
75
- // Alice and Bob decrypt
76
- const aliceDecrypted3 = await alice.decryptMessage(envelope3);
77
- console.log(`✅ Alice decrypted: "${aliceDecrypted3}"`);
78
- const bobDecrypted3 = await bob.decryptMessage(envelope3);
79
- console.log(`✅ Bob decrypted: "${bobDecrypted3}"`);
80
- console.log("\n🎉 MLS 3-Member Test completed successfully!");
81
- console.log("✅ Group creation with 3 members");
82
- console.log("✅ Bidirectional encrypted messaging");
83
- console.log("✅ All members can send and receive messages");
84
- // Cleanup
85
- await alice.destroy();
86
- await bob.destroy();
87
- await charlie.destroy();
88
- console.log("✅ Cleanup completed");
89
- }
90
- catch (error) {
91
- console.error("❌ Test failed:", error);
92
- }
93
- }
94
- // Run the test
95
- if (require.main === module) {
96
- testMLS3Members().catch(console.error);
97
- }