shogun-core 5.2.2 โ†’ 6.0.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 (43) hide show
  1. package/README.md +123 -20
  2. package/dist/browser/shogun-core.js +1134 -493
  3. package/dist/browser/shogun-core.js.map +1 -1
  4. package/dist/config/simplified-config.js +108 -40
  5. package/dist/crypto/mls.js +34 -15
  6. package/dist/crypto/sframe.js +13 -11
  7. package/dist/examples/auth-test.js +263 -59
  8. package/dist/examples/crypto-identity-example.js +55 -21
  9. package/dist/examples/mls-3-member-test.js +97 -0
  10. package/dist/examples/mls-multi-member.js +153 -0
  11. package/dist/examples/mls-sframe-test.js +14 -11
  12. package/dist/examples/mls-simple-test.js +58 -0
  13. package/dist/examples/shogun-core-example.js +90 -0
  14. package/dist/examples/zkproof-credentials-example.js +9 -5
  15. package/dist/examples/zkproof-example.js +14 -10
  16. package/dist/gundb/api.js +17 -16
  17. package/dist/gundb/db.js +769 -328
  18. package/dist/index.js +4 -4
  19. package/dist/managers/CoreInitializer.js +21 -15
  20. package/dist/managers/CryptoIdentityManager.js +79 -32
  21. package/dist/plugins/zkproof/zkCredentials.js +4 -1
  22. package/dist/types/config/simplified-config.d.ts +64 -3
  23. package/dist/types/crypto/sframe.d.ts +4 -0
  24. package/dist/types/examples/mls-3-member-test.d.ts +6 -0
  25. package/dist/types/examples/mls-multi-member.d.ts +6 -0
  26. package/dist/types/examples/mls-simple-test.d.ts +6 -0
  27. package/dist/types/examples/shogun-core-example.d.ts +8 -0
  28. package/dist/types/gundb/api.d.ts +6 -13
  29. package/dist/types/gundb/db.d.ts +84 -41
  30. package/dist/types/index.d.ts +4 -2
  31. package/dist/types/interfaces/shogun.d.ts +1 -2
  32. package/dist/types/managers/CryptoIdentityManager.d.ts +2 -1
  33. package/package.json +11 -8
  34. package/dist/examples/mls-advanced-example.js +0 -294
  35. package/dist/examples/quick-auth-test.js +0 -61
  36. package/dist/examples/simple-api-test.js +0 -114
  37. package/dist/examples/simple-crypto-identity-example.js +0 -84
  38. package/dist/examples/timeout-test.js +0 -227
  39. package/dist/types/examples/mls-advanced-example.d.ts +0 -53
  40. package/dist/types/examples/quick-auth-test.d.ts +0 -8
  41. package/dist/types/examples/simple-api-test.d.ts +0 -10
  42. package/dist/types/examples/simple-crypto-identity-example.d.ts +0 -6
  43. package/dist/types/examples/timeout-test.d.ts +0 -8
@@ -5,16 +5,9 @@
5
5
  * - Direct authentication through Gun.user()
6
6
  */
7
7
  import type { UserInfo, AuthCallback, EventData, EventListener } from "./types";
8
- import type { IGunUserInstance, IGunChain, IGunInstance, ISEAPair, GunMessagePut } from "gun/types";
8
+ import type { IGunUserInstance, IGunChain, IGunInstance, ISEAPair } from "gun/types";
9
9
  import type { AuthResult, SignUpResult } from "../interfaces/shogun";
10
- import Gun from "gun/gun";
11
10
  import SEA from "gun/sea";
12
- import "gun/lib/then";
13
- import "gun/lib/radix";
14
- import "gun/lib/radisk";
15
- import "gun/lib/store";
16
- import "gun/lib/rindexed";
17
- import "gun/lib/webrtc";
18
11
  import derive, { DeriveOptions } from "./derive";
19
12
  import { GunDataEventData, GunPeerEventData } from "../interfaces/events";
20
13
  import { RxJS } from "./rxjs";
