@unicitylabs/sphere-sdk 0.3.3 → 0.3.5

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.
@@ -9210,7 +9210,9 @@ function decryptTextFormatKey(encryptedKey, password) {
9210
9210
  const key = deriveLegacyKey(password);
9211
9211
  const decrypted = import_crypto_js7.default.AES.decrypt(encryptedKey, key);
9212
9212
  const result = decrypted.toString(import_crypto_js7.default.enc.Utf8);
9213
- return result || null;
9213
+ if (!result) return null;
9214
+ if (!/^[0-9a-fA-F]+$/.test(result)) return null;
9215
+ return result;
9214
9216
  } catch {
9215
9217
  return null;
9216
9218
  }
@@ -9802,6 +9804,7 @@ var Sphere = class _Sphere {
9802
9804
  _identity = null;
9803
9805
  _masterKey = null;
9804
9806
  _mnemonic = null;
9807
+ _password = null;
9805
9808
  _source = "unknown";
9806
9809
  _derivationMode = "bip32";
9807
9810
  _basePath = DEFAULT_BASE_PATH;
@@ -9901,7 +9904,8 @@ var Sphere = class _Sphere {
9901
9904
  tokenStorage: options.tokenStorage,
9902
9905
  l1: options.l1,
9903
9906
  price: options.price,
9904
- groupChat
9907
+ groupChat,
9908
+ password: options.password
9905
9909
  });
9906
9910
  return { sphere: sphere2, created: false };
9907
9911
  }
@@ -9927,7 +9931,8 @@ var Sphere = class _Sphere {
9927
9931
  nametag: options.nametag,
9928
9932
  l1: options.l1,
9929
9933
  price: options.price,
9930
- groupChat
9934
+ groupChat,
9935
+ password: options.password
9931
9936
  });
9932
9937
  return { sphere, created: true, generatedMnemonic };
9933
9938
  }
@@ -9974,6 +9979,7 @@ var Sphere = class _Sphere {
9974
9979
  options.price,
9975
9980
  groupChatConfig
9976
9981
  );
9982
+ sphere._password = options.password ?? null;
9977
9983
  await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
9978
9984
  await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
9979
9985
  await sphere.initializeProviders();
@@ -10007,6 +10013,7 @@ var Sphere = class _Sphere {
10007
10013
  options.price,
10008
10014
  groupChatConfig
10009
10015
  );
10016
+ sphere._password = options.password ?? null;
10010
10017
  await sphere.loadIdentityFromStorage();
10011
10018
  await sphere.initializeProviders();
10012
10019
  await sphere.initializeModules();
@@ -10059,6 +10066,7 @@ var Sphere = class _Sphere {
10059
10066
  options.price,
10060
10067
  groupChatConfig
10061
10068
  );
10069
+ sphere._password = options.password ?? null;
10062
10070
  if (options.mnemonic) {
10063
10071
  if (!_Sphere.validateMnemonic(options.mnemonic)) {
10064
10072
  throw new Error("Invalid mnemonic");
@@ -11026,7 +11034,7 @@ var Sphere = class _Sphere {
11026
11034
  await provider.initialize();
11027
11035
  }
11028
11036
  await this.reinitializeModulesForNewAddress();
11029
- if (this._identity.nametag) {
11037
+ if (!newNametag) {
11030
11038
  await this.syncIdentityWithTransport();
11031
11039
  }
11032
11040
  if (newNametag) {
@@ -12237,9 +12245,20 @@ var Sphere = class _Sphere {
12237
12245
  // Private: Encryption
12238
12246
  // ===========================================================================
12239
12247
  encrypt(data) {
12240
- return encryptSimple(data, DEFAULT_ENCRYPTION_KEY);
12248
+ if (!this._password) return data;
12249
+ return encryptSimple(data, this._password);
12241
12250
  }
12242
12251
  decrypt(encrypted) {
12252
+ if (this._password) {
12253
+ try {
12254
+ return decryptSimple(encrypted, this._password);
12255
+ } catch {
12256
+ return null;
12257
+ }
12258
+ }
12259
+ if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
12260
+ return encrypted;
12261
+ }
12243
12262
  try {
12244
12263
  return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
12245
12264
  } catch {