shogun-core 1.3.2 → 1.3.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.
@@ -925,6 +925,8 @@ class GunInstance {
925
925
  sessionStorage.removeItem("gun/");
926
926
  sessionStorage.removeItem("gun/user");
927
927
  sessionStorage.removeItem("gun/auth");
928
+ sessionStorage.removeItem("gun/pair");
929
+ sessionStorage.removeItem("gun/session");
928
930
  (0, logger_1.log)("Session storage cleared");
929
931
  }
930
932
  (0, logger_1.log)("Logout completed successfully");
@@ -1024,10 +1026,25 @@ class GunInstance {
1024
1026
  (0, logger_1.logError)("Error encrypting hint:", encryptError);
1025
1027
  return { success: false, error: "Failed to encrypt password hint" };
1026
1028
  }
1027
- // Save security questions and encrypted hint
1028
- await this.saveUserData("security", {
1029
+ // Save to the public graph, readable by anyone but only decryptable with the right answers.
1030
+ const userPub = currentUser.pub;
1031
+ const securityPayload = {
1029
1032
  questions: JSON.stringify(securityQuestions),
1030
1033
  hint: encryptedHint,
1034
+ };
1035
+ await new Promise((resolve, reject) => {
1036
+ this.gun.get(userPub)
1037
+ .get("security")
1038
+ .put(securityPayload, (ack) => {
1039
+ if (ack.err) {
1040
+ (0, logger_1.logError)("Error saving security data to public graph:", ack.err);
1041
+ reject(new Error(ack.err));
1042
+ }
1043
+ else {
1044
+ (0, logger_1.log)(`Security data saved to public graph for ${userPub}`);
1045
+ resolve();
1046
+ }
1047
+ });
1031
1048
  });
1032
1049
  return { success: true };
1033
1050
  }
@@ -1045,16 +1062,19 @@ class GunInstance {
1045
1062
  async forgotPassword(username, securityAnswers) {
1046
1063
  (0, logger_1.log)("Attempting password recovery for:", username);
1047
1064
  try {
1048
- // Find the user's public key
1049
- const userPub = await this.checkUsernameExists(username);
1050
- if (!userPub) {
1065
+ // Find the user's data
1066
+ const userData = await this.checkUsernameExists(username);
1067
+ if (!userData || !userData.pub) {
1051
1068
  return { success: false, error: "User not found" };
1052
1069
  }
1053
- // Access the user's data using their public key
1054
- const user = this.gun.user(userPub);
1055
- // Retrieve security questions and encrypted hint from the user's graph
1070
+ // Extract the public key from user data
1071
+ const userPub = userData.pub;
1072
+ (0, logger_1.log)(`Found user public key for password recovery: ${userPub}`);
1073
+ // Access the user's security data directly from their public key node
1074
+ // Security data is stored in the user's private space, so we need to access it via their public key
1056
1075
  const securityData = await new Promise((resolve) => {
1057
- user.get("security").once((data) => {
1076
+ this.gun.get(userPub).get("security").once((data) => {
1077
+ (0, logger_1.log)(`Retrieved security data for user ${username}:`, data ? "found" : "not found");
1058
1078
  resolve(data);
1059
1079
  });
1060
1080
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "SHOGUN SDK - Core library for Shogun SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",