@@ -31,6 +24,9 @@ declare class DataBase {
31
24
  private readonly eventEmitter;
32
25
  private _rxjs?;
33
26
  private _cryptoIdentityManager?;
27
+ private _activeTimeouts;
28
+ private _activeIntervals;
29
+ private _isDestroyed;
34
30
  constructor(gun: IGunInstance, appScope?: string, core?: any);
35
31
  /**
36
32
  * Initialize the GunInstance asynchronously
@@ -114,31 +110,21 @@ declare class DataBase {
114
110
  */
115
111
  get(path: string): IGunChain<any, any>;
116
112
  /**
117
- * Gets data at the specified path (one-time read)
118
- * @param path Path to get the data from
119
- * @returns Promise resolving to the data
120
- */
121
- getData(path: string): Promise<any>;
122
- /**
123
- * Puts data at the specified path
124
- * @param path Path to store data
125
- * @param data Data to store
126
- * @returns Promise resolving to operation result
113
+ * Gets the Gun instance for direct operations
114
+ * @returns Gun instance
127
115
  */
128
- put(path: string, data: any): Promise<GunMessagePut>;
116
+ getGunInstance(): IGunInstance;
129
117
  /**
130
- * Sets data at the specified path
131
- * @param path Path to store data
132
- * @param data Data to store
133
- * @returns Promise resolving to operation result
118
+ * Gets the app scope node for direct operations
119
+ * @returns Gun node
134
120
  */
135
- set(path: string, data: any): Promise<GunMessagePut>;
121
+ getAppNode(): IGunChain<any, any>;
136
122
  /**
137
- * Removes data at the specified path
138
- * @param path Path to remove
139
- * @returns Promise resolving to operation result
123
+ * Helper method to get a node at a specific path for direct GUN operations
124
+ * @param path Path to the node
125
+ * @returns Gun node at the specified path
140
126
  */
141
- remove(path: string): Promise<GunMessagePut>;
127
+ getNode(path: string): IGunChain<any, any>;
142
128
  /**
143
129
  * Checks if a user is currently logged in
144
130
  * @returns True if logged in
@@ -167,14 +153,6 @@ declare class DataBase {
167
153
  * Validates signup credentials with enhanced security
168
154
  */
169
155
  private validateSignupCredentials;
170
- /**
171
- * Creates a new user in Gun
172
- */
173
- private createNewUser;
174
- /**
175
- * Authenticates user after creation
176
- */
177
- private authenticateNewUser;
178
156
  /**
179
157
  * Signs up a new user using direct Gun authentication
180
158
  * @param username Username
@@ -182,11 +160,19 @@ declare class DataBase {
182
160
  * @param pair Optional SEA pair for Web3 login
183
161
  * @returns Promise resolving to signup result
184
162
  */
185
- signUp(username: string, password: string, pair?: ISEAPair | null): Promise<SignUpResult>;
163
+ signUp(username: string, password: string, pair?: ISEAPair | null, retryCount?: number, maxRetries?: number): Promise<SignUpResult>;
186
164
  /**
187
165
  * Creates a new user in Gun with pair-based authentication (for Web3/plugins)
188
166
  */
189
167
  private createNewUserWithPair;
168
+ /**
169
+ * Creates a new user in Gun without waiting for acknowledgment
170
+ */
171
+ private createNewUserFixed;
172
+ /**
173
+ * Authenticates user after creation without waiting for acknowledgment
174
+ */
175
+ private authenticateNewUserFixed;
190
176
  private runPostAuthOnAuthResult;
191
177
  /**
192
178
  * Sets up comprehensive user tracking system for agile user lookup
@@ -270,9 +256,17 @@ declare class DataBase {
270
256
  */
271
257
  updateUserLastSeen(userPub: string): Promise<void>;
272
258
  /**
273
- * Performs authentication with Gun
259
+ * Resets Gun.js authentication state to allow new auth operations
260
+ */
261
+ private resetAuthState;
262
+ /**
263
+ * Performs authentication with Gun with retry mechanism
274
264
  */
275
265
  private performAuthentication;
266
+ /**
267
+ * Internal authentication method with timeout
268
+ */
269
+ private performAuthenticationInternal;
276
270
  /**
277
271
  * Builds login result object
278
272
  */
@@ -317,6 +311,19 @@ declare class DataBase {
317
311
  hint?: string;
318
312
  error?: string;
319
313
  }>;
314
+ private _forgotPasswordInternal;
315
+ /**
316
+ * Recovers password hint using security question answers and userPub directly
317
+ * @param userPub User's public key
318
+ * @param securityAnswers Array of answers to security questions
319
+ * @returns Promise resolving with the password hint
320
+ */
321
+ forgotPasswordByPub(userPub: string, securityAnswers: string[]): Promise<{
322
+ success: boolean;
323
+ hint?: string;
324
+ error?: string;
325
+ }>;
326
+ private _forgotPasswordByPubInternal;
320
327
  static Errors: typeof GunErrors;
321
328
  /**
322
329
  * Adds an event listener
@@ -388,10 +395,46 @@ declare class DataBase {
388
395
  * Check if user is authenticated
389
396
  */
390
397
  isAuthenticated(): boolean;
398
+ /**
399
+ * Check if an authentication operation is currently in progress
400
+ */
401
+ isAuthInProgress(): boolean;
402
+ /**
403
+ * Force reset authentication state (useful for debugging or recovery)
404
+ */
405
+ forceResetAuthState(): void;
406
+ /**
407
+ * Aggressive cleanup for problematic users
408
+ * This method performs a complete reset of all authentication state
409
+ */
410
+ aggressiveAuthCleanup(): void;
411
+ /**
412
+ * Creates a completely fresh authentication context
413
+ * This is a more aggressive approach when normal reset doesn't work
414
+ */
415
+ private createFreshAuthContext;
416
+ /**
417
+ * Setup cleanup handlers for memory leak prevention
418
+ */
419
+ private setupCleanupHandlers;
420
+ /**
421
+ * Safe interval wrapper that tracks intervals for cleanup
422
+ */
423
+ private safeInterval;
424
+ /**
425
+ * Clear a specific timeout
426
+ */
427
+ private clearSafeTimeout;
428
+ /**
429
+ * Clear a specific interval
430
+ */
431
+ private clearSafeInterval;
432
+ /**
433
+ * Destroy the database instance and clean up all resources
434
+ */
435
+ destroy(): void;
391
436
  }
