@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.
package/dist/index.cjs CHANGED
@@ -9477,7 +9477,9 @@ function decryptTextFormatKey(encryptedKey, password) {
9477
9477
  const key = deriveLegacyKey(password);
9478
9478
  const decrypted = import_crypto_js7.default.AES.decrypt(encryptedKey, key);
9479
9479
  const result = decrypted.toString(import_crypto_js7.default.enc.Utf8);
9480
- return result || null;
9480
+ if (!result) return null;
9481
+ if (!/^[0-9a-fA-F]+$/.test(result)) return null;
9482
+ return result;
9481
9483
  } catch {
9482
9484
  return null;
9483
9485
  }
@@ -10069,6 +10071,7 @@ var Sphere = class _Sphere {
10069
10071
  _identity = null;
10070
10072
  _masterKey = null;
10071
10073
  _mnemonic = null;
10074
+ _password = null;
10072
10075
  _source = "unknown";
10073
10076
  _derivationMode = "bip32";
10074
10077
  _basePath = DEFAULT_BASE_PATH;
@@ -10168,7 +10171,8 @@ var Sphere = class _Sphere {
10168
10171
  tokenStorage: options.tokenStorage,
10169
10172
  l1: options.l1,
10170
10173
  price: options.price,
10171
- groupChat
10174
+ groupChat,
10175
+ password: options.password
10172
10176
  });
10173
10177
  return { sphere: sphere2, created: false };
10174
10178
  }
@@ -10194,7 +10198,8 @@ var Sphere = class _Sphere {
10194
10198
  nametag: options.nametag,
10195
10199
  l1: options.l1,
10196
10200
  price: options.price,
10197
- groupChat
10201
+ groupChat,
10202
+ password: options.password
10198
10203
  });
10199
10204
  return { sphere, created: true, generatedMnemonic };
10200
10205
  }
@@ -10241,6 +10246,7 @@ var Sphere = class _Sphere {
10241
10246
  options.price,
10242
10247
  groupChatConfig
10243
10248
  );
10249
+ sphere._password = options.password ?? null;
10244
10250
  await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
10245
10251
  await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
10246
10252
  await sphere.initializeProviders();
@@ -10274,6 +10280,7 @@ var Sphere = class _Sphere {
10274
10280
  options.price,
10275
10281
  groupChatConfig
10276
10282
  );
10283
+ sphere._password = options.password ?? null;
10277
10284
  await sphere.loadIdentityFromStorage();
10278
10285
  await sphere.initializeProviders();
10279
10286
  await sphere.initializeModules();
@@ -10326,6 +10333,7 @@ var Sphere = class _Sphere {
10326
10333
  options.price,
10327
10334
  groupChatConfig
10328
10335
  );
10336
+ sphere._password = options.password ?? null;
10329
10337
  if (options.mnemonic) {
10330
10338
  if (!_Sphere.validateMnemonic(options.mnemonic)) {
10331
10339
  throw new Error("Invalid mnemonic");
@@ -11293,7 +11301,7 @@ var Sphere = class _Sphere {
11293
11301
  await provider.initialize();
11294
11302
  }
11295
11303
  await this.reinitializeModulesForNewAddress();
11296
- if (this._identity.nametag) {
11304
+ if (!newNametag) {
11297
11305
  await this.syncIdentityWithTransport();
11298
11306
  }
11299
11307
  if (newNametag) {
@@ -12504,9 +12512,20 @@ var Sphere = class _Sphere {
12504
12512
  // Private: Encryption
12505
12513
  // ===========================================================================
12506
12514
  encrypt(data) {
12507
- return encryptSimple(data, DEFAULT_ENCRYPTION_KEY);
12515
+ if (!this._password) return data;
12516
+ return encryptSimple(data, this._password);
12508
12517
  }
12509
12518
  decrypt(encrypted) {
12519
+ if (this._password) {
12520
+ try {
12521
+ return decryptSimple(encrypted, this._password);
12522
+ } catch {
12523
+ return null;
12524
+ }
12525
+ }
12526
+ if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
12527
+ return encrypted;
12528
+ }
12510
12529
  try {
12511
12530
  return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
12512
12531
  } catch {