@unicitylabs/sphere-sdk 0.3.2 → 0.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.
package/dist/index.cjs CHANGED
@@ -2734,9 +2734,7 @@ var DEV_AGGREGATOR_URL = "https://dev-aggregator.dyndns.org/rpc";
2734
2734
  var TEST_AGGREGATOR_URL = "https://goggregator-test.unicity.network";
2735
2735
  var DEFAULT_AGGREGATOR_TIMEOUT = 3e4;
2736
2736
  var DEFAULT_IPFS_GATEWAYS = [
2737
- "https://ipfs.unicity.network",
2738
- "https://dweb.link",
2739
- "https://ipfs.io"
2737
+ "https://unicity-ipfs1.dyndns.org"
2740
2738
  ];
2741
2739
  var DEFAULT_IPFS_BOOTSTRAP_PEERS = [
2742
2740
  "/dns4/unicity-ipfs2.dyndns.org/tcp/4001/p2p/12D3KooWLNi5NDPPHbrfJakAQqwBqymYTTwMQXQKEWuCrJNDdmfh",
@@ -10071,6 +10069,7 @@ var Sphere = class _Sphere {
10071
10069
  _identity = null;
10072
10070
  _masterKey = null;
10073
10071
  _mnemonic = null;
10072
+ _password = null;
10074
10073
  _source = "unknown";
10075
10074
  _derivationMode = "bip32";
10076
10075
  _basePath = DEFAULT_BASE_PATH;
@@ -10170,7 +10169,8 @@ var Sphere = class _Sphere {
10170
10169
  tokenStorage: options.tokenStorage,
10171
10170
  l1: options.l1,
10172
10171
  price: options.price,
10173
- groupChat
10172
+ groupChat,
10173
+ password: options.password
10174
10174
  });
10175
10175
  return { sphere: sphere2, created: false };
10176
10176
  }
@@ -10196,7 +10196,8 @@ var Sphere = class _Sphere {
10196
10196
  nametag: options.nametag,
10197
10197
  l1: options.l1,
10198
10198
  price: options.price,
10199
- groupChat
10199
+ groupChat,
10200
+ password: options.password
10200
10201
  });
10201
10202
  return { sphere, created: true, generatedMnemonic };
10202
10203
  }
@@ -10243,6 +10244,7 @@ var Sphere = class _Sphere {
10243
10244
  options.price,
10244
10245
  groupChatConfig
10245
10246
  );
10247
+ sphere._password = options.password ?? null;
10246
10248
  await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
10247
10249
  await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
10248
10250
  await sphere.initializeProviders();
@@ -10276,6 +10278,7 @@ var Sphere = class _Sphere {
10276
10278
  options.price,
10277
10279
  groupChatConfig
10278
10280
  );
10281
+ sphere._password = options.password ?? null;
10279
10282
  await sphere.loadIdentityFromStorage();
10280
10283
  await sphere.initializeProviders();
10281
10284
  await sphere.initializeModules();
@@ -10328,6 +10331,7 @@ var Sphere = class _Sphere {
10328
10331
  options.price,
10329
10332
  groupChatConfig
10330
10333
  );
10334
+ sphere._password = options.password ?? null;
10331
10335
  if (options.mnemonic) {
10332
10336
  if (!_Sphere.validateMnemonic(options.mnemonic)) {
10333
10337
  throw new Error("Invalid mnemonic");
@@ -12506,9 +12510,20 @@ var Sphere = class _Sphere {
12506
12510
  // Private: Encryption
12507
12511
  // ===========================================================================
12508
12512
  encrypt(data) {
12509
- return encryptSimple(data, DEFAULT_ENCRYPTION_KEY);
12513
+ if (!this._password) return data;
12514
+ return encryptSimple(data, this._password);
12510
12515
  }
12511
12516
  decrypt(encrypted) {
12517
+ if (this._password) {
12518
+ try {
12519
+ return decryptSimple(encrypted, this._password);
12520
+ } catch {
12521
+ return null;
12522
+ }
12523
+ }
12524
+ if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
12525
+ return encrypted;
12526
+ }
12512
12527
  try {
12513
12528
  return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
12514
12529
  } catch {