392
- declare const createGun: (config: any) => IGunInstance<any>;
393
- export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, createGun };
394
- export default Gun;
437
+ export { DataBase, SEA, RxJS, crypto, GunErrors, derive };
395
438
  export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
396
439
  export type { GunDataEventData, GunPeerEventData };
397
440
  export type { DeriveOptions };
@@ -2,12 +2,14 @@ import { ShogunCore } from "./core";
2
2
  import { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions } from "./gundb/db";
3
3
  import { RxJS, crypto, derive, GunErrors, DataBase } from "./gundb/db";
4
4
  import { SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, TypedGunOperationResult, TypedAuthResult, AutoQuickStart, autoQuickStart } from "./gundb";
5
- import { SEA } from "./gundb/db";
6
- import Gun from "./gundb/db";
5
+ import Gun from "gun";
6
+ import SEA from "gun/sea";
7
7
  export * from "./utils/errorHandler";
8
8
  export * from "./plugins";
9
9
  export * from "./interfaces/shogun";
10
10
  export * from "./config/simplified-config";
11
+ import type { ShogunCoreConfig } from "./interfaces/shogun";
12
+ export type ShogunSDKConfig = ShogunCoreConfig;
11
13
  export type * from "./interfaces/plugin";
12
14
  export type { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions, TypedGunOperationResult, TypedAuthResult, };
13
15
  export { Gun, ShogunCore, SEA, RxJS, crypto, derive, GunErrors, DataBase, SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, AutoQuickStart, autoQuickStart, };
