shogun-core 4.2.3 → 4.2.4
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/shogun-core.js +102 -162
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/gundb/db.js +102 -162
- package/package.json +1 -1
|
@@ -133841,6 +133841,7 @@ class DataBase {
|
|
|
133841
133841
|
constructor(gun, appScope = "shogun") {
|
|
133842
133842
|
this.user = null;
|
|
133843
133843
|
this.onAuthCallbacks = [];
|
|
133844
|
+
console.log("[DB] Initializing DataBase");
|
|
133844
133845
|
// Initialize event emitter
|
|
133845
133846
|
this.eventEmitter = new eventEmitter_1.EventEmitter();
|
|
133846
133847
|
// Validate Gun instance
|
|
@@ -133860,31 +133861,38 @@ class DataBase {
|
|
|
133860
133861
|
throw new Error(`Gun instance is invalid: gun.on is not a function. Received gun.on type: ${typeof gun.on}`);
|
|
133861
133862
|
}
|
|
133862
133863
|
this.gun = gun;
|
|
133864
|
+
console.log("[DB] Gun instance validated");
|
|
133863
133865
|
// Recall only if NOT disabled and there's a "pair" in sessionStorage
|
|
133864
133866
|
this.user = this.gun.user().recall({ sessionStorage: true });
|
|
133867
|
+
console.log("[DB] User recall completed");
|
|
133865
133868
|
this.subscribeToAuthEvents();
|
|
133869
|
+
console.log("[DB] Auth events subscribed");
|
|
133866
133870
|
this.crypto = crypto;
|
|
133867
133871
|
this.sea = sea_1.default;
|
|
133868
133872
|
this._rxjs = new rxjs_1.RxJS(this.gun);
|
|
133869
133873
|
this.node = null;
|
|
133874
|
+
console.log("[DB] DataBase initialization completed");
|
|
133870
133875
|
}
|
|
133871
133876
|
/**
|
|
133872
133877
|
* Initialize the GunInstance asynchronously
|
|
133873
133878
|
* This method should be called after construction to perform async operations
|
|
133874
133879
|
*/
|
|
133875
133880
|
initialize(appScope = "shogun") {
|
|
133881
|
+
console.log(`[DB] Initializing with appScope: ${appScope}`);
|
|
133876
133882
|
try {
|
|
133877
133883
|
const sessionResult = this.restoreSession();
|
|
133884
|
+
console.log(`[DB] Session restore result: ${sessionResult.success ? "success" : "failed"}`);
|
|
133878
133885
|
this.node = this.gun.get(appScope);
|
|
133886
|
+
console.log("[DB] App scope node initialized");
|
|
133879
133887
|
if (sessionResult.success) {
|
|
133880
|
-
|
|
133888
|
+
console.log("[DB] Session automatically restored");
|
|
133881
133889
|
}
|
|
133882
133890
|
else {
|
|
133883
|
-
|
|
133891
|
+
console.log("[DB] No previous session to restore");
|
|
133884
133892
|
}
|
|
133885
133893
|
}
|
|
133886
133894
|
catch (error) {
|
|
133887
|
-
console.error("Error during automatic session restoration:", error);
|
|
133895
|
+
console.error("[DB] Error during automatic session restoration:", error);
|
|
133888
133896
|
}
|
|
133889
133897
|
}
|
|
133890
133898
|
subscribeToAuthEvents() {
|
|
@@ -133907,13 +133915,16 @@ class DataBase {
|
|
|
133907
133915
|
* @param peer URL of the peer to add
|
|
133908
133916
|
*/
|
|
133909
133917
|
addPeer(peer) {
|
|
133918
|
+
console.log(`[PEER] Adding peer: ${peer}`);
|
|
133910
133919
|
this.gun.opt({ peers: [peer] });
|
|
133920
|
+
console.log(`[PEER] Peer added successfully`);
|
|
133911
133921
|
}
|
|
133912
133922
|
/**
|
|
133913
133923
|
* Removes a peer from the network
|
|
133914
133924
|
* @param peer URL of the peer to remove
|
|
133915
133925
|
*/
|
|
133916
133926
|
removePeer(peer) {
|
|
133927
|
+
console.log(`[PEER] Removing peer: ${peer}`);
|
|
133917
133928
|
try {
|
|
133918
133929
|
// Get current peers from Gun instance
|
|
133919
133930
|
const gunOpts = this.gun._.opt;
|
|
@@ -133925,13 +133936,14 @@ class DataBase {
|
|
|
133925
133936
|
if (peerConnection && typeof peerConnection.close === "function") {
|
|
133926
133937
|
peerConnection.close();
|
|
133927
133938
|
}
|
|
133939
|
+
console.log(`[PEER] Peer removed successfully`);
|
|
133928
133940
|
}
|
|
133929
133941
|
else {
|
|
133930
|
-
console.error(`Peer not found in current connections: ${peer}`);
|
|
133942
|
+
console.error(`[PEER] Peer not found in current connections: ${peer}`);
|
|
133931
133943
|
}
|
|
133932
133944
|
}
|
|
133933
133945
|
catch (error) {
|
|
133934
|
-
console.error(`Error removing peer ${peer}:`, error);
|
|
133946
|
+
console.error(`[PEER] Error removing peer ${peer}:`, error);
|
|
133935
133947
|
}
|
|
133936
133948
|
}
|
|
133937
133949
|
/**
|
|
@@ -134142,16 +134154,7 @@ class DataBase {
|
|
|
134142
134154
|
*/
|
|
134143
134155
|
async put(path, data) {
|
|
134144
134156
|
const node = this.navigateToPath(this.node, path);
|
|
134145
|
-
return
|
|
134146
|
-
node.put(data, (ack) => {
|
|
134147
|
-
if (ack && ack.err) {
|
|
134148
|
-
reject(new Error(ack.err));
|
|
134149
|
-
}
|
|
134150
|
-
else {
|
|
134151
|
-
resolve(ack);
|
|
134152
|
-
}
|
|
134153
|
-
});
|
|
134154
|
-
});
|
|
134157
|
+
return await node.put(data).then();
|
|
134155
134158
|
}
|
|
134156
134159
|
/**
|
|
134157
134160
|
* Sets data at the specified path
|
|
@@ -134161,16 +134164,7 @@ class DataBase {
|
|
|
134161
134164
|
*/
|
|
134162
134165
|
async set(path, data) {
|
|
134163
134166
|
const node = this.navigateToPath(this.node, path);
|
|
134164
|
-
return
|
|
134165
|
-
node.set(data, (ack) => {
|
|
134166
|
-
if (ack && ack.err) {
|
|
134167
|
-
reject(new Error(ack.err));
|
|
134168
|
-
}
|
|
134169
|
-
else {
|
|
134170
|
-
resolve(ack);
|
|
134171
|
-
}
|
|
134172
|
-
});
|
|
134173
|
-
});
|
|
134167
|
+
return await node.set(data).then();
|
|
134174
134168
|
}
|
|
134175
134169
|
/**
|
|
134176
134170
|
* Removes data at the specified path
|
|
@@ -134179,16 +134173,7 @@ class DataBase {
|
|
|
134179
134173
|
*/
|
|
134180
134174
|
async remove(path) {
|
|
134181
134175
|
const node = this.navigateToPath(this.node, path);
|
|
134182
|
-
return
|
|
134183
|
-
node.put(null, (ack) => {
|
|
134184
|
-
if (ack && ack.err) {
|
|
134185
|
-
reject(new Error(ack.err));
|
|
134186
|
-
}
|
|
134187
|
-
else {
|
|
134188
|
-
resolve(ack);
|
|
134189
|
-
}
|
|
134190
|
-
});
|
|
134191
|
-
});
|
|
134176
|
+
return await node.put(null).then();
|
|
134192
134177
|
}
|
|
134193
134178
|
/**
|
|
134194
134179
|
* Checks if a user is currently logged in
|
|
@@ -134691,18 +134676,20 @@ class DataBase {
|
|
|
134691
134676
|
});
|
|
134692
134677
|
}
|
|
134693
134678
|
async runPostAuthOnAuthResult(username, userPub, authResult) {
|
|
134694
|
-
|
|
134679
|
+
console.log(`[POSTAUTH] Starting post-auth setup for user: ${username}, userPub: ${userPub}`);
|
|
134695
134680
|
try {
|
|
134681
|
+
console.log(`[POSTAUTH] Validating parameters for user: ${username}`);
|
|
134696
134682
|
// Validate required parameters
|
|
134697
134683
|
if (!username ||
|
|
134698
134684
|
typeof username !== "string" ||
|
|
134699
134685
|
username.trim().length === 0) {
|
|
134686
|
+
console.error(`[POSTAUTH] Invalid username provided: ${username}`);
|
|
134700
134687
|
throw new Error("Invalid username provided");
|
|
134701
134688
|
}
|
|
134702
134689
|
if (!userPub ||
|
|
134703
134690
|
typeof userPub !== "string" ||
|
|
134704
134691
|
userPub.trim().length === 0) {
|
|
134705
|
-
console.error("Invalid userPub provided:", {
|
|
134692
|
+
console.error("[POSTAUTH] Invalid userPub provided:", {
|
|
134706
134693
|
userPub,
|
|
134707
134694
|
type: typeof userPub,
|
|
134708
134695
|
authResult,
|
|
@@ -134711,34 +134698,38 @@ class DataBase {
|
|
|
134711
134698
|
}
|
|
134712
134699
|
// Additional validation for userPub format
|
|
134713
134700
|
if (!userPub.includes(".") || userPub.length < 10) {
|
|
134714
|
-
console.error(
|
|
134701
|
+
console.error(`[POSTAUTH] Invalid userPub format: ${userPub}`);
|
|
134715
134702
|
throw new Error("Invalid userPub format");
|
|
134716
134703
|
}
|
|
134704
|
+
console.log(`[POSTAUTH] Parameters validated for user: ${username}`);
|
|
134717
134705
|
// Normalize username to prevent path issues
|
|
134718
134706
|
const normalizedUsername = username.trim().toLowerCase();
|
|
134719
134707
|
if (normalizedUsername.length === 0) {
|
|
134708
|
+
console.error(`[POSTAUTH] Normalized username is empty for user: ${username}`);
|
|
134720
134709
|
throw new Error("Username cannot be empty");
|
|
134721
134710
|
}
|
|
134722
|
-
|
|
134723
|
-
|
|
134724
|
-
|
|
134725
|
-
});
|
|
134726
|
-
});
|
|
134711
|
+
console.log(`[POSTAUTH] Normalized username: ${normalizedUsername}`);
|
|
134712
|
+
console.log(`[POSTAUTH] Checking if user exists: ${userPub}`);
|
|
134713
|
+
const existingUser = await this.gun.get(userPub).then();
|
|
134727
134714
|
const isNewUser = !existingUser || !existingUser.alias;
|
|
134728
|
-
|
|
134715
|
+
console.log(`[POSTAUTH] User is ${isNewUser ? "NEW" : "EXISTING"}: ${userPub}`);
|
|
134729
134716
|
// Get user's encryption public key (epub) for comprehensive tracking
|
|
134730
134717
|
const userInstance = this.gun.user();
|
|
134731
134718
|
const userSea = userInstance?._?.sea;
|
|
134732
134719
|
const epub = userSea?.epub;
|
|
134720
|
+
console.log(`[POSTAUTH] User epub retrieved: ${epub ? "yes" : "no"}`);
|
|
134733
134721
|
// Enhanced user tracking system
|
|
134722
|
+
console.log(`[POSTAUTH] Setting up comprehensive user tracking for: ${normalizedUsername}`);
|
|
134734
134723
|
const trackingResult = await this.setupComprehensiveUserTracking(normalizedUsername, userPub, epub);
|
|
134735
134724
|
if (!trackingResult) {
|
|
134725
|
+
console.error(`[POSTAUTH] Comprehensive user tracking setup failed for: ${normalizedUsername}`);
|
|
134736
134726
|
return {
|
|
134737
134727
|
success: false,
|
|
134738
134728
|
error: "Comprehensive user tracking setup failed",
|
|
134739
134729
|
};
|
|
134740
134730
|
}
|
|
134741
|
-
|
|
134731
|
+
console.log(`[POSTAUTH] User tracking setup completed successfully for: ${normalizedUsername}`);
|
|
134732
|
+
const result = {
|
|
134742
134733
|
success: true,
|
|
134743
134734
|
userPub: userPub,
|
|
134744
134735
|
username: normalizedUsername,
|
|
@@ -134753,9 +134744,11 @@ class DataBase {
|
|
|
134753
134744
|
}
|
|
134754
134745
|
: undefined,
|
|
134755
134746
|
};
|
|
134747
|
+
console.log(`[POSTAUTH] Post-auth setup completed successfully for user: ${username}`);
|
|
134748
|
+
return result;
|
|
134756
134749
|
}
|
|
134757
134750
|
catch (error) {
|
|
134758
|
-
console.error(`Error in post-authentication setup
|
|
134751
|
+
console.error(`[POSTAUTH] Error in post-authentication setup for ${username}:`, error);
|
|
134759
134752
|
return {
|
|
134760
134753
|
success: false,
|
|
134761
134754
|
error: `Post-authentication setup failed: ${error}`,
|
|
@@ -134767,43 +134760,66 @@ class DataBase {
|
|
|
134767
134760
|
* Creates multiple indexes for efficient user discovery
|
|
134768
134761
|
*/
|
|
134769
134762
|
async setupComprehensiveUserTracking(username, userPub, epub) {
|
|
134763
|
+
console.log(`[TRACKING] Starting comprehensive user tracking setup for: ${username}, userPub: ${userPub}`);
|
|
134770
134764
|
try {
|
|
134771
134765
|
// 1. Create alias index: ~@alias -> userPub (for GunDB compatibility)
|
|
134766
|
+
console.log(`[TRACKING] Step 1: Creating alias index for ${username}`);
|
|
134772
134767
|
const aliasIndexResult = await this.createAliasIndex(username, userPub);
|
|
134773
134768
|
if (!aliasIndexResult) {
|
|
134769
|
+
console.error(`[TRACKING] Failed to create alias index for ${username}`);
|
|
134774
134770
|
return false;
|
|
134775
134771
|
}
|
|
134772
|
+
console.log(`[TRACKING] Step 1 completed: Alias index created for ${username}`);
|
|
134776
134773
|
// 2. Create username mapping: usernames/alias -> userPub
|
|
134774
|
+
console.log(`[TRACKING] Step 2: Creating username mapping for ${username}`);
|
|
134777
134775
|
const usernameMappingResult = await this.createUsernameMapping(username, userPub);
|
|
134778
134776
|
if (!usernameMappingResult) {
|
|
134777
|
+
console.error(`[TRACKING] Failed to create username mapping for ${username}`);
|
|
134779
134778
|
return false;
|
|
134780
134779
|
}
|
|
134780
|
+
console.log(`[TRACKING] Step 2 completed: Username mapping created for ${username}`);
|
|
134781
134781
|
// 3. Create user registry: users/userPub -> user data
|
|
134782
|
+
console.log(`[TRACKING] Step 3: Creating user registry for ${username}`);
|
|
134782
134783
|
const userRegistryResult = await this.createUserRegistry(username, userPub, epub);
|
|
134783
134784
|
if (!userRegistryResult) {
|
|
134785
|
+
console.error(`[TRACKING] Failed to create user registry for ${username}`);
|
|
134784
134786
|
return false;
|
|
134785
134787
|
}
|
|
134788
|
+
console.log(`[TRACKING] Step 3 completed: User registry created for ${username}`);
|
|
134786
134789
|
// 4. Create reverse lookup: userPub -> alias
|
|
134790
|
+
console.log(`[TRACKING] Step 4: Creating reverse lookup for ${username}`);
|
|
134787
134791
|
const reverseLookupResult = await this.createReverseLookup(username, userPub);
|
|
134788
134792
|
if (!reverseLookupResult) {
|
|
134793
|
+
console.error(`[TRACKING] Failed to create reverse lookup for ${username}`);
|
|
134789
134794
|
return false;
|
|
134790
134795
|
}
|
|
134796
|
+
console.log(`[TRACKING] Step 4 completed: Reverse lookup created for ${username}`);
|
|
134791
134797
|
// 5. Create epub index: epubKeys/epub -> userPub (for encryption lookups)
|
|
134792
134798
|
if (epub) {
|
|
134799
|
+
console.log(`[TRACKING] Step 5: Creating epub index for ${username}`);
|
|
134793
134800
|
const epubIndexResult = await this.createEpubIndex(epub, userPub);
|
|
134794
134801
|
if (!epubIndexResult) {
|
|
134802
|
+
console.error(`[TRACKING] Failed to create epub index for ${username}`);
|
|
134795
134803
|
return false;
|
|
134796
134804
|
}
|
|
134805
|
+
console.log(`[TRACKING] Step 5 completed: Epub index created for ${username}`);
|
|
134806
|
+
}
|
|
134807
|
+
else {
|
|
134808
|
+
console.log(`[TRACKING] Step 5 skipped: No epub available for ${username}`);
|
|
134797
134809
|
}
|
|
134798
134810
|
// 6. Create user metadata in user's own node
|
|
134811
|
+
console.log(`[TRACKING] Step 6: Creating user metadata for ${username}`);
|
|
134799
134812
|
const userMetadataResult = await this.createUserMetadata(username, userPub, epub);
|
|
134800
134813
|
if (!userMetadataResult) {
|
|
134814
|
+
console.error(`[TRACKING] Failed to create user metadata for ${username}`);
|
|
134801
134815
|
return false;
|
|
134802
134816
|
}
|
|
134817
|
+
console.log(`[TRACKING] Step 6 completed: User metadata created for ${username}`);
|
|
134818
|
+
console.log(`[TRACKING] Comprehensive user tracking setup completed successfully for: ${username}`);
|
|
134803
134819
|
return true;
|
|
134804
134820
|
}
|
|
134805
134821
|
catch (error) {
|
|
134806
|
-
console.error(`Error in comprehensive user tracking setup
|
|
134822
|
+
console.error(`[TRACKING] Error in comprehensive user tracking setup for ${username}:`, error);
|
|
134807
134823
|
// Don't throw - continue with other operations
|
|
134808
134824
|
return false;
|
|
134809
134825
|
}
|
|
@@ -134895,20 +134911,18 @@ class DataBase {
|
|
|
134895
134911
|
*/
|
|
134896
134912
|
async createReverseLookup(username, userPub) {
|
|
134897
134913
|
try {
|
|
134898
|
-
|
|
134899
|
-
|
|
134900
|
-
|
|
134901
|
-
|
|
134902
|
-
|
|
134903
|
-
|
|
134904
|
-
|
|
134905
|
-
|
|
134906
|
-
|
|
134907
|
-
|
|
134908
|
-
|
|
134909
|
-
|
|
134910
|
-
});
|
|
134911
|
-
});
|
|
134914
|
+
const ack = await this.node
|
|
134915
|
+
.get("userAliases")
|
|
134916
|
+
.get(userPub)
|
|
134917
|
+
.put(username)
|
|
134918
|
+
.then();
|
|
134919
|
+
if (ack.err) {
|
|
134920
|
+
console.error(`Error creating reverse lookup: ${ack.err}`);
|
|
134921
|
+
return false;
|
|
134922
|
+
}
|
|
134923
|
+
else {
|
|
134924
|
+
return true;
|
|
134925
|
+
}
|
|
134912
134926
|
}
|
|
134913
134927
|
catch (error) {
|
|
134914
134928
|
console.error(`Error creating reverse lookup: ${error}`);
|
|
@@ -134981,14 +134995,9 @@ class DataBase {
|
|
|
134981
134995
|
}
|
|
134982
134996
|
// Method 1: Try GunDB standard alias lookup (~@alias)
|
|
134983
134997
|
try {
|
|
134984
|
-
const aliasData = this.gun.get(`~@${normalizedAlias}`);
|
|
134985
|
-
|
|
134986
|
-
aliasData
|
|
134987
|
-
resolve(data);
|
|
134988
|
-
});
|
|
134989
|
-
});
|
|
134990
|
-
if (aliasDataObj && aliasDataObj["~pubKeyOfUser"]) {
|
|
134991
|
-
const userPub = aliasDataObj["~pubKeyOfUser"]["#"] || aliasDataObj["~pubKeyOfUser"];
|
|
134998
|
+
const aliasData = await this.gun.get(`~@${normalizedAlias}`).then();
|
|
134999
|
+
if (aliasData && aliasData["~pubKeyOfUser"]) {
|
|
135000
|
+
const userPub = aliasData["~pubKeyOfUser"]["#"] || aliasData["~pubKeyOfUser"];
|
|
134992
135001
|
if (userPub) {
|
|
134993
135002
|
const userData = await this.getUserDataByPub(userPub);
|
|
134994
135003
|
if (userData) {
|
|
@@ -135002,14 +135011,10 @@ class DataBase {
|
|
|
135002
135011
|
}
|
|
135003
135012
|
// Method 2: Try username mapping (usernames/alias -> userPub)
|
|
135004
135013
|
try {
|
|
135005
|
-
const userPub = await
|
|
135006
|
-
|
|
135007
|
-
|
|
135008
|
-
|
|
135009
|
-
.once((data) => {
|
|
135010
|
-
resolve(data);
|
|
135011
|
-
});
|
|
135012
|
-
});
|
|
135014
|
+
const userPub = await this.node
|
|
135015
|
+
.get("usernames")
|
|
135016
|
+
.get(normalizedAlias)
|
|
135017
|
+
.then();
|
|
135013
135018
|
if (userPub) {
|
|
135014
135019
|
const userData = await this.getUserDataByPub(userPub);
|
|
135015
135020
|
if (userData) {
|
|
@@ -135039,14 +135044,7 @@ class DataBase {
|
|
|
135039
135044
|
}
|
|
135040
135045
|
// Method 1: Try user registry (users/userPub -> user data)
|
|
135041
135046
|
try {
|
|
135042
|
-
const userData = await
|
|
135043
|
-
this.node
|
|
135044
|
-
.get("users")
|
|
135045
|
-
.get(userPub)
|
|
135046
|
-
.once((data) => {
|
|
135047
|
-
resolve(data);
|
|
135048
|
-
});
|
|
135049
|
-
});
|
|
135047
|
+
const userData = await this.node.get("users").get(userPub).then();
|
|
135050
135048
|
if (userData && userData.username) {
|
|
135051
135049
|
return {
|
|
135052
135050
|
userPub: userData.userPub || userPub,
|
|
@@ -135062,11 +135060,7 @@ class DataBase {
|
|
|
135062
135060
|
}
|
|
135063
135061
|
// Method 2: Try user's own node
|
|
135064
135062
|
try {
|
|
135065
|
-
const userNodeData = await
|
|
135066
|
-
this.gun.get(userPub).once((data) => {
|
|
135067
|
-
resolve(data);
|
|
135068
|
-
});
|
|
135069
|
-
});
|
|
135063
|
+
const userNodeData = await this.gun.get(userPub).then();
|
|
135070
135064
|
if (userNodeData && userNodeData.username) {
|
|
135071
135065
|
return {
|
|
135072
135066
|
userPub: userPub,
|
|
@@ -135097,14 +135091,7 @@ class DataBase {
|
|
|
135097
135091
|
if (!epub || typeof epub !== "string") {
|
|
135098
135092
|
return null;
|
|
135099
135093
|
}
|
|
135100
|
-
const userPub = await
|
|
135101
|
-
this.node
|
|
135102
|
-
.get("epubKeys")
|
|
135103
|
-
.get(epub)
|
|
135104
|
-
.once((data) => {
|
|
135105
|
-
resolve(data);
|
|
135106
|
-
});
|
|
135107
|
-
});
|
|
135094
|
+
const userPub = await this.node.get("epubKeys").get(epub).then();
|
|
135108
135095
|
return userPub || null;
|
|
135109
135096
|
}
|
|
135110
135097
|
catch (error) {
|
|
@@ -135122,14 +135109,7 @@ class DataBase {
|
|
|
135122
135109
|
if (!userPub || typeof userPub !== "string") {
|
|
135123
135110
|
return null;
|
|
135124
135111
|
}
|
|
135125
|
-
const alias = await
|
|
135126
|
-
this.node
|
|
135127
|
-
.get("userAliases")
|
|
135128
|
-
.get(userPub)
|
|
135129
|
-
.once((data) => {
|
|
135130
|
-
resolve(data);
|
|
135131
|
-
});
|
|
135132
|
-
});
|
|
135112
|
+
const alias = await this.node.get("userAliases").get(userPub).then();
|
|
135133
135113
|
return alias || null;
|
|
135134
135114
|
}
|
|
135135
135115
|
catch (error) {
|
|
@@ -135168,39 +135148,19 @@ class DataBase {
|
|
|
135168
135148
|
const timestamp = Date.now();
|
|
135169
135149
|
// Update in user registry
|
|
135170
135150
|
try {
|
|
135171
|
-
await
|
|
135172
|
-
|
|
135173
|
-
|
|
135174
|
-
|
|
135175
|
-
|
|
135176
|
-
|
|
135177
|
-
if (ack && ack.err) {
|
|
135178
|
-
reject(new Error(ack.err));
|
|
135179
|
-
}
|
|
135180
|
-
else {
|
|
135181
|
-
resolve();
|
|
135182
|
-
}
|
|
135183
|
-
});
|
|
135184
|
-
});
|
|
135151
|
+
await this.node
|
|
135152
|
+
.get("users")
|
|
135153
|
+
.get(userPub)
|
|
135154
|
+
.get("lastSeen")
|
|
135155
|
+
.put(timestamp)
|
|
135156
|
+
.then();
|
|
135185
135157
|
}
|
|
135186
135158
|
catch (error) {
|
|
135187
135159
|
console.error(`Failed to update lastSeen in user registry:`, error);
|
|
135188
135160
|
}
|
|
135189
135161
|
// Update in user's own node
|
|
135190
135162
|
try {
|
|
135191
|
-
await
|
|
135192
|
-
this.gun
|
|
135193
|
-
.get(userPub)
|
|
135194
|
-
.get("lastSeen")
|
|
135195
|
-
.put(timestamp, (ack) => {
|
|
135196
|
-
if (ack && ack.err) {
|
|
135197
|
-
reject(new Error(ack.err));
|
|
135198
|
-
}
|
|
135199
|
-
else {
|
|
135200
|
-
resolve();
|
|
135201
|
-
}
|
|
135202
|
-
});
|
|
135203
|
-
});
|
|
135163
|
+
await this.gun.get(userPub).get("lastSeen").put(timestamp).then();
|
|
135204
135164
|
}
|
|
135205
135165
|
catch (error) {
|
|
135206
135166
|
console.error(`Failed to update lastSeen in user node:`, error);
|
|
@@ -135451,19 +135411,10 @@ class DataBase {
|
|
|
135451
135411
|
questions: JSON.stringify(securityQuestions),
|
|
135452
135412
|
hint: encryptedHint,
|
|
135453
135413
|
};
|
|
135454
|
-
const ack = await
|
|
135455
|
-
|
|
135456
|
-
|
|
135457
|
-
|
|
135458
|
-
.put(securityPayload, (ack) => {
|
|
135459
|
-
if (ack && ack.err) {
|
|
135460
|
-
reject(new Error(ack.err));
|
|
135461
|
-
}
|
|
135462
|
-
else {
|
|
135463
|
-
resolve(ack);
|
|
135464
|
-
}
|
|
135465
|
-
});
|
|
135466
|
-
});
|
|
135414
|
+
const ack = await this.node.get(userPub)
|
|
135415
|
+
.get("security")
|
|
135416
|
+
.put(securityPayload)
|
|
135417
|
+
.then();
|
|
135467
135418
|
if (ack.err) {
|
|
135468
135419
|
console.error("Error saving security data to public graph:", ack.err);
|
|
135469
135420
|
throw new Error(ack.err);
|
|
@@ -135486,26 +135437,15 @@ class DataBase {
|
|
|
135486
135437
|
try {
|
|
135487
135438
|
// Find the user's data using direct lookup
|
|
135488
135439
|
const normalizedUsername = username.trim().toLowerCase();
|
|
135489
|
-
const userPub = await
|
|
135490
|
-
|
|
135491
|
-
.get("usernames")
|
|
135492
|
-
.get(normalizedUsername)
|
|
135493
|
-
.once((data) => {
|
|
135494
|
-
resolve(data);
|
|
135495
|
-
});
|
|
135496
|
-
});
|
|
135440
|
+
const userPub = (await this.node.get("usernames").get(normalizedUsername).then()) ||
|
|
135441
|
+
null;
|
|
135497
135442
|
if (!userPub) {
|
|
135498
135443
|
return { success: false, error: "User not found" };
|
|
135499
135444
|
}
|
|
135500
135445
|
// Access the user's security data directly from their public key node
|
|
135501
|
-
const securityData = await
|
|
135502
|
-
|
|
135503
|
-
|
|
135504
|
-
.get("security")
|
|
135505
|
-
.once((data) => {
|
|
135506
|
-
resolve(data);
|
|
135507
|
-
});
|
|
135508
|
-
});
|
|
135446
|
+
const securityData = await this.node.get(userPub)
|
|
135447
|
+
.get("security")
|
|
135448
|
+
.then();
|
|
135509
135449
|
if (!securityData || !securityData.hint) {
|
|
135510
135450
|
return {
|
|
135511
135451
|
success: false,
|