shogun-core 6.2.3 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
- package/dist/browser/shogun-core.js +138850 -146638
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{core.js → src/core.js} +167 -107
- package/dist/src/crypto/asymmetric.js +168 -0
- package/dist/src/crypto/double-ratchet.js +908 -0
- package/dist/src/crypto/file-encryption.js +352 -0
- package/dist/src/crypto/hashing.js +160 -0
- package/dist/src/crypto/index.js +18 -0
- package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
- package/dist/src/crypto/mls.js +734 -0
- package/dist/src/crypto/pgp.js +619 -0
- package/dist/{crypto → src/crypto}/random-generation.js +125 -103
- package/dist/src/crypto/sframe.js +466 -0
- package/dist/src/crypto/signal-protocol.js +943 -0
- package/dist/src/crypto/symmetric.js +165 -0
- package/dist/src/crypto/utils.js +220 -0
- package/dist/src/examples/auth-test.js +535 -0
- package/dist/src/examples/crypto-identity-example.js +294 -0
- package/dist/src/examples/crypto-working-test.js +149 -0
- package/dist/src/examples/double-ratchet-test.js +240 -0
- package/dist/src/examples/mls-3-member-test.js +183 -0
- package/dist/src/examples/mls-multi-member.js +439 -0
- package/dist/src/examples/mls-sframe-test.js +491 -0
- package/dist/src/examples/mls-simple-test.js +122 -0
- package/dist/src/examples/pgp-example.js +354 -0
- package/dist/src/examples/random-generation-test.js +191 -0
- package/dist/src/examples/shogun-core-example.js +204 -0
- package/dist/src/examples/signal-protocol-test.js +82 -0
- package/dist/src/examples/zkproof-credentials-example.js +357 -0
- package/dist/src/examples/zkproof-example.js +357 -0
- package/dist/src/gundb/crypto.js +420 -0
- package/dist/src/gundb/db.js +728 -0
- package/dist/src/gundb/derive.js +327 -0
- package/dist/src/gundb/errors.js +115 -0
- package/dist/src/gundb/gun-es.js +8 -0
- package/dist/src/gundb/index.js +5 -0
- package/dist/{gundb → src/gundb}/rxjs.js +147 -111
- package/dist/{gundb → src/gundb}/types.js +1 -2
- package/dist/src/index.js +19 -0
- package/dist/src/interfaces/events.js +57 -0
- package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
- package/dist/src/managers/AuthManager.js +301 -0
- package/dist/src/managers/CoreInitializer.js +304 -0
- package/dist/src/managers/CryptoIdentityManager.js +230 -0
- package/dist/{managers → src/managers}/EventManager.js +19 -21
- package/dist/{managers → src/managers}/PluginManager.js +123 -89
- package/dist/src/plugins/base.js +90 -0
- package/dist/src/plugins/index.js +17 -0
- package/dist/src/plugins/nostr/index.js +4 -0
- package/dist/src/plugins/nostr/nostrConnector.js +539 -0
- package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
- package/dist/src/plugins/nostr/nostrSigner.js +414 -0
- package/dist/src/plugins/smartwallet/index.js +2 -0
- package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
- package/dist/src/plugins/web3/index.js +4 -0
- package/dist/src/plugins/web3/types.js +1 -0
- package/dist/src/plugins/web3/web3Connector.js +738 -0
- package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
- package/dist/src/plugins/web3/web3Signer.js +432 -0
- package/dist/src/plugins/webauthn/index.js +3 -0
- package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
- package/dist/src/plugins/webauthn/webauthn.js +647 -0
- package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
- package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
- package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
- package/dist/src/plugins/zkproof/types.js +1 -0
- package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
- package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
- package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
- package/dist/src/storage/storage.js +189 -0
- package/dist/src/utils/errorHandler.js +339 -0
- package/dist/{utils → src/utils}/eventEmitter.js +26 -26
- package/dist/{utils → src/utils}/seedPhrase.js +23 -32
- package/dist/{utils → src/utils}/validation.js +14 -21
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
- package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
- package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
- package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/src/examples/random-generation-test.d.ts +1 -0
- package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
- package/dist/types/src/gundb/gun-es.d.ts +8 -0
- package/dist/types/src/gundb/min.d.ts +3 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
- package/package.json +14 -11
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
- package/dist/crypto/asymmetric.js +0 -99
- package/dist/crypto/double-ratchet.js +0 -370
- package/dist/crypto/file-encryption.js +0 -213
- package/dist/crypto/hashing.js +0 -87
- package/dist/crypto/index.js +0 -34
- package/dist/crypto/mls.js +0 -569
- package/dist/crypto/pgp.js +0 -390
- package/dist/crypto/sframe.js +0 -352
- package/dist/crypto/signal-protocol.js +0 -456
- package/dist/crypto/symmetric.js +0 -91
- package/dist/crypto/types.js +0 -2
- package/dist/crypto/utils.js +0 -140
- package/dist/examples/auth-test.js +0 -453
- package/dist/examples/crypto-identity-example.js +0 -196
- package/dist/examples/crypto-working-test.js +0 -83
- package/dist/examples/double-ratchet-test.js +0 -155
- package/dist/examples/mls-3-member-test.js +0 -97
- package/dist/examples/mls-multi-member.js +0 -153
- package/dist/examples/mls-sframe-test.js +0 -307
- package/dist/examples/mls-simple-test.js +0 -58
- package/dist/examples/pgp-example.js +0 -200
- package/dist/examples/random-generation-test.js +0 -151
- package/dist/examples/shogun-core-example.js +0 -150
- package/dist/examples/signal-protocol-test.js +0 -38
- package/dist/examples/zkproof-credentials-example.js +0 -217
- package/dist/examples/zkproof-example.js +0 -242
- package/dist/gundb/crypto.js +0 -306
- package/dist/gundb/db.js +0 -485
- package/dist/gundb/derive.js +0 -232
- package/dist/gundb/errors.js +0 -76
- package/dist/gundb/gun-es.js +0 -12
- package/dist/gundb/index.js +0 -21
- package/dist/gundb/min.js +0 -10
- package/dist/index.esm.js +0 -22
- package/dist/index.js +0 -47
- package/dist/interfaces/common.js +0 -2
- package/dist/interfaces/events.js +0 -40
- package/dist/interfaces/plugin.js +0 -2
- package/dist/managers/AuthManager.js +0 -226
- package/dist/managers/CoreInitializer.js +0 -250
- package/dist/managers/CryptoIdentityManager.js +0 -138
- package/dist/plugins/base.js +0 -50
- package/dist/plugins/index.js +0 -32
- package/dist/plugins/nostr/index.js +0 -20
- package/dist/plugins/nostr/nostrConnector.js +0 -419
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
- package/dist/plugins/nostr/nostrSigner.js +0 -319
- package/dist/plugins/nostr/types.js +0 -2
- package/dist/plugins/smartwallet/index.js +0 -18
- package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
- package/dist/plugins/smartwallet/types.js +0 -2
- package/dist/plugins/web3/index.js +0 -20
- package/dist/plugins/web3/types.js +0 -2
- package/dist/plugins/web3/web3Connector.js +0 -533
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
- package/dist/plugins/web3/web3Signer.js +0 -314
- package/dist/plugins/webauthn/index.js +0 -19
- package/dist/plugins/webauthn/webauthn.js +0 -496
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
- package/dist/plugins/webauthn/webauthnSigner.js +0 -310
- package/dist/plugins/zkproof/types.js +0 -2
- package/dist/plugins/zkproof/zkCredentials.js +0 -216
- package/dist/plugins/zkproof/zkProofConnector.js +0 -198
- package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
- package/dist/storage/storage.js +0 -145
- package/dist/types/gundb/gun-es.d.ts +0 -8
- package/dist/utils/errorHandler.js +0 -246
- /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
- /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
- /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
- /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
- /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
- /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
- /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
- /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
- /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
package/dist/crypto/utils.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throttle = exports.debounce = exports.restoreBackup = exports.createBackup = exports.compareFiles = exports.createFileHash = exports.isTextFile = exports.getFileExtension = exports.sanitizeFileName = exports.createProgressCallback = exports.formatDuration = exports.formatBytes = exports.measurePerformance = exports.generateSecurePassword = exports.validatePassword = void 0;
|
|
4
|
-
// Common utility functions for crypto operations
|
|
5
|
-
const validatePassword = (password) => {
|
|
6
|
-
// Basic password validation
|
|
7
|
-
return password.length >= 8;
|
|
8
|
-
};
|
|
9
|
-
exports.validatePassword = validatePassword;
|
|
10
|
-
const generateSecurePassword = (length = 16) => {
|
|
11
|
-
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
|
|
12
|
-
const randomValues = crypto.getRandomValues(new Uint8Array(length));
|
|
13
|
-
let password = "";
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
password += charset[randomValues[i] % charset.length];
|
|
16
|
-
}
|
|
17
|
-
return password;
|
|
18
|
-
};
|
|
19
|
-
exports.generateSecurePassword = generateSecurePassword;
|
|
20
|
-
const measurePerformance = async (operation, operationName) => {
|
|
21
|
-
const start = performance.now();
|
|
22
|
-
const result = await operation();
|
|
23
|
-
const end = performance.now();
|
|
24
|
-
const duration = end - start;
|
|
25
|
-
console.log(`⏱️ ${operationName} took ${duration.toFixed(2)}ms`);
|
|
26
|
-
return { result, duration };
|
|
27
|
-
};
|
|
28
|
-
exports.measurePerformance = measurePerformance;
|
|
29
|
-
const formatBytes = (bytes) => {
|
|
30
|
-
if (bytes === 0)
|
|
31
|
-
return "0 Bytes";
|
|
32
|
-
const k = 1024;
|
|
33
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
34
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
35
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
36
|
-
};
|
|
37
|
-
exports.formatBytes = formatBytes;
|
|
38
|
-
const formatDuration = (ms) => {
|
|
39
|
-
if (ms < 1000)
|
|
40
|
-
return `${ms.toFixed(2)}ms`;
|
|
41
|
-
if (ms < 60000)
|
|
42
|
-
return `${(ms / 1000).toFixed(2)}s`;
|
|
43
|
-
return `${(ms / 60000).toFixed(2)}m`;
|
|
44
|
-
};
|
|
45
|
-
exports.formatDuration = formatDuration;
|
|
46
|
-
const createProgressCallback = (onProgress, total) => {
|
|
47
|
-
let current = 0;
|
|
48
|
-
return {
|
|
49
|
-
increment: (amount = 1) => {
|
|
50
|
-
current += amount;
|
|
51
|
-
const progress = Math.min((current / total) * 100, 100);
|
|
52
|
-
onProgress(progress);
|
|
53
|
-
},
|
|
54
|
-
setProgress: (progress) => {
|
|
55
|
-
current = (progress / 100) * total;
|
|
56
|
-
onProgress(progress);
|
|
57
|
-
},
|
|
58
|
-
complete: () => {
|
|
59
|
-
current = total;
|
|
60
|
-
onProgress(100);
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
exports.createProgressCallback = createProgressCallback;
|
|
65
|
-
const sanitizeFileName = (fileName) => {
|
|
66
|
-
// Remove or replace invalid characters
|
|
67
|
-
return fileName.replace(/[<>:"/\\|?*]/g, "_");
|
|
68
|
-
};
|
|
69
|
-
exports.sanitizeFileName = sanitizeFileName;
|
|
70
|
-
const getFileExtension = (fileName) => {
|
|
71
|
-
const lastDot = fileName.lastIndexOf(".");
|
|
72
|
-
return lastDot !== -1 ? fileName.substring(lastDot + 1).toLowerCase() : "";
|
|
73
|
-
};
|
|
74
|
-
exports.getFileExtension = getFileExtension;
|
|
75
|
-
const isTextFile = (fileName) => {
|
|
76
|
-
const textExtensions = [
|
|
77
|
-
"txt",
|
|
78
|
-
"md",
|
|
79
|
-
"json",
|
|
80
|
-
"js",
|
|
81
|
-
"ts",
|
|
82
|
-
"html",
|
|
83
|
-
"css",
|
|
84
|
-
"xml",
|
|
85
|
-
"csv",
|
|
86
|
-
];
|
|
87
|
-
const extension = (0, exports.getFileExtension)(fileName);
|
|
88
|
-
return textExtensions.includes(extension);
|
|
89
|
-
};
|
|
90
|
-
exports.isTextFile = isTextFile;
|
|
91
|
-
const createFileHash = async (file) => {
|
|
92
|
-
const buffer = await file.arrayBuffer();
|
|
93
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
|
|
94
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
95
|
-
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
96
|
-
};
|
|
97
|
-
exports.createFileHash = createFileHash;
|
|
98
|
-
const compareFiles = async (file1, file2) => {
|
|
99
|
-
if (file1.size !== file2.size)
|
|
100
|
-
return false;
|
|
101
|
-
const hash1 = await (0, exports.createFileHash)(file1);
|
|
102
|
-
const hash2 = await (0, exports.createFileHash)(file2);
|
|
103
|
-
return hash1 === hash2;
|
|
104
|
-
};
|
|
105
|
-
exports.compareFiles = compareFiles;
|
|
106
|
-
const createBackup = (data) => {
|
|
107
|
-
return JSON.stringify({
|
|
108
|
-
data,
|
|
109
|
-
timestamp: new Date().toISOString(),
|
|
110
|
-
version: "1.0",
|
|
111
|
-
}, null, 2);
|
|
112
|
-
};
|
|
113
|
-
exports.createBackup = createBackup;
|
|
114
|
-
const restoreBackup = (backupString) => {
|
|
115
|
-
const backup = JSON.parse(backupString);
|
|
116
|
-
if (!backup.timestamp || !backup.data) {
|
|
117
|
-
throw new Error("Invalid backup format");
|
|
118
|
-
}
|
|
119
|
-
return backup.data;
|
|
120
|
-
};
|
|
121
|
-
exports.restoreBackup = restoreBackup;
|
|
122
|
-
const debounce = (func, wait) => {
|
|
123
|
-
let timeout;
|
|
124
|
-
return (...args) => {
|
|
125
|
-
clearTimeout(timeout);
|
|
126
|
-
timeout = setTimeout(() => func(...args), wait);
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
exports.debounce = debounce;
|
|
130
|
-
const throttle = (func, limit) => {
|
|
131
|
-
let inThrottle;
|
|
132
|
-
return (...args) => {
|
|
133
|
-
if (!inThrottle) {
|
|
134
|
-
func(...args);
|
|
135
|
-
inThrottle = true;
|
|
136
|
-
setTimeout(() => (inThrottle = false), limit);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
exports.throttle = throttle;
|
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Authentication Test Script
|
|
4
|
-
*
|
|
5
|
-
* Tests signup and login functionality with username and password
|
|
6
|
-
* Includes timeout handling and error recovery testing
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.authTest = authTest;
|
|
10
|
-
const index_1 = require("../index");
|
|
11
|
-
const core_1 = require("../core");
|
|
12
|
-
async function authTest() {
|
|
13
|
-
console.log("🔐 ShogunCore Authentication Test\n");
|
|
14
|
-
// Set a global timeout to prevent hanging
|
|
15
|
-
const globalTimeout = setTimeout(() => {
|
|
16
|
-
console.log("⏰ Global timeout reached - test taking too long");
|
|
17
|
-
console.log("✅ Test completed (with timeout)");
|
|
18
|
-
process.exit(0);
|
|
19
|
-
}, 120000); // 120 seconds timeout (increased for login/signup operations)
|
|
20
|
-
// Memory monitoring
|
|
21
|
-
const logMemoryUsage = (label) => {
|
|
22
|
-
if (typeof process !== "undefined" && process.memoryUsage) {
|
|
23
|
-
const usage = process.memoryUsage();
|
|
24
|
-
console.log(`📊 [${label}] Memory Usage:`, {
|
|
25
|
-
rss: `${Math.round(usage.rss / 1024 / 1024)}MB`,
|
|
26
|
-
heapUsed: `${Math.round(usage.heapUsed / 1024 / 1024)}MB`,
|
|
27
|
-
heapTotal: `${Math.round(usage.heapTotal / 1024 / 1024)}MB`,
|
|
28
|
-
external: `${Math.round(usage.external / 1024 / 1024)}MB`,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
// Cleanup function to clear timeouts and listeners
|
|
33
|
-
const cleanup = () => {
|
|
34
|
-
if (globalTimeout) {
|
|
35
|
-
clearTimeout(globalTimeout);
|
|
36
|
-
}
|
|
37
|
-
// Clear any other timeouts that might be running
|
|
38
|
-
// Note: process.emit('cleanup') is not a standard Node.js event
|
|
39
|
-
};
|
|
40
|
-
// Handle process cleanup
|
|
41
|
-
process.on("SIGINT", cleanup);
|
|
42
|
-
process.on("SIGTERM", cleanup);
|
|
43
|
-
process.on("exit", cleanup);
|
|
44
|
-
// === INITIALIZATION ===
|
|
45
|
-
console.log("📦 === INITIALIZATION ===\n");
|
|
46
|
-
// Set SEA on Gun globally BEFORE creating instance
|
|
47
|
-
index_1.Gun.SEA = index_1.SEA;
|
|
48
|
-
// Debug: Check if SEA is available
|
|
49
|
-
console.log("[DEBUG] SEA available:", !!index_1.SEA);
|
|
50
|
-
console.log("[DEBUG] Gun.SEA available:", !!index_1.Gun.SEA);
|
|
51
|
-
// Create Gun instance first
|
|
52
|
-
// Note: Enabling localStorage allows operations to work offline/without peer acknowledgment
|
|
53
|
-
// In Node.js, Gun will use an in-memory store if localStorage isn't available
|
|
54
|
-
const gunInstance = (0, index_1.Gun)({
|
|
55
|
-
peers: [
|
|
56
|
-
"https://g3ru5bwxmezpuu3ktnoclbpiw4.srv.us/gun",
|
|
57
|
-
"https://5eh4twk2f62autunsje4panime.srv.us/gun",
|
|
58
|
-
],
|
|
59
|
-
radisk: false,
|
|
60
|
-
localStorage: false, // Enable for testing - allows offline operations
|
|
61
|
-
// Reduce log noise from SEA verification errors (these are expected when checking invalid credentials)
|
|
62
|
-
log: () => { }, // Disable Gun.js console logging to reduce noise
|
|
63
|
-
});
|
|
64
|
-
// Attach SEA to Gun instance for Node.js environment
|
|
65
|
-
gunInstance.SEA = index_1.SEA;
|
|
66
|
-
// Also set SEA on global Gun for CryptoIdentityManager fallback
|
|
67
|
-
if (index_1.Gun && !index_1.Gun.SEA) {
|
|
68
|
-
index_1.Gun.SEA = index_1.SEA;
|
|
69
|
-
}
|
|
70
|
-
// Set on globalThis as well
|
|
71
|
-
if (globalThis.Gun) {
|
|
72
|
-
globalThis.Gun.SEA = index_1.SEA;
|
|
73
|
-
}
|
|
74
|
-
globalThis.SEA = index_1.SEA;
|
|
75
|
-
console.log("[DEBUG] gunInstance.SEA available:", !!gunInstance.SEA);
|
|
76
|
-
console.log("[DEBUG] Gun.SEA available:", !!index_1.Gun.SEA);
|
|
77
|
-
console.log("[DEBUG] globalThis.SEA available:", !!globalThis.SEA);
|
|
78
|
-
// Use ShogunCore with existing Gun instance
|
|
79
|
-
const shogunCore = new core_1.ShogunCore({
|
|
80
|
-
gunInstance: gunInstance,
|
|
81
|
-
});
|
|
82
|
-
try {
|
|
83
|
-
console.log("✓ ShogunCore initialized successfully");
|
|
84
|
-
logMemoryUsage("After Init");
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
console.error("❌ Failed to initialize ShogunCore:", error);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const db = shogunCore.db;
|
|
91
|
-
console.log("peers:", db.gun._.opt.peers);
|
|
92
|
-
console.log("- Database instance:", db ? "Available" : "Not available");
|
|
93
|
-
const user = db.gun.user();
|
|
94
|
-
const currentUserInfo = user?.is
|
|
95
|
-
? { alias: user.is.alias, pub: user.is.pub }
|
|
96
|
-
: null;
|
|
97
|
-
console.log("- Current user:", currentUserInfo?.alias || "None");
|
|
98
|
-
console.log("- Is logged in:", db.isLoggedIn());
|
|
99
|
-
console.log("");
|
|
100
|
-
logMemoryUsage("Before Tests");
|
|
101
|
-
// === TEST 1: BASIC SIGNUP AND LOGIN ===
|
|
102
|
-
console.log("🧪 === TEST 1: BASIC SIGNUP AND LOGIN ===\n");
|
|
103
|
-
const testUsername = "scobru";
|
|
104
|
-
const testPassword = "francos88";
|
|
105
|
-
// Clean up any existing session
|
|
106
|
-
console.log("🧹 Cleaning up any existing session...");
|
|
107
|
-
db.logout();
|
|
108
|
-
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second
|
|
109
|
-
// Force reset auth state for problematic users
|
|
110
|
-
if (testUsername === "scobru") {
|
|
111
|
-
console.log("🔧 Performing aggressive cleanup for problematic user...");
|
|
112
|
-
db.aggressiveAuthCleanup();
|
|
113
|
-
await new Promise((resolve) => setTimeout(resolve, 3000)); // Wait 3 seconds
|
|
114
|
-
console.log("✓ Aggressive cleanup completed");
|
|
115
|
-
}
|
|
116
|
-
console.log("✓ Session cleanup completed\n");
|
|
117
|
-
console.log(`Testing with username: ${testUsername}`);
|
|
118
|
-
console.log(`Password: ${testPassword}\n`);
|
|
119
|
-
// Test signup
|
|
120
|
-
console.log("🔄 Attempting signup...");
|
|
121
|
-
const signupStartTime = Date.now();
|
|
122
|
-
// Check if user already exists before signup
|
|
123
|
-
console.log(`🔍 Pre-signup check for user: ${testUsername}`);
|
|
124
|
-
const preSignupCheck = await new Promise((resolve) => {
|
|
125
|
-
const timeout = setTimeout(() => {
|
|
126
|
-
console.log("⏰ Pre-signup check timeout");
|
|
127
|
-
resolve(false);
|
|
128
|
-
}, 3000);
|
|
129
|
-
db.gun.get(`~@${testUsername}`).once((data) => {
|
|
130
|
-
clearTimeout(timeout);
|
|
131
|
-
console.log("📊 Pre-signup data:", data ? "User exists" : "User not found");
|
|
132
|
-
if (data) {
|
|
133
|
-
console.log("🔑 User pub:", data.pub ? `${data.pub.substring(0, 20)}...` : "None");
|
|
134
|
-
console.log("📝 User keys:", Object.keys(data));
|
|
135
|
-
}
|
|
136
|
-
resolve(!!data && !!data.pub);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
if (preSignupCheck) {
|
|
140
|
-
console.log("⚠️ User already exists, skipping signup and going directly to login");
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
try {
|
|
144
|
-
// Signup without timeout (the database now handles this properly)
|
|
145
|
-
const signupResult = await db.signUp(testUsername, testPassword);
|
|
146
|
-
const signupDuration = Date.now() - signupStartTime;
|
|
147
|
-
console.log(`✓ Signup completed in ${signupDuration}ms`);
|
|
148
|
-
console.log("Signup result:", {
|
|
149
|
-
success: signupResult.success,
|
|
150
|
-
userPub: signupResult.userPub
|
|
151
|
-
? `${signupResult.userPub.substring(0, 20)}...`
|
|
152
|
-
: "None",
|
|
153
|
-
username: signupResult.username,
|
|
154
|
-
isNewUser: signupResult.isNewUser,
|
|
155
|
-
error: signupResult.error || "None",
|
|
156
|
-
});
|
|
157
|
-
if (!signupResult.success) {
|
|
158
|
-
console.log("ℹ️ Signup failed, user might already exist. Will try login...");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
console.log("ℹ️ Signup threw exception, user might already exist. Will try login...");
|
|
163
|
-
console.log("Exception details:", error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Wait a moment before attempting login
|
|
167
|
-
console.log("⏳ Waiting 2 seconds before login attempt...");
|
|
168
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
169
|
-
console.log("");
|
|
170
|
-
// Test login
|
|
171
|
-
console.log("🔄 Attempting login...");
|
|
172
|
-
const loginStartTime = Date.now();
|
|
173
|
-
try {
|
|
174
|
-
// Skip user existence check and try direct login
|
|
175
|
-
console.log("🔄 Attempting direct login (bypassing user existence check)...");
|
|
176
|
-
// Login without timeout (the database now handles this properly)
|
|
177
|
-
const loginResult = await db.login(testUsername, testPassword);
|
|
178
|
-
const loginDuration = Date.now() - loginStartTime;
|
|
179
|
-
console.log(`✓ Login completed in ${loginDuration}ms`);
|
|
180
|
-
console.log("Login result:", {
|
|
181
|
-
success: loginResult.success,
|
|
182
|
-
userPub: loginResult.userPub
|
|
183
|
-
? `${loginResult.userPub.substring(0, 20)}...`
|
|
184
|
-
: "None",
|
|
185
|
-
username: loginResult.username,
|
|
186
|
-
error: loginResult.error || "None",
|
|
187
|
-
});
|
|
188
|
-
if (!loginResult.success) {
|
|
189
|
-
console.error("❌ Login failed:", loginResult.error);
|
|
190
|
-
console.log("ℹ️ If this is a new user, try running the test again after a few seconds");
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
// Verify user state
|
|
194
|
-
console.log("\n🔍 Verifying user state...");
|
|
195
|
-
const userInstance = db.gun.user();
|
|
196
|
-
const currentUser = userInstance?.is
|
|
197
|
-
? {
|
|
198
|
-
alias: userInstance.is.alias,
|
|
199
|
-
pub: userInstance.is.pub,
|
|
200
|
-
epub: userInstance?._?.sea?.epub,
|
|
201
|
-
}
|
|
202
|
-
: null;
|
|
203
|
-
const isLoggedIn = db.isLoggedIn();
|
|
204
|
-
console.log("Current user:", {
|
|
205
|
-
alias: currentUser?.alias || "None",
|
|
206
|
-
pub: currentUser?.pub ? `${currentUser.pub.substring(0, 20)}...` : "None",
|
|
207
|
-
epub: currentUser?.epub
|
|
208
|
-
? `${currentUser.epub.substring(0, 20)}...`
|
|
209
|
-
: "None",
|
|
210
|
-
});
|
|
211
|
-
console.log("Is logged in:", isLoggedIn);
|
|
212
|
-
if (!isLoggedIn || !currentUser) {
|
|
213
|
-
console.error("❌ User state verification failed");
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
console.log("✅ Login verification completed successfully!");
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
console.error("❌ Login threw exception:", error);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
console.log("🔄 Proceeding to next test...");
|
|
223
|
-
console.log("");
|
|
224
|
-
// === TEST 2: DATA OPERATIONS WHILE LOGGED IN ===
|
|
225
|
-
console.log("💾 === TEST 2: DATA OPERATIONS WHILE LOGGED IN ===\n");
|
|
226
|
-
try {
|
|
227
|
-
// Get GUN instance directly from database
|
|
228
|
-
const gunInstance = db.gun;
|
|
229
|
-
const appNode = db.node;
|
|
230
|
-
// Test data storage using GUN directly
|
|
231
|
-
const testData = {
|
|
232
|
-
message: "Hello from auth test!",
|
|
233
|
-
timestamp: Date.now(),
|
|
234
|
-
secret: "This is encrypted data",
|
|
235
|
-
};
|
|
236
|
-
console.log("🔄 Storing data using GUN directly...");
|
|
237
|
-
// Store data using GUN directly without waiting for acknowledgment
|
|
238
|
-
appNode.get("test/encrypted-data").put(testData);
|
|
239
|
-
console.log("✓ Data stored successfully (no ack wait)");
|
|
240
|
-
// Wait a moment for data to be stored
|
|
241
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
242
|
-
console.log("🔄 Retrieving data using GUN directly...");
|
|
243
|
-
// Retrieve data using GUN directly
|
|
244
|
-
const retrievedData = await new Promise((resolve) => {
|
|
245
|
-
const timeout = setTimeout(() => {
|
|
246
|
-
console.log("⏰ Data retrieval timeout");
|
|
247
|
-
resolve(null);
|
|
248
|
-
}, 3000);
|
|
249
|
-
appNode.get("test/encrypted-data").once((data) => {
|
|
250
|
-
clearTimeout(timeout);
|
|
251
|
-
resolve(data);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
if (retrievedData) {
|
|
255
|
-
console.log("✓ Data retrieved:", retrievedData);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
console.log("⚠️ Data retrieval timeout (but this is expected)");
|
|
259
|
-
}
|
|
260
|
-
// Test simple GUN operations
|
|
261
|
-
console.log("\n🔄 Testing simple GUN operations...");
|
|
262
|
-
// Store user profile data
|
|
263
|
-
const profileData = {
|
|
264
|
-
name: "Auth Test User",
|
|
265
|
-
email: "authtest@example.com",
|
|
266
|
-
bio: "Testing authentication flow",
|
|
267
|
-
lastUpdated: Date.now(),
|
|
268
|
-
};
|
|
269
|
-
const userInstance = db.gun.user();
|
|
270
|
-
const currentUser = userInstance?.is ? { pub: userInstance.is.pub } : null;
|
|
271
|
-
if (currentUser?.pub) {
|
|
272
|
-
appNode.get("users").get(currentUser.pub).get("profile").put(profileData);
|
|
273
|
-
console.log("✓ Profile data stored");
|
|
274
|
-
// Wait a moment
|
|
275
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
276
|
-
// Try to retrieve profile
|
|
277
|
-
const profile = await new Promise((resolve) => {
|
|
278
|
-
const timeout = setTimeout(() => {
|
|
279
|
-
console.log("⏰ Profile retrieval timeout");
|
|
280
|
-
resolve(null);
|
|
281
|
-
}, 3000);
|
|
282
|
-
appNode
|
|
283
|
-
.get("users")
|
|
284
|
-
.get(currentUser.pub)
|
|
285
|
-
.get("profile")
|
|
286
|
-
.once((data) => {
|
|
287
|
-
clearTimeout(timeout);
|
|
288
|
-
resolve(data);
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
if (profile) {
|
|
292
|
-
console.log("✓ Profile retrieved:", profile);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
console.log("⚠️ Profile retrieval timeout (but this is expected)");
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
console.log("⚠️ No current user pub available for profile test");
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
catch (error) {
|
|
303
|
-
console.error("❌ Data operations failed:", error);
|
|
304
|
-
}
|
|
305
|
-
console.log("");
|
|
306
|
-
// === TEST 3: LOGOUT ===
|
|
307
|
-
console.log("🚪 === TEST 3: LOGOUT ===\n");
|
|
308
|
-
try {
|
|
309
|
-
console.log("🔄 Attempting logout...");
|
|
310
|
-
// Use GUN logout directly from database instance
|
|
311
|
-
const gunInstance = db.gun;
|
|
312
|
-
gunInstance.user().leave();
|
|
313
|
-
console.log("✓ GUN logout completed");
|
|
314
|
-
// Wait a moment for logout to complete
|
|
315
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
316
|
-
const isStillLoggedIn = db.isLoggedIn();
|
|
317
|
-
const userAfterLogout = db.gun.user();
|
|
318
|
-
const currentUserAfterLogout = userAfterLogout?.is
|
|
319
|
-
? { alias: userAfterLogout.is.alias }
|
|
320
|
-
: null;
|
|
321
|
-
console.log("✓ Logout completed");
|
|
322
|
-
console.log("Is logged in after logout:", isStillLoggedIn);
|
|
323
|
-
console.log("Current user after logout:", currentUserAfterLogout?.alias || "None");
|
|
324
|
-
if (isStillLoggedIn) {
|
|
325
|
-
console.warn("⚠️ User still appears to be logged in after logout");
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
console.log("✓ Logout successful - user is no longer logged in");
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
catch (error) {
|
|
332
|
-
console.error("❌ Logout failed:", error);
|
|
333
|
-
}
|
|
334
|
-
console.log("");
|
|
335
|
-
// === TEST 4: RE-LOGIN ===
|
|
336
|
-
console.log("🔄 === TEST 4: RE-LOGIN ===\n");
|
|
337
|
-
try {
|
|
338
|
-
console.log("🔄 Attempting re-login with same credentials...");
|
|
339
|
-
// Use GUN login directly from database instance
|
|
340
|
-
const gunInstance = db.gun;
|
|
341
|
-
gunInstance.user().auth(testUsername, testPassword);
|
|
342
|
-
// Wait for authentication to complete
|
|
343
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
344
|
-
// Check if authentication was successful
|
|
345
|
-
const user = gunInstance.user();
|
|
346
|
-
const isAuthenticated = !!user.is;
|
|
347
|
-
if (isAuthenticated && user.is) {
|
|
348
|
-
console.log("✓ Re-login successful");
|
|
349
|
-
console.log("User pub:", user.is.pub?.substring(0, 20) + "...");
|
|
350
|
-
console.log("User alias:", user.is.alias || testUsername);
|
|
351
|
-
const currentUserInstance = db.gun.user();
|
|
352
|
-
const currentUserInfo = currentUserInstance?.is
|
|
353
|
-
? { alias: currentUserInstance.is.alias }
|
|
354
|
-
: null;
|
|
355
|
-
console.log("Current user:", currentUserInfo?.alias || "None");
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
console.error("❌ Re-login failed - authentication not successful");
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
catch (error) {
|
|
362
|
-
console.error("❌ Re-login threw exception:", error);
|
|
363
|
-
}
|
|
364
|
-
console.log("");
|
|
365
|
-
// === TEST 5: ERROR HANDLING ===
|
|
366
|
-
console.log("⚠️ === TEST 5: ERROR HANDLING ===\n");
|
|
367
|
-
// Test invalid credentials
|
|
368
|
-
console.log("🔄 Testing invalid password...");
|
|
369
|
-
try {
|
|
370
|
-
const invalidLoginResult = await db.login(testUsername, "wrongpassword");
|
|
371
|
-
console.log("Invalid login result:", {
|
|
372
|
-
success: invalidLoginResult.success,
|
|
373
|
-
error: invalidLoginResult.error || "None",
|
|
374
|
-
});
|
|
375
|
-
if (!invalidLoginResult.success) {
|
|
376
|
-
console.log("✓ Invalid password correctly rejected");
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
console.warn("⚠️ Invalid password was accepted (unexpected)");
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
console.log("✓ Invalid password threw exception (expected):", error instanceof Error ? error.message : String(error));
|
|
384
|
-
}
|
|
385
|
-
// Test non-existent user
|
|
386
|
-
console.log("\n🔄 Testing non-existent user...");
|
|
387
|
-
try {
|
|
388
|
-
const nonexistentLoginResult = await db.login("nonexistentuser123", "password");
|
|
389
|
-
console.log("Non-existent user login result:", {
|
|
390
|
-
success: nonexistentLoginResult.success,
|
|
391
|
-
error: nonexistentLoginResult.error || "None",
|
|
392
|
-
});
|
|
393
|
-
if (!nonexistentLoginResult.success) {
|
|
394
|
-
console.log("✓ Non-existent user correctly rejected");
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
console.warn("⚠️ Non-existent user was accepted (unexpected)");
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
catch (error) {
|
|
401
|
-
console.log("✓ Non-existent user threw exception (expected):", error instanceof Error ? error.message : String(error));
|
|
402
|
-
}
|
|
403
|
-
console.log("");
|
|
404
|
-
// === TEST 6: PASSWORD RECOVERY ===
|
|
405
|
-
// NOTE: Password recovery functions removed in simplified database
|
|
406
|
-
// Skipping password recovery test
|
|
407
|
-
console.log("🔐 === TEST 6: PASSWORD RECOVERY ===\n");
|
|
408
|
-
console.log("ℹ️ Password recovery test skipped (functions removed in simplified database)\n");
|
|
409
|
-
// === FINAL LOGOUT ===
|
|
410
|
-
console.log("🚪 === FINAL CLEANUP ===\n");
|
|
411
|
-
try {
|
|
412
|
-
db.logout();
|
|
413
|
-
console.log("✓ Final logout completed");
|
|
414
|
-
}
|
|
415
|
-
catch (error) {
|
|
416
|
-
console.error("❌ Final logout failed:", error);
|
|
417
|
-
}
|
|
418
|
-
// Clear global timeout
|
|
419
|
-
clearTimeout(globalTimeout);
|
|
420
|
-
// Log memory usage before cleanup
|
|
421
|
-
logMemoryUsage("Before Cleanup");
|
|
422
|
-
// Destroy database instance to prevent memory leaks
|
|
423
|
-
try {
|
|
424
|
-
db.destroy();
|
|
425
|
-
console.log("✓ Database instance destroyed");
|
|
426
|
-
}
|
|
427
|
-
catch (error) {
|
|
428
|
-
console.error("❌ Database destruction failed:", error);
|
|
429
|
-
}
|
|
430
|
-
// Force garbage collection if available
|
|
431
|
-
if (typeof global !== "undefined" && global.gc) {
|
|
432
|
-
global.gc();
|
|
433
|
-
logMemoryUsage("After GC");
|
|
434
|
-
}
|
|
435
|
-
// Additional cleanup
|
|
436
|
-
cleanup();
|
|
437
|
-
// Final memory check
|
|
438
|
-
logMemoryUsage("Final");
|
|
439
|
-
console.log("\n✅ Authentication test completed!");
|
|
440
|
-
console.log("\n📊 Test Summary:");
|
|
441
|
-
console.log("- ✓ Signup with username/password");
|
|
442
|
-
console.log("- ✓ Login with username/password");
|
|
443
|
-
console.log("- ✓ Data operations while logged in");
|
|
444
|
-
console.log("- ✓ Logout functionality");
|
|
445
|
-
console.log("- ✓ Re-login capability");
|
|
446
|
-
console.log("- ✓ Error handling for invalid credentials");
|
|
447
|
-
console.log("- ✓ Error handling for non-existent users");
|
|
448
|
-
// Password recovery tests removed (functions removed in simplified database)
|
|
449
|
-
}
|
|
450
|
-
// Esegui il test
|
|
451
|
-
if (require.main === module) {
|
|
452
|
-
authTest().catch(console.error);
|
|
453
|
-
}
|