@@ -153,8 +153,7 @@ export interface WebauthnConfig {
153
153
  * Shogun SDK configuration
154
154
  */
155
155
  export interface ShogunCoreConfig {
156
- gunInstance?: IGunInstance<any>;
157
- gunOptions?: any;
156
+ gunInstance: IGunInstance<any>;
158
157
  webauthn?: WebauthnConfig;
159
158
  web3?: {
160
159
  enabled?: boolean;
@@ -54,10 +54,11 @@ export interface IdentityRetrievalResult {
54
54
  */
55
55
  export declare class CryptoIdentityManager {
56
56
  private core;
57
+ private db;
57
58
  private pgpManager;
58
59
  private mlsManager;
59
60
  private sframeManager;
60
- constructor(core: IShogunCore);
61
+ constructor(core: IShogunCore, db?: any);
61
62
  /**
62
63
  * Genera tutte le identitร  crypto disponibili per un utente
63
64
  * @param username - Nome utente
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "5.2.2",
3
+ "version": "6.0.0",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -23,17 +23,21 @@
23
23
  "build:cjs": "tsc",
24
24
  "build:browser": "webpack --config webpack.config.cjs",
25
25
  "dev": "tsc --watch",
26
- "identity": "tsx ship/examples/identity-cli.ts",
27
- "messenger": "tsx ship/examples/messenger-cli.ts",
28
- "wallet": "tsx ship/examples/wallet-cli.ts",
29
- "stealth": "tsx ship/examples/stealth-cli.ts",
30
- "storage": "tsx ship/examples/storage-cli.ts",
31
- "vault": "tsx ship/examples/vault-cli.ts",
26
+ "identity": "tsx ../shogun-SHIP/src/examples/identity-cli.ts",
27
+ "messenger": "tsx ../shogun-SHIP/src/examples/messenger-cli.ts",
28
+ "wallet": "tsx ../shogun-SHIP/src/examples/wallet-cli.ts",
29
+ "stealth": "tsx ../shogun-SHIP/src/examples/stealth-cli.ts",
30
+ "storage": "tsx ../shogun-SHIP/src/examples/storage-cli.ts",
31
+ "vault": "tsx ../shogun-SHIP/src/examples/vault-cli.ts",
32
32
  "format": "prettier --write \"src/**/*.ts\"",
33
33
  "docs": "yarn typedoc --options typedoc.json",
34
34
  "prebuild": "rimraf dist",
35
35
  "setup:zkproof": "node scripts/setup-zkproof.js",
36
36
  "auth:test": "yarn tsx src/examples/auth-test.ts",
37
+ "hint:test": "yarn tsx src/examples/password-hint-test.ts",
38
+ "hint:simple": "yarn tsx src/examples/simple-hint-test.ts",
39
+ "hint:direct": "yarn tsx src/examples/direct-hint-test.ts",
40
+ "hint:fast": "yarn tsx src/examples/hint-test-fast.ts",
37
41
  "zkproof:example": "yarn tsx src/examples/zkproof-example.ts",
38
42
  "zkproof:credentials": "yarn tsx src/examples/zkproof-credentials-example.ts",
39
43
  "crypto:working": "yarn tsx src/examples/crypto-working-test.ts",
@@ -80,7 +84,6 @@
80
84
  "gun": "git+https://github.com/amark/gun.git",
81
85
  "nostr-tools": "^2.15.0",
82
86
  "openpgp": "^6.2.2",
83
- "react": "^19.2.0",
84
87
  "rxjs": "^7.8.2",
85
88
  "ts-mls": "^1.3.2",
86
89
  "uuid": "^11.1.0",
@@ -1,294 +0,0 @@
1
- "use strict";
2
- /**
3
- * MLS Advanced Example
4
- * Demonstrates advanced MLS features including:
5
- * - Group creation and management
6
- * - Member addition/removal
7
- * - Key rotation and forward secrecy
8
- * - Message encryption/decryption
9
- * - Commit processing and synchronization
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MLSGroupDemo = void 0;
13
- exports.demonstrateMLSAdvanced = demonstrateMLSAdvanced;
14
- const crypto_1 = require("../crypto");
15
- class MLSGroupDemo {
16
- constructor(groupId, creatorId) {
17
- this.users = new Map();
18
- this.groupId = groupId;
19
- this.creator = creatorId;
20
- console.log(`๐Ÿ—๏ธ [MLS Demo] Created group '${groupId}' with creator '${creatorId}'`);
21
- }
22
- /**
23
- * Add a user to the demo
24
- */
25
- async addUser(userId) {
26
- console.log(`๐Ÿ‘ค [MLS Demo] Adding user: ${userId}`);
27
- const manager = new crypto_1.MLSManager(userId);
28
- await manager.initialize();
29
- const keyPackage = manager.getKeyPackage();
30
- if (!keyPackage) {
31
- throw new Error(`Failed to get key package for user ${userId}`);
32
- }
33
- this.users.set(userId, {
34
- id: userId,
35
- manager,
36
- keyPackage,
37
- });
38
- console.log(`โœ… [MLS Demo] User ${userId} added successfully`);
39
- }
40
- /**
41
- * Create the group with the creator
42
- */
43
- async createGroup() {
44
- const creator = this.users.get(this.creator);
45
- if (!creator) {
46
- throw new Error(`Creator ${this.creator} not found`);
47
- }
48
- console.log(`๐Ÿ“ [MLS Demo] Creating group with creator: ${this.creator}`);
49
- const groupInfo = await creator.manager.createGroup(this.groupId);
50
- console.log(`โœ… [MLS Demo] Group created:`, {
51
- groupId: new TextDecoder().decode(groupInfo.groupId),
52
- members: groupInfo.members,
53
- epoch: groupInfo.epoch.toString(),
54
- });
55
- }
56
- /**
57
- * Add members to the group
58
- */
59
- async addMembers(memberIds) {
60
- const creator = this.users.get(this.creator);
61
- if (!creator) {
62
- throw new Error(`Creator ${this.creator} not found`);
63
- }
64
- console.log(`โž• [MLS Demo] Adding members: ${memberIds.join(", ")}`);
65
- const keyPackages = memberIds.map((id) => {
66
- const user = this.users.get(id);
67
- if (!user) {
68
- throw new Error(`User ${id} not found`);
69
- }
70
- return user.keyPackage;
71
- });
72
- const addResult = await creator.manager.addMembers(this.groupId, keyPackages);
73
- console.log(`โœ… [MLS Demo] Add commit created, epoch: ${addResult.commit?.epoch || "unknown"}`);
74
- // Send welcome messages to new members
75
- for (const memberId of memberIds) {
76
- const member = this.users.get(memberId);
77
- if (!member)
78
- continue;
79
- console.log(`๐Ÿ“ฉ [MLS Demo] Sending welcome to ${memberId}`);
80
- const groupInfo = await member.manager.processWelcome(addResult.welcome, addResult.ratchetTree);
81
- console.log(`โœ… [MLS Demo] ${memberId} joined group:`, {
82
- groupId: new TextDecoder().decode(groupInfo.groupId),
83
- members: groupInfo.members,
84
- epoch: groupInfo.epoch.toString(),
85
- });
86
- }
87
- // Process commit for existing members
88
- for (const [userId, user] of this.users) {
89
- if (userId !== this.creator) {
90
- console.log(`โš™๏ธ [MLS Demo] Processing commit for existing member: ${userId}`);
91
- await user.manager.processCommit(this.groupId, addResult.commit);
92
- }
93
- }
94
- console.log(`โœ… [MLS Demo] All members synchronized`);
95
- }
96
- /**
97
- * Send a message from one user to the group
98
- */
99
- async sendMessage(senderId, message) {
100
- const sender = this.users.get(senderId);
101
- if (!sender) {
102
- throw new Error(`Sender ${senderId} not found`);
103
- }
104
- console.log(`๐Ÿ’ฌ [MLS Demo] ${senderId} sending message: "${message}"`);
105
- const envelope = await sender.manager.encryptMessage(this.groupId, message);
106
- console.log(`๐Ÿ”’ [MLS Demo] Message encrypted:`, {
107
- groupId: new TextDecoder().decode(envelope.groupId),
108
- timestamp: new Date(envelope.timestamp).toISOString(),
109
- ciphertextLength: envelope.ciphertext.length,
110
- });
111
- // All members decrypt the message
112
- for (const [userId, user] of this.users) {
113
- try {
114
- const decrypted = await user.manager.decryptMessage(envelope);
115
- console.log(`๐Ÿ”“ [MLS Demo] ${userId} decrypted: "${decrypted}"`);
116
- }
117
- catch (error) {
118
- console.error(`โŒ [MLS Demo] ${userId} failed to decrypt:`, error);
119
- }
120
- }
121
- }
122
- /**
123
- * Perform key rotation
124
- */
125
- async rotateKeys(initiatorId) {
126
- const initiator = this.users.get(initiatorId);
127
- if (!initiator) {
128
- throw new Error(`Initiator ${initiatorId} not found`);
129
- }
130
- console.log(`๐Ÿ”„ [MLS Demo] ${initiatorId} initiating key rotation`);
131
- const updateCommit = await initiator.manager.updateKey(this.groupId);
132
- console.log(`โœ… [MLS Demo] Key rotation commit created`);
133
- // All members process the update commit
134
- for (const [userId, user] of this.users) {
135
- console.log(`โš™๏ธ [MLS Demo] Processing key rotation for ${userId}`);
136
- await user.manager.processCommit(this.groupId, updateCommit);
137
- }
138
- console.log(`โœ… [MLS Demo] Key rotation completed for all members`);
139
- }
140
- /**
141
- * Remove members from the group
142
- */
143
- async removeMembers(memberIds) {
144
- const creator = this.users.get(this.creator);
145
- if (!creator) {
146
- throw new Error(`Creator ${this.creator} not found`);
147
- }
148
- console.log(`โž– [MLS Demo] Removing members: ${memberIds.join(", ")}`);
149
- // Get member indices (simplified - in real implementation you'd track indices properly)
150
- const memberIndices = memberIds.map((id) => {
151
- const user = this.users.get(id);
152
- if (!user) {
153
- throw new Error(`User ${id} not found`);
154
- }
155
- // This is simplified - real implementation would track actual indices
156
- return Array.from(this.users.keys()).indexOf(id);
157
- });
158
- const removeCommit = await creator.manager.removeMembers(this.groupId, memberIndices);
159
- console.log(`โœ… [MLS Demo] Remove commit created`);
160
- // Process commit for remaining members
161
- for (const [userId, user] of this.users) {
162
- if (!memberIds.includes(userId)) {
163
- console.log(`โš™๏ธ [MLS Demo] Processing remove commit for ${userId}`);
164
- await user.manager.processCommit(this.groupId, removeCommit);
165
- }
166
- }
167
- // Remove users from our demo
168
- for (const memberId of memberIds) {
169
- this.users.delete(memberId);
170
- console.log(`๐Ÿ—‘๏ธ [MLS Demo] Removed user ${memberId} from demo`);
171
- }
172
- console.log(`โœ… [MLS Demo] Members removed successfully`);
173
- }
174
- /**
175
- * Get group information
176
- */
177
- async getGroupInfo() {
178
- const creator = this.users.get(this.creator);
179
- if (!creator) {
180
- throw new Error(`Creator ${this.creator} not found`);
181
- }
182
- const groupInfo = await creator.manager.getGroupKeyInfo(this.groupId);
183
- return {
184
- groupId: this.groupId,
185
- members: Array.from(this.users.keys()),
186
- groupInfo,
187
- };
188
- }
189
- /**
190
- * Demonstrate codec functionality
191
- */
192
- async demonstrateCodec() {
193
- console.log(`๐Ÿ“ฆ [MLS Demo] Demonstrating codec functionality`);
194
- const creator = this.users.get(this.creator);
195
- if (!creator) {
196
- throw new Error(`Creator ${this.creator} not found`);
197
- }
198
- // Test key package encoding/decoding
199
- const keyPackage = creator.keyPackage.publicPackage;
200
- const encoded = (0, crypto_1.encodeKeyPackage)(keyPackage);
201
- const decoded = (0, crypto_1.decodeKeyPackage)(encoded);
202
- console.log(`โœ… [MLS Demo] Key package codec test passed`);
203
- // Test welcome message encoding/decoding
204
- const groupInfo = await creator.manager.getGroupKeyInfo(this.groupId);
205
- if (groupInfo) {
206
- console.log(`โœ… [MLS Demo] Group info retrieved:`, {
207
- groupId: groupInfo.groupId,
208
- epoch: groupInfo.epoch,
209
- members: groupInfo.members,
210
- cipherSuite: groupInfo.cipherSuite,
211
- treeHash: groupInfo.treeHash,
212
- });
213
- }
214
- console.log(`โœ… [MLS Demo] Codec demonstration completed`);
215
- }
216
- /**
217
- * Clean up resources
218
- */
219
- async cleanup() {
220
- console.log(`๐Ÿงน [MLS Demo] Cleaning up resources`);
221
- for (const [userId, user] of this.users) {
222
- await user.manager.destroy();
223
- console.log(`โœ… [MLS Demo] Destroyed manager for ${userId}`);
224
- }
225
- this.users.clear();
226
- console.log(`โœ… [MLS Demo] Cleanup completed`);
227
- }
228
- }
229
- exports.MLSGroupDemo = MLSGroupDemo;
230
- // Main demonstration function
231
- async function demonstrateMLSAdvanced() {
232
- console.log("๐Ÿš€ Starting MLS Advanced Demonstration");
233
- console.log("=".repeat(50));
234
- const demo = new MLSGroupDemo("advanced-group", "alice");
235
- try {
236
- // Step 1: Add users
237
- console.log("\n๐Ÿ“‹ Step 1: Adding users");
238
- await demo.addUser("alice");
239
- await demo.addUser("bob");
240
- await demo.addUser("charlie");
241
- await demo.addUser("david");
242
- // Step 2: Create group
243
- console.log("\n๐Ÿ“‹ Step 2: Creating group");
244
- await demo.createGroup();
245
- // Step 3: Add members
246
- console.log("\n๐Ÿ“‹ Step 3: Adding members to group");
247
- await demo.addMembers(["bob", "charlie", "david"]);
248
- // Step 4: Send messages
249
- console.log("\n๐Ÿ“‹ Step 4: Sending messages");
250
- await demo.sendMessage("alice", "Welcome to our secure group! ๐Ÿ”’");
251
- await demo.sendMessage("bob", "Thanks Alice! This is amazing! ๐ŸŽ‰");
252
- await demo.sendMessage("charlie", "The encryption is working perfectly! โœจ");
253
- await demo.sendMessage("david", "Forward secrecy is incredible! ๐Ÿ›ก๏ธ");
254
- // Step 5: Key rotation
255
- console.log("\n๐Ÿ“‹ Step 5: Performing key rotation");
256
- await demo.rotateKeys("alice");
257
- // Step 6: Send more messages after key rotation
258
- console.log("\n๐Ÿ“‹ Step 6: Sending messages after key rotation");
259
- await demo.sendMessage("bob", "Keys rotated successfully! ๐Ÿ”„");
260
- await demo.sendMessage("charlie", "Old messages are still secure! ๐Ÿ”");
261
- // Step 7: Remove a member
262
- console.log("\n๐Ÿ“‹ Step 7: Removing a member");
263
- await demo.removeMembers(["david"]);
264
- // Step 8: Send message after removal
265
- console.log("\n๐Ÿ“‹ Step 8: Sending message after member removal");
266
- await demo.sendMessage("alice", "David has been removed from the group");
267
- // Step 9: Demonstrate codec
268
- console.log("\n๐Ÿ“‹ Step 9: Demonstrating codec functionality");
269
- await demo.demonstrateCodec();
270
- // Step 10: Get final group info
271
- console.log("\n๐Ÿ“‹ Step 10: Final group information");
272
- const finalInfo = await demo.getGroupInfo();
273
- console.log("๐Ÿ“Š Final Group State:", finalInfo);
274
- console.log("\n๐ŸŽ‰ MLS Advanced Demonstration completed successfully!");
275
- console.log("=".repeat(50));
276
- console.log("โœ… Group creation and management");
277
- console.log("โœ… Member addition and removal");
278
- console.log("โœ… End-to-end encrypted messaging");
279
- console.log("โœ… Key rotation and forward secrecy");
280
- console.log("โœ… Commit processing and synchronization");
281
- console.log("โœ… Codec functionality");
282
- console.log("โœ… RFC 9420 compliance");
283
- }
284
- catch (error) {
285
- console.error("โŒ MLS Advanced Demonstration failed:", error);
286
- }
287
- finally {
288
- await demo.cleanup();
289
- }
290
- }
291
- // Run the demonstration
292
- if (require.main === module) {
293
- demonstrateMLSAdvanced().catch(console.error);
294
- }
@@ -1,61 +0,0 @@
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
- }