@unicitylabs/sphere-sdk 0.12.0-dev.1 → 0.13.0

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.
@@ -10851,6 +10851,7 @@ var PaymentsModule = class _PaymentsModule {
10851
10851
  this.spendQueue.destroy();
10852
10852
  this.reservationLedger.clear();
10853
10853
  this.parsedTokenCache.clear();
10854
+ this.tokens.clear();
10854
10855
  this.unsubscribeStorageEvents();
10855
10856
  }
10856
10857
  // ===========================================================================
@@ -26800,6 +26801,10 @@ var Sphere = class _Sphere {
26800
26801
  _masterKey = null;
26801
26802
  _mnemonic = null;
26802
26803
  _password = null;
26804
+ /** True when the wallet was created/loaded/imported WITH a password. Distinguishes
26805
+ * "no password by design" (encrypt passes through) from "the password is gone" (encrypt
26806
+ * must throw rather than silently write plaintext over an encrypted record). */
26807
+ _passwordProtected = false;
26803
26808
  _source = "unknown";
26804
26809
  _derivationMode = "bip32";
26805
26810
  _basePath = DEFAULT_BASE_PATH;
@@ -27128,6 +27133,7 @@ var Sphere = class _Sphere {
27128
27133
  options.walletApi
27129
27134
  );
27130
27135
  sphere._password = options.password ?? null;
27136
+ sphere._passwordProtected = sphere._password !== null;
27131
27137
  progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
27132
27138
  await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
27133
27139
  await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
@@ -27192,6 +27198,7 @@ var Sphere = class _Sphere {
27192
27198
  options.walletApi
27193
27199
  );
27194
27200
  sphere._password = options.password ?? null;
27201
+ sphere._passwordProtected = sphere._password !== null;
27195
27202
  if (!options.storage.isConnected()) {
27196
27203
  await options.storage.connect();
27197
27204
  }
@@ -27263,6 +27270,7 @@ var Sphere = class _Sphere {
27263
27270
  options.walletApi
27264
27271
  );
27265
27272
  sphere._password = options.password ?? null;
27273
+ sphere._passwordProtected = sphere._password !== null;
27266
27274
  progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
27267
27275
  if (options.mnemonic) {
27268
27276
  if (!_Sphere.validateMnemonic(options.mnemonic)) {
@@ -27619,6 +27627,7 @@ var Sphere = class _Sphere {
27619
27627
  * Check if wallet has BIP32 master key for HD derivation
27620
27628
  */
27621
27629
  hasMasterKey() {
27630
+ this.ensureReady();
27622
27631
  return this._masterKey !== null;
27623
27632
  }
27624
27633
  // ===========================================================================
@@ -27648,12 +27657,14 @@ var Sphere = class _Sphere {
27648
27657
  * Returns null if wallet was imported from file (masterKey only)
27649
27658
  */
27650
27659
  getMnemonic() {
27660
+ this.ensureReady();
27651
27661
  return this._mnemonic;
27652
27662
  }
27653
27663
  /**
27654
27664
  * Get wallet info for backup/export purposes
27655
27665
  */
27656
27666
  getWalletInfo() {
27667
+ this.ensureReady();
27657
27668
  let address0 = null;
27658
27669
  try {
27659
27670
  if (this._identity) {
@@ -29442,6 +29453,9 @@ var Sphere = class _Sphere {
29442
29453
  this._initialized = false;
29443
29454
  this._trackedAddressesLoaded = false;
29444
29455
  this._identity = null;
29456
+ this._mnemonic = null;
29457
+ this._masterKey = null;
29458
+ this._password = null;
29445
29459
  this._trackedAddresses.clear();
29446
29460
  this._addressIdToIndex.clear();
29447
29461
  this._addressNametags.clear();
@@ -29927,7 +29941,12 @@ var Sphere = class _Sphere {
29927
29941
  // Private: Encryption
29928
29942
  // ===========================================================================
29929
29943
  encrypt(data) {
29930
- if (!this._password) return data;
29944
+ if (!this._password) {
29945
+ if (this._passwordProtected) {
29946
+ throw new SphereError("Wallet password is not available", "NOT_INITIALIZED");
29947
+ }
29948
+ return data;
29949
+ }
29931
29950
  return encryptSimple(data, this._password);
29932
29951
  }
29933
29952
  decrypt(encrypted) {