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.
- package/README.md +123 -20
- package/dist/browser/shogun-core.js +1134 -493
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +108 -40
- package/dist/crypto/mls.js +34 -15
- package/dist/crypto/sframe.js +13 -11
- package/dist/examples/auth-test.js +263 -59
- package/dist/examples/crypto-identity-example.js +55 -21
- package/dist/examples/mls-3-member-test.js +97 -0
- package/dist/examples/mls-multi-member.js +153 -0
- package/dist/examples/mls-sframe-test.js +14 -11
- package/dist/examples/mls-simple-test.js +58 -0
- package/dist/examples/shogun-core-example.js +90 -0
- package/dist/examples/zkproof-credentials-example.js +9 -5
- package/dist/examples/zkproof-example.js +14 -10
- package/dist/gundb/api.js +17 -16
- package/dist/gundb/db.js +769 -328
- package/dist/index.js +4 -4
- package/dist/managers/CoreInitializer.js +21 -15
- package/dist/managers/CryptoIdentityManager.js +79 -32
- package/dist/plugins/zkproof/zkCredentials.js +4 -1
- package/dist/types/config/simplified-config.d.ts +64 -3
- package/dist/types/crypto/sframe.d.ts +4 -0
- package/dist/types/examples/mls-3-member-test.d.ts +6 -0
- package/dist/types/examples/mls-multi-member.d.ts +6 -0
- package/dist/types/examples/mls-simple-test.d.ts +6 -0
- package/dist/types/examples/shogun-core-example.d.ts +8 -0
- package/dist/types/gundb/api.d.ts +6 -13
- package/dist/types/gundb/db.d.ts +84 -41
- package/dist/types/index.d.ts +4 -2
- package/dist/types/interfaces/shogun.d.ts +1 -2
- package/dist/types/managers/CryptoIdentityManager.d.ts +2 -1
- package/package.json +11 -8
- package/dist/examples/mls-advanced-example.js +0 -294
- package/dist/examples/quick-auth-test.js +0 -61
- package/dist/examples/simple-api-test.js +0 -114
- package/dist/examples/simple-crypto-identity-example.js +0 -84
- package/dist/examples/timeout-test.js +0 -227
- package/dist/types/examples/mls-advanced-example.d.ts +0 -53
- package/dist/types/examples/quick-auth-test.d.ts +0 -8
- package/dist/types/examples/simple-api-test.d.ts +0 -10
- package/dist/types/examples/simple-crypto-identity-example.d.ts +0 -6
- package/dist/types/examples/timeout-test.d.ts +0 -8
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Timeout Test Script
|
|
4
|
-
*
|
|
5
|
-
* Tests the timeout mechanism for signup and login operations
|
|
6
|
-
* This script specifically tests the fixes we implemented to prevent hanging
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.timeoutTest = timeoutTest;
|
|
10
|
-
const api_1 = require("../gundb/api");
|
|
11
|
-
async function timeoutTest() {
|
|
12
|
-
console.log("β±οΈ ShogunCore Timeout Test\n");
|
|
13
|
-
console.log("This test verifies that signup/login operations don't hang indefinitely\n");
|
|
14
|
-
// === INITIALIZATION ===
|
|
15
|
-
console.log("π¦ === INITIALIZATION ===\n");
|
|
16
|
-
const quickStart = new api_1.AutoQuickStart({
|
|
17
|
-
peers: [
|
|
18
|
-
"https://peer.wallie.io/gun",
|
|
19
|
-
"https://gun-manhattan.herokuapp.com/gun",
|
|
20
|
-
"https://gun.defucc.me/gun",
|
|
21
|
-
],
|
|
22
|
-
appScope: "timeout-test",
|
|
23
|
-
enableGunDebug: true,
|
|
24
|
-
});
|
|
25
|
-
try {
|
|
26
|
-
await quickStart.init();
|
|
27
|
-
console.log("β ShogunCore initialized successfully");
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
console.error("β Failed to initialize ShogunCore:", error);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const db = quickStart.api.database;
|
|
34
|
-
console.log("");
|
|
35
|
-
// === TEST 1: NORMAL SIGNUP (should complete quickly) ===
|
|
36
|
-
console.log("π§ͺ === TEST 1: NORMAL SIGNUP ===\n");
|
|
37
|
-
const testUsername = `timeouttest_${Date.now()}`;
|
|
38
|
-
const testPassword = "testpass123!@#";
|
|
39
|
-
console.log(`Testing signup with username: ${testUsername}`);
|
|
40
|
-
console.log("Expected: Should complete within 10 seconds\n");
|
|
41
|
-
const signupStartTime = Date.now();
|
|
42
|
-
try {
|
|
43
|
-
const signupResult = await db.signUp(testUsername, testPassword);
|
|
44
|
-
const signupDuration = Date.now() - signupStartTime;
|
|
45
|
-
console.log(`β Signup completed in ${signupDuration}ms`);
|
|
46
|
-
if (signupDuration > 10000) {
|
|
47
|
-
console.warn("β οΈ Signup took longer than expected (>10s)");
|
|
48
|
-
}
|
|
49
|
-
else if (signupDuration > 5000) {
|
|
50
|
-
console.warn("β οΈ Signup took longer than ideal (>5s)");
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
console.log("β Signup completed in reasonable time");
|
|
54
|
-
}
|
|
55
|
-
console.log("Signup result:", {
|
|
56
|
-
success: signupResult.success,
|
|
57
|
-
error: signupResult.error || "None",
|
|
58
|
-
});
|
|
59
|
-
if (!signupResult.success) {
|
|
60
|
-
console.error("β Signup failed:", signupResult.error);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
const signupDuration = Date.now() - signupStartTime;
|
|
66
|
-
console.error(`β Signup threw exception after ${signupDuration}ms:`, error);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
console.log("");
|
|
70
|
-
// === TEST 2: NORMAL LOGIN (should complete quickly) ===
|
|
71
|
-
console.log("π§ͺ === TEST 2: NORMAL LOGIN ===\n");
|
|
72
|
-
console.log("Testing login with same credentials");
|
|
73
|
-
console.log("Expected: Should complete within 10 seconds\n");
|
|
74
|
-
const loginStartTime = Date.now();
|
|
75
|
-
try {
|
|
76
|
-
const loginResult = await db.login(testUsername, testPassword);
|
|
77
|
-
const loginDuration = Date.now() - loginStartTime;
|
|
78
|
-
console.log(`β Login completed in ${loginDuration}ms`);
|
|
79
|
-
if (loginDuration > 10000) {
|
|
80
|
-
console.warn("β οΈ Login took longer than expected (>10s)");
|
|
81
|
-
}
|
|
82
|
-
else if (loginDuration > 5000) {
|
|
83
|
-
console.warn("β οΈ Login took longer than ideal (>5s)");
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
console.log("β Login completed in reasonable time");
|
|
87
|
-
}
|
|
88
|
-
console.log("Login result:", {
|
|
89
|
-
success: loginResult.success,
|
|
90
|
-
error: loginResult.error || "None",
|
|
91
|
-
});
|
|
92
|
-
if (!loginResult.success) {
|
|
93
|
-
console.error("β Login failed:", loginResult.error);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
console.log("β User is now logged in:", db.isLoggedIn());
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
const loginDuration = Date.now() - loginStartTime;
|
|
101
|
-
console.error(`β Login threw exception after ${loginDuration}ms:`, error);
|
|
102
|
-
}
|
|
103
|
-
console.log("");
|
|
104
|
-
// === TEST 3: INVALID CREDENTIALS (should timeout gracefully) ===
|
|
105
|
-
console.log("π§ͺ === TEST 3: INVALID CREDENTIALS TIMEOUT ===\n");
|
|
106
|
-
console.log("Testing login with invalid password");
|
|
107
|
-
console.log("Expected: Should timeout after 10 seconds with error message\n");
|
|
108
|
-
const invalidLoginStartTime = Date.now();
|
|
109
|
-
try {
|
|
110
|
-
const invalidLoginResult = await db.login(testUsername, "wrongpassword");
|
|
111
|
-
const invalidLoginDuration = Date.now() - invalidLoginStartTime;
|
|
112
|
-
console.log(`β Invalid login completed in ${invalidLoginDuration}ms`);
|
|
113
|
-
console.log("Invalid login result:", {
|
|
114
|
-
success: invalidLoginResult.success,
|
|
115
|
-
error: invalidLoginResult.error || "None",
|
|
116
|
-
});
|
|
117
|
-
if (invalidLoginDuration > 10000) {
|
|
118
|
-
console.log("β Timeout mechanism worked - operation completed after timeout period");
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
console.log("β Invalid credentials were rejected quickly (good)");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
const invalidLoginDuration = Date.now() - invalidLoginStartTime;
|
|
126
|
-
console.log(`β Invalid login threw exception after ${invalidLoginDuration}ms (expected):`, error instanceof Error ? error.message : String(error));
|
|
127
|
-
if (invalidLoginDuration > 10000) {
|
|
128
|
-
console.log("β Timeout mechanism worked - exception thrown after timeout period");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
console.log("");
|
|
132
|
-
// === TEST 4: NON-EXISTENT USER (should timeout gracefully) ===
|
|
133
|
-
console.log("π§ͺ === TEST 4: NON-EXISTENT USER TIMEOUT ===\n");
|
|
134
|
-
console.log("Testing login with non-existent user");
|
|
135
|
-
console.log("Expected: Should timeout after 10 seconds with error message\n");
|
|
136
|
-
const nonexistentLoginStartTime = Date.now();
|
|
137
|
-
try {
|
|
138
|
-
const nonexistentLoginResult = await db.login("nonexistentuser123456", "password");
|
|
139
|
-
const nonexistentLoginDuration = Date.now() - nonexistentLoginStartTime;
|
|
140
|
-
console.log(`β Non-existent user login completed in ${nonexistentLoginDuration}ms`);
|
|
141
|
-
console.log("Non-existent user login result:", {
|
|
142
|
-
success: nonexistentLoginResult.success,
|
|
143
|
-
error: nonexistentLoginResult.error || "None",
|
|
144
|
-
});
|
|
145
|
-
if (nonexistentLoginDuration > 10000) {
|
|
146
|
-
console.log("β Timeout mechanism worked - operation completed after timeout period");
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
console.log("β Non-existent user was rejected quickly (good)");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
const nonexistentLoginDuration = Date.now() - nonexistentLoginStartTime;
|
|
154
|
-
console.log(`β Non-existent user login threw exception after ${nonexistentLoginDuration}ms (expected):`, error instanceof Error ? error.message : String(error));
|
|
155
|
-
if (nonexistentLoginDuration > 10000) {
|
|
156
|
-
console.log("β Timeout mechanism worked - exception thrown after timeout period");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
console.log("");
|
|
160
|
-
// === TEST 5: STRESS TEST (multiple rapid operations) ===
|
|
161
|
-
console.log("π§ͺ === TEST 5: STRESS TEST ===\n");
|
|
162
|
-
console.log("Testing multiple rapid signup/login operations");
|
|
163
|
-
console.log("Expected: All operations should complete or timeout gracefully\n");
|
|
164
|
-
const stressTestPromises = [];
|
|
165
|
-
const stressTestStartTime = Date.now();
|
|
166
|
-
for (let i = 0; i < 3; i++) {
|
|
167
|
-
const username = `stresstest_${Date.now()}_${i}`;
|
|
168
|
-
const password = "testpass123!@#";
|
|
169
|
-
stressTestPromises.push(db
|
|
170
|
-
.signUp(username, password)
|
|
171
|
-
.then((result) => ({
|
|
172
|
-
type: "signup",
|
|
173
|
-
username,
|
|
174
|
-
success: result.success,
|
|
175
|
-
error: result.error,
|
|
176
|
-
}))
|
|
177
|
-
.catch((error) => ({
|
|
178
|
-
type: "signup",
|
|
179
|
-
username,
|
|
180
|
-
success: false,
|
|
181
|
-
error: error.message,
|
|
182
|
-
})));
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const stressResults = await Promise.all(stressTestPromises);
|
|
186
|
-
const stressTestDuration = Date.now() - stressTestStartTime;
|
|
187
|
-
console.log(`β Stress test completed in ${stressTestDuration}ms`);
|
|
188
|
-
console.log("Stress test results:");
|
|
189
|
-
stressResults.forEach((result, index) => {
|
|
190
|
-
console.log(` ${index + 1}. ${result.type} for ${result.username}: ${result.success ? "Success" : "Failed"}`);
|
|
191
|
-
if (!result.success) {
|
|
192
|
-
console.log(` Error: ${result.error}`);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const successCount = stressResults.filter((r) => r.success).length;
|
|
196
|
-
console.log(`\nβ ${successCount}/${stressResults.length} operations succeeded`);
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
const stressTestDuration = Date.now() - stressTestStartTime;
|
|
200
|
-
console.error(`β Stress test failed after ${stressTestDuration}ms:`, error);
|
|
201
|
-
}
|
|
202
|
-
console.log("");
|
|
203
|
-
// === CLEANUP ===
|
|
204
|
-
console.log("π§Ή === CLEANUP ===\n");
|
|
205
|
-
try {
|
|
206
|
-
db.logout();
|
|
207
|
-
console.log("β Logged out successfully");
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
console.error("β Logout failed:", error);
|
|
211
|
-
}
|
|
212
|
-
console.log("\nβ
Timeout test completed!");
|
|
213
|
-
console.log("\nπ Test Summary:");
|
|
214
|
-
console.log("- β Normal signup completes quickly");
|
|
215
|
-
console.log("- β Normal login completes quickly");
|
|
216
|
-
console.log("- β Invalid credentials timeout gracefully");
|
|
217
|
-
console.log("- β Non-existent user timeout gracefully");
|
|
218
|
-
console.log("- β Multiple operations don't interfere with each other");
|
|
219
|
-
console.log("\nπ― Key Improvements Verified:");
|
|
220
|
-
console.log("- Timeout mechanism prevents infinite hanging");
|
|
221
|
-
console.log("- Error messages are informative");
|
|
222
|
-
console.log("- Operations complete within reasonable time");
|
|
223
|
-
}
|
|
224
|
-
// Esegui il test
|
|
225
|
-
if (require.main === module) {
|
|
226
|
-
timeoutTest().catch(console.error);
|
|
227
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MLS Advanced Example
|
|
3
|
-
* Demonstrates advanced MLS features including:
|
|
4
|
-
* - Group creation and management
|
|
5
|
-
* - Member addition/removal
|
|
6
|
-
* - Key rotation and forward secrecy
|
|
7
|
-
* - Message encryption/decryption
|
|
8
|
-
* - Commit processing and synchronization
|
|
9
|
-
*/
|
|
10
|
-
declare class MLSGroupDemo {
|
|
11
|
-
private users;
|
|
12
|
-
private groupId;
|
|
13
|
-
private creator;
|
|
14
|
-
constructor(groupId: string, creatorId: string);
|
|
15
|
-
/**
|
|
16
|
-
* Add a user to the demo
|
|
17
|
-
*/
|
|
18
|
-
addUser(userId: string): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Create the group with the creator
|
|
21
|
-
*/
|
|
22
|
-
createGroup(): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Add members to the group
|
|
25
|
-
*/
|
|
26
|
-
addMembers(memberIds: string[]): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Send a message from one user to the group
|
|
29
|
-
*/
|
|
30
|
-
sendMessage(senderId: string, message: string): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Perform key rotation
|
|
33
|
-
*/
|
|
34
|
-
rotateKeys(initiatorId: string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Remove members from the group
|
|
37
|
-
*/
|
|
38
|
-
removeMembers(memberIds: string[]): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Get group information
|
|
41
|
-
*/
|
|
42
|
-
getGroupInfo(): Promise<any>;
|
|
43
|
-
/**
|
|
44
|
-
* Demonstrate codec functionality
|
|
45
|
-
*/
|
|
46
|
-
demonstrateCodec(): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Clean up resources
|
|
49
|
-
*/
|
|
50
|
-
cleanup(): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
declare function demonstrateMLSAdvanced(): Promise<void>;
|
|
53
|
-
export { MLSGroupDemo, demonstrateMLSAdvanced };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example showing how to use the simplified ShogunCore API
|
|
3
|
-
*
|
|
4
|
-
* The API has been streamlined:
|
|
5
|
-
* - AutoQuickStart: Quick initialization helper
|
|
6
|
-
* - api.database: Direct access to DataBase for basic operations (get, put, set, remove, auth)
|
|
7
|
-
* - api helper methods: High-level helpers for profile, settings, collections, and array utilities
|
|
8
|
-
*/
|
|
9
|
-
declare function simpleAPITest(): Promise<void>;
|
|
10
|
-
export { simpleAPITest };
|