shogun-core 5.2.0 → 5.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +145 -1143
  2. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
  3. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
  4. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
  5. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
  6. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
  7. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
  8. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
  9. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
  10. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
  11. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
  12. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
  13. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
  14. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
  15. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
  16. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
  17. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
  18. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
  19. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
  20. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
  21. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
  22. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
  23. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
  24. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
  25. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
  26. package/dist/browser/shogun-core.js +160386 -0
  27. package/dist/browser/shogun-core.js.map +1 -0
  28. package/dist/config/simplified-config.js +236 -0
  29. package/dist/core.js +329 -0
  30. package/dist/crypto/asymmetric.js +99 -0
  31. package/dist/crypto/double-ratchet.js +370 -0
  32. package/dist/crypto/file-encryption.js +213 -0
  33. package/dist/crypto/hashing.js +87 -0
  34. package/dist/crypto/index.js +34 -0
  35. package/dist/crypto/mls-codec.js +202 -0
  36. package/dist/crypto/mls.js +550 -0
  37. package/dist/crypto/pgp.js +390 -0
  38. package/dist/crypto/random-generation.js +341 -0
  39. package/dist/crypto/sframe.js +350 -0
  40. package/dist/crypto/signal-protocol.js +376 -0
  41. package/dist/crypto/symmetric.js +91 -0
  42. package/dist/crypto/types.js +2 -0
  43. package/dist/crypto/utils.js +140 -0
  44. package/dist/examples/auth-test.js +253 -0
  45. package/dist/examples/crypto-identity-example.js +151 -0
  46. package/dist/examples/crypto-working-test.js +83 -0
  47. package/dist/examples/double-ratchet-test.js +155 -0
  48. package/dist/examples/mls-advanced-example.js +294 -0
  49. package/dist/examples/mls-sframe-test.js +304 -0
  50. package/dist/examples/pgp-example.js +200 -0
  51. package/dist/examples/quick-auth-test.js +61 -0
  52. package/dist/examples/random-generation-test.js +151 -0
  53. package/dist/examples/signal-protocol-test.js +38 -0
  54. package/dist/examples/simple-api-test.js +114 -0
  55. package/dist/examples/simple-crypto-identity-example.js +84 -0
  56. package/dist/examples/timeout-test.js +227 -0
  57. package/dist/examples/zkproof-credentials-example.js +212 -0
  58. package/dist/examples/zkproof-example.js +201 -0
  59. package/dist/gundb/api.js +435 -0
  60. package/dist/gundb/crypto.js +283 -0
  61. package/dist/gundb/db.js +1946 -0
  62. package/dist/gundb/derive.js +232 -0
  63. package/dist/gundb/errors.js +76 -0
  64. package/dist/gundb/index.js +22 -0
  65. package/dist/gundb/rxjs.js +447 -0
  66. package/dist/gundb/types.js +5 -0
  67. package/dist/index.js +58 -0
  68. package/dist/interfaces/common.js +2 -0
  69. package/dist/interfaces/events.js +40 -0
  70. package/dist/interfaces/plugin.js +2 -0
  71. package/dist/interfaces/shogun.js +37 -0
  72. package/dist/managers/AuthManager.js +226 -0
  73. package/dist/managers/CoreInitializer.js +228 -0
  74. package/dist/managers/CryptoIdentityManager.js +366 -0
  75. package/dist/managers/EventManager.js +70 -0
  76. package/dist/managers/PluginManager.js +299 -0
  77. package/dist/plugins/base.js +50 -0
  78. package/dist/plugins/index.js +32 -0
  79. package/dist/plugins/nostr/index.js +20 -0
  80. package/dist/plugins/nostr/nostrConnector.js +419 -0
  81. package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
  82. package/dist/plugins/nostr/nostrSigner.js +319 -0
  83. package/dist/plugins/nostr/types.js +2 -0
  84. package/dist/plugins/smartwallet/index.js +18 -0
  85. package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
  86. package/dist/plugins/smartwallet/types.js +2 -0
  87. package/dist/plugins/web3/index.js +20 -0
  88. package/dist/plugins/web3/types.js +2 -0
  89. package/dist/plugins/web3/web3Connector.js +533 -0
  90. package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
  91. package/dist/plugins/web3/web3Signer.js +314 -0
  92. package/dist/plugins/webauthn/index.js +19 -0
  93. package/dist/plugins/webauthn/types.js +14 -0
  94. package/dist/plugins/webauthn/webauthn.js +496 -0
  95. package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
  96. package/dist/plugins/webauthn/webauthnSigner.js +310 -0
  97. package/dist/plugins/zkproof/index.js +53 -0
  98. package/dist/plugins/zkproof/types.js +2 -0
  99. package/dist/plugins/zkproof/zkCredentials.js +213 -0
  100. package/dist/plugins/zkproof/zkProofConnector.js +198 -0
  101. package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
  102. package/dist/storage/storage.js +145 -0
  103. package/dist/types/config/simplified-config.d.ts +114 -0
  104. package/dist/types/core.d.ts +305 -0
  105. package/dist/types/crypto/asymmetric.d.ts +6 -0
  106. package/dist/types/crypto/double-ratchet.d.ts +22 -0
  107. package/dist/types/crypto/file-encryption.d.ts +19 -0
  108. package/dist/types/crypto/hashing.d.ts +9 -0
  109. package/dist/types/crypto/index.d.ts +13 -0
  110. package/dist/types/crypto/mls-codec.d.ts +39 -0
  111. package/dist/types/crypto/mls.d.ts +130 -0
  112. package/dist/types/crypto/pgp.d.ts +95 -0
  113. package/dist/types/crypto/random-generation.d.ts +35 -0
  114. package/dist/types/crypto/sframe.d.ts +102 -0
  115. package/dist/types/crypto/signal-protocol.d.ts +26 -0
  116. package/dist/types/crypto/symmetric.d.ts +9 -0
  117. package/dist/types/crypto/types.d.ts +144 -0
  118. package/dist/types/crypto/utils.d.ts +22 -0
  119. package/dist/types/examples/auth-test.d.ts +8 -0
  120. package/dist/types/examples/crypto-identity-example.d.ts +5 -0
  121. package/dist/types/examples/crypto-working-test.d.ts +1 -0
  122. package/dist/types/examples/double-ratchet-test.d.ts +1 -0
  123. package/dist/types/examples/mls-advanced-example.d.ts +53 -0
  124. package/dist/types/examples/mls-sframe-test.d.ts +1 -0
  125. package/dist/types/examples/pgp-example.d.ts +75 -0
  126. package/dist/types/examples/quick-auth-test.d.ts +8 -0
  127. package/dist/types/examples/random-generation-test.d.ts +1 -0
  128. package/dist/types/examples/signal-protocol-test.d.ts +1 -0
  129. package/dist/types/examples/simple-api-test.d.ts +10 -0
  130. package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
  131. package/dist/types/examples/timeout-test.d.ts +8 -0
  132. package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
  133. package/dist/types/examples/zkproof-example.d.ts +11 -0
  134. package/dist/types/gundb/api.d.ts +185 -0
  135. package/dist/types/gundb/crypto.d.ts +95 -0
  136. package/dist/types/gundb/db.d.ts +397 -0
  137. package/dist/types/gundb/derive.d.ts +21 -0
  138. package/dist/types/gundb/errors.d.ts +42 -0
  139. package/dist/types/gundb/index.d.ts +3 -0
  140. package/dist/types/gundb/rxjs.d.ts +110 -0
  141. package/dist/types/gundb/types.d.ts +255 -0
  142. package/dist/types/index.d.ts +16 -0
  143. package/dist/types/interfaces/common.d.ts +85 -0
  144. package/dist/types/interfaces/events.d.ts +131 -0
  145. package/dist/types/interfaces/plugin.d.ts +162 -0
  146. package/dist/types/interfaces/shogun.d.ts +208 -0
  147. package/dist/types/managers/AuthManager.d.ts +72 -0
  148. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  149. package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
  150. package/dist/types/managers/EventManager.d.ts +49 -0
  151. package/dist/types/managers/PluginManager.d.ts +145 -0
  152. package/dist/types/plugins/base.d.ts +35 -0
  153. package/dist/types/plugins/index.d.ts +18 -0
  154. package/dist/types/plugins/nostr/index.d.ts +4 -0
  155. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  156. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  157. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  158. package/dist/types/plugins/nostr/types.d.ts +122 -0
  159. package/dist/types/plugins/smartwallet/index.d.ts +2 -0
  160. package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
  161. package/dist/types/plugins/smartwallet/types.d.ts +80 -0
  162. package/dist/types/plugins/web3/index.d.ts +4 -0
  163. package/dist/types/plugins/web3/types.d.ts +107 -0
  164. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  165. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  166. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  167. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  168. package/dist/types/plugins/webauthn/types.d.ts +183 -0
  169. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  170. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
  171. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  172. package/dist/types/plugins/zkproof/index.d.ts +48 -0
  173. package/dist/types/plugins/zkproof/types.d.ts +123 -0
  174. package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
  175. package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
  176. package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
  177. package/dist/types/storage/storage.d.ts +51 -0
  178. package/dist/types/utils/errorHandler.d.ts +119 -0
  179. package/dist/types/utils/eventEmitter.d.ts +39 -0
  180. package/dist/types/utils/seedPhrase.d.ts +50 -0
  181. package/dist/types/utils/validation.d.ts +27 -0
  182. package/dist/utils/errorHandler.js +246 -0
  183. package/dist/utils/eventEmitter.js +79 -0
  184. package/dist/utils/seedPhrase.js +97 -0
  185. package/dist/utils/validation.js +81 -0
  186. package/package.json +10 -57
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ /**
3
+ * PGP Example - Simple and Immediate
4
+ * Demonstrates basic PGP functionality:
5
+ * - Key generation
6
+ * - Message encryption/decryption
7
+ * - Digital signing
8
+ * - Signature verification
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.simplePGPExample = simplePGPExample;
12
+ exports.advancedPGPExample = advancedPGPExample;
13
+ exports.runAllPGPExamples = runAllPGPExamples;
14
+ const crypto_1 = require("../crypto");
15
+ // Simple PGP usage example
16
+ async function simplePGPExample() {
17
+ try {
18
+ console.log("🔐 Starting Simple PGP Example");
19
+ console.log("=".repeat(40));
20
+ // Method 1: Using factory functions (simplest)
21
+ console.log("\n📋 Method 1: Factory Functions");
22
+ // Generate key pairs
23
+ const aliceKeys = await (0, crypto_1.generatePGPKeyPair)("Alice", "alice@example.com", "alice123");
24
+ const bobKeys = await (0, crypto_1.generatePGPKeyPair)("Bob", "bob@example.com", "bob123");
25
+ console.log("✅ Key pairs generated");
26
+ console.log("Alice Key ID:", aliceKeys.keyId);
27
+ console.log("Bob Key ID:", bobKeys.keyId);
28
+ // Encrypt message from Alice to Bob
29
+ const message = "Hello Bob! This is a secret message from Alice. 🔐";
30
+ const encrypted = await (0, crypto_1.encryptPGPMessage)(message, bobKeys.publicKey);
31
+ console.log("✅ Message encrypted");
32
+ console.log("Encrypted message length:", encrypted.message.length);
33
+ // Bob decrypts the message
34
+ const decrypted = await (0, crypto_1.decryptPGPMessage)(encrypted.message, bobKeys.privateKey, "bob123");
35
+ console.log("✅ Message decrypted");
36
+ console.log("Original message:", message);
37
+ console.log("Decrypted message:", decrypted);
38
+ console.log("Messages match:", message === decrypted);
39
+ // Alice signs a message
40
+ const signedMessage = "This is a signed message from Alice. ✍️";
41
+ const signature = await (0, crypto_1.signPGPMessage)(signedMessage, aliceKeys.privateKey, "alice123");
42
+ console.log("✅ Message signed");
43
+ console.log("Signature length:", signature.signature.length);
44
+ // Bob verifies Alice's signature
45
+ const verification = await (0, crypto_1.verifyPGPSignature)(signedMessage, signature.signature, aliceKeys.publicKey);
46
+ console.log("✅ Signature verified");
47
+ console.log("Signature valid:", verification.valid);
48
+ console.log("\n🎉 Simple PGP Example completed successfully!");
49
+ return {
50
+ success: true,
51
+ messageDecrypted: message === decrypted,
52
+ signatureValid: verification.valid,
53
+ };
54
+ }
55
+ catch (error) {
56
+ console.error("❌ Simple PGP Example failed:", error);
57
+ return {
58
+ success: false,
59
+ error: error instanceof Error ? error.message : "Unknown error",
60
+ };
61
+ }
62
+ }
63
+ // Advanced PGP usage with manager
64
+ async function advancedPGPExample() {
65
+ let manager;
66
+ try {
67
+ console.log("\n🔐 Starting Advanced PGP Example");
68
+ console.log("=".repeat(40));
69
+ // Method 2: Using PGPManager (more control)
70
+ manager = await (0, crypto_1.createPGPManager)();
71
+ console.log("✅ PGP Manager created");
72
+ // Generate multiple key pairs
73
+ const users = [
74
+ { name: "Alice", email: "alice@example.com", passphrase: "alice123" },
75
+ { name: "Bob", email: "bob@example.com", passphrase: "bob123" },
76
+ {
77
+ name: "Charlie",
78
+ email: "charlie@example.com",
79
+ passphrase: "charlie123",
80
+ },
81
+ ];
82
+ const userKeys = new Map();
83
+ for (const user of users) {
84
+ const keys = await manager.generateKeyPair(user.name, user.email, user.passphrase);
85
+ userKeys.set(user.name, keys);
86
+ console.log(`✅ ${user.name} key pair generated: ${keys.keyId}`);
87
+ }
88
+ // Test group messaging (Alice sends to Bob and Charlie)
89
+ console.log("\n📧 Group Messaging Test");
90
+ const groupMessage = "Hello everyone! This is a group message from Alice. 👥";
91
+ // Encrypt for Bob
92
+ const encryptedForBob = await manager.encryptMessage(groupMessage, userKeys.get("Bob").publicKey, userKeys.get("Alice").privateKey, // Alice signs
93
+ "alice123");
94
+ // Encrypt for Charlie
95
+ const encryptedForCharlie = await manager.encryptMessage(groupMessage, userKeys.get("Charlie").publicKey, userKeys.get("Alice").privateKey, // Alice signs
96
+ "alice123");
97
+ console.log("✅ Messages encrypted for Bob and Charlie");
98
+ // Bob decrypts
99
+ const bobDecrypted = await manager.decryptMessage(encryptedForBob.message, userKeys.get("Bob").privateKey, "bob123");
100
+ // Charlie decrypts
101
+ const charlieDecrypted = await manager.decryptMessage(encryptedForCharlie.message, userKeys.get("Charlie").privateKey, "charlie123");
102
+ console.log("✅ Messages decrypted by Bob and Charlie");
103
+ console.log("Bob received:", bobDecrypted);
104
+ console.log("Charlie received:", charlieDecrypted);
105
+ // Test key information
106
+ console.log("\n🔍 Key Information");
107
+ for (const [name, keys] of userKeys) {
108
+ const keyInfo = await manager.getKeyInfo(keys.publicKey);
109
+ console.log(`${name}:`, {
110
+ keyId: keyInfo.keyId,
111
+ fingerprint: keyInfo.fingerprint,
112
+ algorithm: keyInfo.algorithm,
113
+ created: keyInfo.created,
114
+ isPrivate: keyInfo.isPrivate,
115
+ isPublic: keyInfo.isPublic,
116
+ });
117
+ }
118
+ // Test key export/import
119
+ console.log("\n📤 Key Export/Import Test");
120
+ const aliceKeyArmored = await manager.exportKey(userKeys.get("Alice").publicKey, "armored");
121
+ const aliceKeyBinary = await manager.exportKey(userKeys.get("Alice").publicKey, "binary");
122
+ console.log("✅ Alice's key exported in armored and binary formats");
123
+ console.log("Armored length:", aliceKeyArmored.length);
124
+ console.log("Binary length:", aliceKeyBinary.length);
125
+ // Import the binary key back
126
+ const importedKey = await manager.importKey(aliceKeyBinary, "binary");
127
+ console.log("✅ Key imported from binary format");
128
+ console.log("Imported key matches original:", importedKey === userKeys.get("Alice").publicKey);
129
+ console.log("\n🎉 Advanced PGP Example completed successfully!");
130
+ return {
131
+ success: true,
132
+ groupMessaging: true,
133
+ keyManagement: true,
134
+ exportImport: true,
135
+ };
136
+ }
137
+ catch (error) {
138
+ console.error("❌ Advanced PGP Example failed:", error);
139
+ return {
140
+ success: false,
141
+ error: error instanceof Error ? error.message : "Unknown error",
142
+ };
143
+ }
144
+ finally {
145
+ // Clean up
146
+ if (typeof manager !== "undefined") {
147
+ manager.destroy();
148
+ }
149
+ }
150
+ }
151
+ // Run all examples
152
+ async function runAllPGPExamples() {
153
+ console.log("🚀 Running All PGP Examples");
154
+ console.log("=".repeat(50));
155
+ // Example 1: Simple usage
156
+ console.log("\n=== Example 1: Simple PGP Usage ===");
157
+ const simpleResult = await simplePGPExample();
158
+ // Example 2: Advanced usage
159
+ console.log("\n=== Example 2: Advanced PGP Usage ===");
160
+ const advancedResult = await advancedPGPExample();
161
+ // Example 3: Full demonstration
162
+ console.log("\n=== Example 3: Full PGP Demonstration ===");
163
+ const demoResult = await (0, crypto_1.demonstratePGP)();
164
+ console.log("\n📊 Final Results:");
165
+ console.log("Simple PGP:", simpleResult.success ? "✅ PASSED" : "❌ FAILED");
166
+ console.log("Advanced PGP:", advancedResult.success ? "✅ PASSED" : "❌ FAILED");
167
+ console.log("Full Demo:", demoResult.success ? "✅ PASSED" : "❌ FAILED");
168
+ const allPassed = simpleResult.success && advancedResult.success && demoResult.success;
169
+ if (allPassed) {
170
+ console.log("\n🎉 All PGP examples completed successfully!");
171
+ console.log("🔐 PGP Features Demonstrated:");
172
+ console.log(" ✅ Key generation (RSA 4096-bit)");
173
+ console.log(" ✅ Message encryption/decryption");
174
+ console.log(" ✅ Digital signing and verification");
175
+ console.log(" ✅ Key management and information");
176
+ console.log(" ✅ Key export/import (armored/binary)");
177
+ console.log(" ✅ Group messaging with signing");
178
+ console.log(" ✅ OpenPGP standard compliance");
179
+ }
180
+ else {
181
+ console.log("\n❌ Some PGP examples failed");
182
+ }
183
+ return {
184
+ simple: simpleResult,
185
+ advanced: advancedResult,
186
+ demo: demoResult,
187
+ allPassed,
188
+ };
189
+ }
190
+ // Run the examples
191
+ if (require.main === module) {
192
+ runAllPGPExamples()
193
+ .then((result) => {
194
+ console.log("\n📊 Final Test Summary:");
195
+ console.log(JSON.stringify(result, null, 2));
196
+ })
197
+ .catch((error) => {
198
+ console.error("💥 PGP examples execution failed:", error);
199
+ });
200
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Quick Auth Test Script
4
+ *
5
+ * Simple script to quickly test signup and login functionality
6
+ * Run this to verify that the authentication system is working
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.quickAuthTest = quickAuthTest;
10
+ const api_1 = require("../gundb/api");
11
+ async function quickAuthTest() {
12
+ console.log("🚀 Quick Authentication Test\n");
13
+ // Initialize ShogunCore
14
+ const quickStart = new api_1.AutoQuickStart({
15
+ peers: ["https://peer.wallie.io/gun"],
16
+ appScope: "quick-test",
17
+ });
18
+ try {
19
+ await quickStart.init();
20
+ console.log("✓ ShogunCore initialized");
21
+ }
22
+ catch (error) {
23
+ console.error("❌ Initialization failed:", error);
24
+ return;
25
+ }
26
+ const db = quickStart.api.database;
27
+ const username = `quicktest_${Date.now()}`;
28
+ const password = "testpass123";
29
+ console.log(`Testing with username: ${username}\n`);
30
+ // Test signup
31
+ console.log("🔄 Testing signup...");
32
+ const signupResult = await db.signUp(username, password);
33
+ if (signupResult.success) {
34
+ console.log("✓ Signup successful");
35
+ }
36
+ else {
37
+ console.error("❌ Signup failed:", signupResult.error);
38
+ return;
39
+ }
40
+ // Test login
41
+ console.log("🔄 Testing login...");
42
+ const loginResult = await db.login(username, password);
43
+ if (loginResult.success) {
44
+ console.log("✓ Login successful");
45
+ console.log("✓ User is logged in:", db.isLoggedIn());
46
+ }
47
+ else {
48
+ console.error("❌ Login failed:", loginResult.error);
49
+ return;
50
+ }
51
+ // Test logout
52
+ console.log("🔄 Testing logout...");
53
+ db.logout();
54
+ console.log("✓ Logout completed");
55
+ console.log("✓ User is logged out:", !db.isLoggedIn());
56
+ console.log("\n✅ All tests passed! Authentication system is working correctly.");
57
+ }
58
+ // Run the test
59
+ if (require.main === module) {
60
+ quickAuthTest().catch(console.error);
61
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Random Generation test
4
+ const crypto_1 = require("../crypto");
5
+ // Test Random Generation
6
+ async function testRandomGeneration() {
7
+ try {
8
+ console.log("🎲 Starting Random Generation test...");
9
+ // Test 1: Basic random string generation
10
+ console.log("\n1. Testing basic random string generation...");
11
+ const randomStr = (0, crypto_1.generateRandomString)(16, "test-");
12
+ console.log("✅ Random string:", randomStr);
13
+ // Test 2: Random bytes
14
+ console.log("\n2. Testing random bytes...");
15
+ const bytes = (0, crypto_1.randomBytes)(8);
16
+ console.log("✅ Random bytes:", Array.from(bytes)
17
+ .map((b) => b.toString(16).padStart(2, "0"))
18
+ .join(""));
19
+ // Test 3: Random integer
20
+ console.log("\n3. Testing random integer...");
21
+ const randomNum = (0, crypto_1.randomInt)(1, 100);
22
+ console.log("✅ Random integer (1-100):", randomNum);
23
+ // Test 4: Random float
24
+ console.log("\n4. Testing random float...");
25
+ const randomFloatVal = (0, crypto_1.randomFloat)();
26
+ console.log("✅ Random float:", randomFloatVal);
27
+ // Test 5: Random boolean
28
+ console.log("\n5. Testing random boolean...");
29
+ const randomBoolVal = (0, crypto_1.randomBool)();
30
+ console.log("✅ Random boolean:", randomBoolVal);
31
+ // Test 6: Random UUID
32
+ console.log("\n6. Testing random UUID...");
33
+ const uuid = (0, crypto_1.randomUUID)();
34
+ console.log("✅ Random UUID:", uuid);
35
+ // Test 7: Deterministic random
36
+ console.log("\n7. Testing deterministic random...");
37
+ const detRandom = (0, crypto_1.createDeterministicRandom)("test-seed");
38
+ const detInt1 = detRandom.integer(1, 100);
39
+ const detInt2 = detRandom.integer(1, 100);
40
+ const detFloat = detRandom.floating(0, 1, 4);
41
+ const detBool = detRandom.bool();
42
+ const detString = detRandom.string(10);
43
+ const detGuid = detRandom.guid();
44
+ console.log("✅ Deterministic integer 1:", detInt1);
45
+ console.log("✅ Deterministic integer 2:", detInt2);
46
+ console.log("✅ Deterministic float:", detFloat);
47
+ console.log("✅ Deterministic boolean:", detBool);
48
+ console.log("✅ Deterministic string:", detString);
49
+ console.log("✅ Deterministic GUID:", detGuid);
50
+ // Test 8: Chance.js compatibility
51
+ console.log("\n8. Testing Chance.js compatibility...");
52
+ const chanceInstance = (0, crypto_1.chance)("chance-seed");
53
+ const chanceInt = chanceInstance.integer(1, 50);
54
+ const chanceFloat = chanceInstance.floating(0, 10, 2);
55
+ const chanceBool = chanceInstance.bool();
56
+ console.log("✅ Chance integer:", chanceInt);
57
+ console.log("✅ Chance float:", chanceFloat);
58
+ console.log("✅ Chance boolean:", chanceBool);
59
+ // Test 9: Array utilities
60
+ console.log("\n9. Testing array utilities...");
61
+ const testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
62
+ const choice = (0, crypto_1.randomChoice)(testArray);
63
+ const shuffled = (0, crypto_1.randomShuffle)(testArray);
64
+ console.log("✅ Random choice from array:", choice);
65
+ console.log("✅ Shuffled array:", shuffled);
66
+ // Test 10: Random color
67
+ console.log("\n10. Testing random color...");
68
+ const color = (0, crypto_1.randomColor)();
69
+ console.log("✅ Random color:", color);
70
+ // Test 11: Random password
71
+ console.log("\n11. Testing random password...");
72
+ const password = (0, crypto_1.randomPassword)({
73
+ length: 16,
74
+ includeUppercase: true,
75
+ includeLowercase: true,
76
+ includeNumbers: true,
77
+ includeSymbols: true,
78
+ excludeSimilar: true,
79
+ });
80
+ console.log("✅ Random password:", password);
81
+ // Test 12: Random seed phrase
82
+ console.log("\n12. Testing random seed phrase...");
83
+ const seedPhrase = (0, crypto_1.randomSeedPhrase)(12);
84
+ console.log("✅ Random seed phrase:", seedPhrase.join(" "));
85
+ // Test 13: Deterministic consistency
86
+ console.log("\n13. Testing deterministic consistency...");
87
+ const det1 = (0, crypto_1.createDeterministicRandom)("consistency-test");
88
+ const det2 = (0, crypto_1.createDeterministicRandom)("consistency-test");
89
+ const val1_1 = det1.integer(1, 100);
90
+ const val1_2 = det1.integer(1, 100);
91
+ const val2_1 = det2.integer(1, 100);
92
+ const val2_2 = det2.integer(1, 100);
93
+ console.log("✅ Deterministic consistency test:");
94
+ console.log(" Same seed, first value:", val1_1 === val2_1 ? "✅ MATCH" : "❌ MISMATCH");
95
+ console.log(" Same seed, second value:", val1_2 === val2_2 ? "✅ MATCH" : "❌ MISMATCH");
96
+ console.log("\n🎉 All Random Generation tests completed successfully!");
97
+ return {
98
+ success: true,
99
+ tests: {
100
+ randomString: randomStr,
101
+ randomBytes: Array.from(bytes)
102
+ .map((b) => b.toString(16).padStart(2, "0"))
103
+ .join(""),
104
+ randomInt: randomNum,
105
+ randomFloat: randomFloatVal,
106
+ randomBool: randomBoolVal,
107
+ randomUUID: uuid,
108
+ deterministic: {
109
+ int1: detInt1,
110
+ int2: detInt2,
111
+ float: detFloat,
112
+ bool: detBool,
113
+ string: detString,
114
+ guid: detGuid,
115
+ },
116
+ chance: {
117
+ int: chanceInt,
118
+ float: chanceFloat,
119
+ bool: chanceBool,
120
+ },
121
+ arrayUtils: {
122
+ choice,
123
+ shuffledLength: shuffled.length,
124
+ },
125
+ color,
126
+ password,
127
+ seedPhrase: seedPhrase.join(" "),
128
+ consistency: {
129
+ firstMatch: val1_1 === val2_1,
130
+ secondMatch: val1_2 === val2_2,
131
+ },
132
+ },
133
+ };
134
+ }
135
+ catch (error) {
136
+ console.error("❌ Random Generation test error:", error);
137
+ return {
138
+ success: false,
139
+ error: error instanceof Error ? error.message : "Unknown error",
140
+ };
141
+ }
142
+ }
143
+ // Run the test
144
+ testRandomGeneration()
145
+ .then((result) => {
146
+ console.log("\n📊 Final Result:");
147
+ console.log(JSON.stringify(result, null, 2));
148
+ })
149
+ .catch((error) => {
150
+ console.error("💥 Test execution failed:", error);
151
+ });
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Signal Protocol test
4
+ const crypto_1 = require("../crypto");
5
+ // Test Signal Protocol
6
+ async function testSignalProtocol() {
7
+ try {
8
+ console.log("📡 Starting Signal Protocol test...");
9
+ const result = await (0, crypto_1.demonstrateSignalProtocol)();
10
+ if (result.success) {
11
+ console.log("✅ Signal Protocol test successful!");
12
+ console.log("Alice and Bob have the same secret:", result.aliceSecret === result.bobSecret);
13
+ console.log("One-time prekey used:", result.usedOneTimePrekey);
14
+ console.log("Alice secret (first 20 chars):", result.aliceSecret.substring(0, 20) + "...");
15
+ console.log("Bob secret (first 20 chars):", result.bobSecret.substring(0, 20) + "...");
16
+ }
17
+ else {
18
+ console.log("❌ Signal Protocol test failed");
19
+ }
20
+ return result;
21
+ }
22
+ catch (error) {
23
+ console.error("❌ Signal Protocol test error:", error);
24
+ return {
25
+ success: false,
26
+ error: error instanceof Error ? error.message : "Unknown error",
27
+ };
28
+ }
29
+ }
30
+ // Run the test
31
+ testSignalProtocol()
32
+ .then((result) => {
33
+ console.log("\n📊 Signal Protocol Result:");
34
+ console.log(JSON.stringify(result, null, 2));
35
+ })
36
+ .catch((error) => {
37
+ console.error("💥 Signal Protocol test execution failed:", error);
38
+ });
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Example showing how to use the simplified ShogunCore API
4
+ *
5
+ * The API has been streamlined:
6
+ * - AutoQuickStart: Quick initialization helper
7
+ * - api.database: Direct access to DataBase for basic operations (get, put, set, remove, auth)
8
+ * - api helper methods: High-level helpers for profile, settings, collections, and array utilities
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.simpleAPITest = simpleAPITest;
12
+ const api_1 = require("../gundb/api");
13
+ async function simpleAPITest() {
14
+ console.log("🚀 ShogunCore Simplified API Example\n");
15
+ // === QUICK START ===
16
+ console.log("📦 === INITIALIZATION ===\n");
17
+ // Use AutoQuickStart for easy setup
18
+ const quickStart = new api_1.AutoQuickStart({
19
+ peers: ["https://peer.wallie.io/gun"],
20
+ appScope: "simple-test",
21
+ });
22
+ await quickStart.init();
23
+ // Access the API and database
24
+ const api = quickStart.api;
25
+ const db = api.database; // Direct access to DataBase for basic operations
26
+ console.log("Initialized successfully!");
27
+ console.log("- api: provides helper methods");
28
+ console.log("- db (api.database): provides full DataBase functionality\n");
29
+ // === BASIC OPERATIONS (via database) ===
30
+ console.log("💾 === BASIC OPERATIONS (use api.database) ===\n");
31
+ const testData = { message: "Hello World", timestamp: Date.now() };
32
+ // Use db for basic operations
33
+ await db.put("global/data", testData);
34
+ console.log("✓ Saved data with db.put()");
35
+ const retrieved = await db.getData("global/data");
36
+ console.log("✓ Retrieved data with db.getData():", retrieved);
37
+ await db.remove("global/data");
38
+ console.log("✓ Removed data with db.remove()\n");
39
+ // === AUTHENTICATION (via database) ===
40
+ console.log("🔐 === AUTHENTICATION (use api.database) ===\n");
41
+ const username = "testuser_" + Date.now();
42
+ const password = "testpass123";
43
+ const signupResult = await db.signUp(username, password);
44
+ console.log("✓ Signup:", signupResult.success ? "Success" : "Failed");
45
+ if (signupResult.success) {
46
+ const loginResult = await db.login(username, password);
47
+ console.log("✓ Login:", loginResult.success ? "Success" : "Failed");
48
+ if (loginResult.success) {
49
+ console.log("✓ Current user:", db.getCurrentUser()?.alias, "\n");
50
+ // === HELPER METHODS (via api) ===
51
+ console.log("⭐ === HELPER METHODS (use api helpers) ===\n");
52
+ // Profile helper
53
+ await api.updateProfile({
54
+ name: "Test User",
55
+ email: "test@example.com",
56
+ bio: "Testing the simplified API",
57
+ });
58
+ console.log("✓ Profile updated with api.updateProfile()");
59
+ const profile = await api.getProfile();
60
+ console.log("✓ Profile retrieved:", profile);
61
+ // Settings helper
62
+ await api.saveSettings({
63
+ theme: "dark",
64
+ language: "en",
65
+ notifications: true,
66
+ });
67
+ console.log("✓ Settings saved with api.saveSettings()");
68
+ const settings = await api.getSettings();
69
+ console.log("✓ Settings retrieved:", settings);
70
+ // Collections helper
71
+ await api.createCollection("favorites", {
72
+ item1: { id: "item1", title: "First Item" },
73
+ item2: { id: "item2", title: "Second Item" },
74
+ });
75
+ console.log("✓ Collection created with api.createCollection()");
76
+ await api.addToCollection("favorites", "item3", {
77
+ id: "item3",
78
+ title: "Third Item",
79
+ });
80
+ console.log("✓ Item added with api.addToCollection()");
81
+ const collection = await api.getCollection("favorites");
82
+ console.log("✓ Collection retrieved:", collection);
83
+ // === ARRAY UTILITIES ===
84
+ console.log("\n🔧 === ARRAY UTILITIES ===\n");
85
+ const items = [
86
+ { id: "1", name: "Item 1", value: 100 },
87
+ { id: "2", name: "Item 2", value: 200 },
88
+ { id: "3", name: "Item 3", value: 300 },
89
+ ];
90
+ // Convert array to GunDB-friendly indexed object
91
+ const indexed = api.arrayToIndexedObject(items);
92
+ console.log("✓ Array converted to indexed object:", indexed);
93
+ // Convert back to array
94
+ const restored = api.indexedObjectToArray(indexed);
95
+ console.log("✓ Indexed object converted back to array:", restored);
96
+ // Logout
97
+ db.logout();
98
+ console.log("\n✓ Logged out");
99
+ }
100
+ }
101
+ console.log("\n✅ Example completed!");
102
+ console.log("\nSummary:");
103
+ console.log("- Use AutoQuickStart for easy initialization");
104
+ console.log("- Use api.database for basic operations (get, put, auth, etc.)");
105
+ console.log("- Use api helper methods for high-level operations:");
106
+ console.log(" • updateProfile(), getProfile()");
107
+ console.log(" • saveSettings(), getSettings()");
108
+ console.log(" • createCollection(), addToCollection(), getCollection()");
109
+ console.log(" • arrayToIndexedObject(), indexedObjectToArray()");
110
+ }
111
+ // Esegui il test
112
+ if (require.main === module) {
113
+ simpleAPITest().catch(console.error);
114
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Esempio semplificato del CryptoIdentityManager
4
+ * Focus sulla funzionalità principale senza plugin opzionali
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.simpleCryptoIdentityExample = simpleCryptoIdentityExample;
8
+ const index_1 = require("../index");
9
+ // Esempio principale
10
+ async function simpleCryptoIdentityExample() {
11
+ console.log("🚀 Esempio Semplificato CryptoIdentityManager");
12
+ console.log("============================================\n");
13
+ // 1. Inizializza ShogunCore
14
+ const core = new index_1.ShogunCore({
15
+ gunOptions: {
16
+ peers: ["https://peer.wallie.io/gun"],
17
+ radisk: true,
18
+ localStorage: false,
19
+ },
20
+ });
21
+ console.log("✅ ShogunCore inizializzato");
22
+ // 2. Registra un nuovo utente (genera automaticamente SEA pair)
23
+ const username = `user_${Date.now()}`;
24
+ const signupResult = await core.signUp(username, "password123");
25
+ if (!signupResult.success) {
26
+ console.error("❌ Registrazione fallita:", signupResult.error);
27
+ return;
28
+ }
29
+ console.log("✅ Utente registrato:", {
30
+ username: signupResult.username,
31
+ userPub: signupResult.userPub?.substring(0, 20) + "...",
32
+ hasSEAPair: !!signupResult.sea,
33
+ });
34
+ // 3. Le identità crypto sono state generate automaticamente durante la registrazione
35
+ const cryptoManager = new index_1.CryptoIdentityManager(core);
36
+ // 4. Recupera le identità crypto dell'utente corrente
37
+ const identitiesResult = await cryptoManager.getCurrentUserIdentities();
38
+ if (identitiesResult.success && identitiesResult.identities) {
39
+ const identities = identitiesResult.identities;
40
+ console.log("\n🔐 Identità crypto generate automaticamente:");
41
+ console.log("===========================================");
42
+ console.log("- RSA Key Pair:", identities.rsa ? "✅" : "❌");
43
+ console.log("- AES Symmetric Key:", identities.aes ? "✅" : "❌");
44
+ console.log("- Signal Protocol Identity:", identities.signal ? "✅" : "❌");
45
+ console.log("- PGP Key Pair:", identities.pgp ? "✅" : "❌");
46
+ console.log("- MLS Group:", identities.mls ? "✅" : "❌");
47
+ console.log("- SFrame Key:", identities.sframe ? "✅" : "❌");
48
+ console.log("- Created At:", new Date(identities.createdAt).toISOString());
49
+ console.log("- Version:", identities.version);
50
+ }
51
+ else {
52
+ console.error("❌ Errore nel recupero delle identità:", identitiesResult.error);
53
+ }
54
+ // 5. Test login con utente esistente
55
+ console.log("\n🔄 Test login con utente esistente...");
56
+ const loginResult = await core.login(username, "password123");
57
+ if (loginResult.success) {
58
+ console.log("✅ Login riuscito");
59
+ // Le identità crypto esistenti vengono recuperate automaticamente
60
+ const existingIdentities = await cryptoManager.getCurrentUserIdentities();
61
+ if (existingIdentities.success) {
62
+ console.log("✅ Identità crypto esistenti recuperate");
63
+ }
64
+ }
65
+ else {
66
+ console.error("❌ Login fallito:", loginResult.error);
67
+ }
68
+ // 6. Test verifica esistenza identità
69
+ console.log("\n🔍 Test verifica esistenza identità...");
70
+ const hasIdentities = await cryptoManager.hasStoredIdentities(username);
71
+ console.log(`✅ Identità salvate per ${username}: ${hasIdentities ? "Sì" : "No"}`);
72
+ console.log("\n🎉 Esempio completato!");
73
+ console.log("=====================");
74
+ console.log("✅ Il CryptoIdentityManager funziona perfettamente!");
75
+ console.log("✅ Le identità crypto vengono generate automaticamente");
76
+ console.log("✅ Le identità vengono salvate e recuperate correttamente");
77
+ console.log("✅ Il sistema è pronto per l'uso! 🚀");
78
+ }
79
+ // Esegui l'esempio se il file viene eseguito direttamente
80
+ if (typeof window === "undefined" && require.main === module) {
81
+ simpleCryptoIdentityExample().catch((error) => {
82
+ console.error("❌ Errore durante l'esecuzione dell'esempio:", error);
83
+ });
84
+ }