@0xsequence/provider 0.38.2 → 0.39.2

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.
@@ -378,13 +378,18 @@ class BaseProviderTransport {
378
378
 
379
379
 
380
380
  if (message.type === exports.EventType.ACCOUNTS_CHANGED) {
381
- this.accountsChangedPayload = undefined;
381
+ this.accountsChangedPayload = {
382
+ accounts: []
383
+ };
382
384
 
383
385
  if (message.data && message.data.length > 0) {
384
- this.accountsChangedPayload = ethers.ethers.utils.getAddress(message.data[0]);
385
- this.events.emit('accountsChanged', [this.accountsChangedPayload]);
386
+ this.accountsChangedPayload = {
387
+ accounts: [ethers.ethers.utils.getAddress(message.data[0])],
388
+ origin: message.origin
389
+ };
390
+ this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin);
386
391
  } else {
387
- this.events.emit('accountsChanged', []);
392
+ this.events.emit('accountsChanged', [], message.origin);
388
393
  }
389
394
 
390
395
  return;
@@ -1192,7 +1197,7 @@ class WalletRequestHandler {
1192
1197
  };
1193
1198
  }
1194
1199
 
1195
- notifyConnect(connectDetails) {
1200
+ notifyConnect(connectDetails, origin) {
1196
1201
  var _connectDetails$sessi;
1197
1202
 
1198
1203
  this.events.emit('connect', connectDetails);
@@ -1200,13 +1205,12 @@ class WalletRequestHandler {
1200
1205
  if ((_connectDetails$sessi = connectDetails.session) != null && _connectDetails$sessi.accountAddress) {
1201
1206
  var _connectDetails$sessi2;
1202
1207
 
1203
- this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress]);
1208
+ this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress], origin);
1204
1209
  }
1205
1210
  }
1206
1211
 
1207
- notifyDisconnect() {
1208
- this.events.emit('accountsChanged', []);
1209
- this.events.emit('networks', []);
1212
+ notifyDisconnect(origin) {
1213
+ this.events.emit('accountsChanged', [], origin);
1210
1214
  this.events.emit('disconnect');
1211
1215
  }
1212
1216
 
@@ -1703,7 +1707,7 @@ const hexlifyTransaction = (transaction, allowExtra) => {
1703
1707
  return result;
1704
1708
  };
1705
1709
 
1706
- const eip191prefix = ethers.ethers.utils.toUtf8Bytes("\x19Ethereum Signed Message:\n");
1710
+ const eip191prefix = ethers.ethers.utils.toUtf8Bytes('\x19Ethereum Signed Message:\n');
1707
1711
  const messageToBytes = message => {
1708
1712
  if (ethers.ethers.utils.isBytes(message) || ethers.ethers.utils.isHexString(message)) {
1709
1713
  return ethers.ethers.utils.arrayify(message);
@@ -1799,8 +1803,29 @@ const isWalletUpToDate = async (signer, chainId) => {
1799
1803
 
1800
1804
  const isUpToDate = config.isConfigEqual(authChainConfig, requiredChainConfig);
1801
1805
  return isDeployed && isUpToDate;
1802
- }; // window.localstorage helper
1806
+ };
1807
+ class LocalStorage {
1808
+ constructor() {}
1809
+
1810
+ static getInstance() {
1811
+ if (!LocalStorage._instance) {
1812
+ LocalStorage._instance = {
1813
+ getItem: key => Promise.resolve(window.localStorage.getItem(key)),
1814
+ setItem: (key, value) => Promise.resolve(window.localStorage.setItem(key, value)),
1815
+ removeItem: key => Promise.resolve(window.localStorage.removeItem(key))
1816
+ };
1817
+ }
1818
+
1819
+ return this._instance;
1820
+ }
1821
+
1822
+ static use(instance) {
1823
+ LocalStorage._instance = instance;
1824
+ }
1825
+
1826
+ } // window.localstorage helper
1803
1827
 
1828
+ LocalStorage._instance = void 0;
1804
1829
  class LocalStore {
1805
1830
  constructor(key, def) {
1806
1831
  this.def = def;
@@ -1808,8 +1833,8 @@ class LocalStore {
1808
1833
  this.key = key;
1809
1834
  }
1810
1835
 
1811
- get() {
1812
- const val = window.localStorage.getItem(this.key);
1836
+ async get() {
1837
+ const val = await LocalStorage.getInstance().getItem(this.key);
1813
1838
 
1814
1839
  if (val === null) {
1815
1840
  return this.def;
@@ -1825,11 +1850,11 @@ class LocalStore {
1825
1850
  }
1826
1851
 
1827
1852
  set(val) {
1828
- val ? window.localStorage.setItem(this.key, JSON.stringify(val)) : window.localStorage.removeItem(this.key);
1853
+ val ? LocalStorage.getInstance().setItem(this.key, JSON.stringify(val)) : LocalStorage.getInstance().removeItem(this.key);
1829
1854
  }
1830
1855
 
1831
1856
  del() {
1832
- window.localStorage.removeItem(this.key);
1857
+ LocalStorage.getInstance().removeItem(this.key);
1833
1858
  }
1834
1859
 
1835
1860
  }
@@ -2052,11 +2077,11 @@ class BaseWalletTransport {
2052
2077
  };
2053
2078
 
2054
2079
  this.saveTransportSession = session => {
2055
- window.localStorage.setItem(TRANSPORT_SESSION_LS_KEY, JSON.stringify(session));
2080
+ LocalStorage.getInstance().setItem(TRANSPORT_SESSION_LS_KEY, JSON.stringify(session));
2056
2081
  };
2057
2082
 
2058
- this.getCachedTransportSession = () => {
2059
- const session = window.localStorage.getItem(TRANSPORT_SESSION_LS_KEY);
2083
+ this.getCachedTransportSession = async function () {
2084
+ const session = await LocalStorage.getInstance().getItem(TRANSPORT_SESSION_LS_KEY);
2060
2085
 
2061
2086
  try {
2062
2087
  return session ? JSON.parse(session) : null;
@@ -2078,9 +2103,9 @@ class BaseWalletTransport {
2078
2103
 
2079
2104
  this.notifyDisconnect(error);
2080
2105
  });
2081
- this.walletRequestHandler.on('accountsChanged', accounts => {
2106
+ this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
2082
2107
  if (!this.registered) return;
2083
- this.notifyAccountsChanged(accounts);
2108
+ this.notifyAccountsChanged(accounts, origin);
2084
2109
  });
2085
2110
  this.walletRequestHandler.on('networks', networks => {
2086
2111
  if (!this.registered) return;
@@ -2165,11 +2190,12 @@ class BaseWalletTransport {
2165
2190
  });
2166
2191
  }
2167
2192
 
2168
- notifyAccountsChanged(accounts) {
2193
+ notifyAccountsChanged(accounts, origin) {
2169
2194
  this.sendMessage({
2170
2195
  idx: -1,
2171
2196
  type: exports.EventType.ACCOUNTS_CHANGED,
2172
- data: accounts
2197
+ data: accounts,
2198
+ origin: origin
2173
2199
  });
2174
2200
  }
2175
2201
 
@@ -2433,14 +2459,14 @@ class ProxyMessageHandler extends BaseWalletTransport {
2433
2459
  this._registered = true;
2434
2460
  } // note: we can't decide whether to restore the session within register(), because session info is
2435
2461
  // received asyncronously via EventType.OPEN after register() is executed.
2436
- // And in the case of a redirect/reload, EventType.OPEN is not sent at all,
2462
+ // And in the case of a redirect/reload, EventType.OPEN is not sent at all,
2437
2463
  // because the wallet is already open.
2438
2464
  //
2439
2465
  // call this method from wallet redirect hander when a session restore is needed
2440
2466
 
2441
2467
 
2442
- restoreSession() {
2443
- const cachedSession = this.getCachedTransportSession();
2468
+ async restoreSession() {
2469
+ const cachedSession = await this.getCachedTransportSession();
2444
2470
 
2445
2471
  if (cachedSession) {
2446
2472
  this.open(cachedSession);
@@ -2864,7 +2890,7 @@ class WindowMessageHandler extends BaseWalletTransport {
2864
2890
  this._init = exports.InitState.NIL;
2865
2891
  }
2866
2892
 
2867
- register(windowHref) {
2893
+ async register(windowHref) {
2868
2894
  const isPopup = parent.window.opener !== null;
2869
2895
  this._isPopup = isPopup;
2870
2896
 
@@ -2882,7 +2908,7 @@ class WindowMessageHandler extends BaseWalletTransport {
2882
2908
  const isNewWindowSession = !!session.sessionId; // attempt to restore previous session in the case of a redirect or window reload
2883
2909
 
2884
2910
  if (!isNewWindowSession) {
2885
- session = this.getCachedTransportSession();
2911
+ session = await this.getCachedTransportSession();
2886
2912
  }
2887
2913
 
2888
2914
  if (!session) {
@@ -3302,9 +3328,21 @@ class Wallet {
3302
3328
  } else {
3303
3329
  this.useSession(session, true);
3304
3330
  }
3305
- }); // below will update the account upon wallet connect/disconnect (aka, login/logout)
3331
+ }); // below will update the account upon wallet connect/disconnect - aka, login/logout.
3332
+ // if an origin is provided, this operation should be performed only on that origin
3333
+ // and shouldn't affect the session of the wallet.
3334
+
3335
+ this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
3336
+ if (origin) {
3337
+ if (accounts.length > 0) {
3338
+ this.useSession({
3339
+ accountAddress: accounts[0]
3340
+ }, true);
3341
+ }
3342
+
3343
+ return;
3344
+ }
3306
3345
 
3307
- this.transport.messageProvider.on('accountsChanged', accounts => {
3308
3346
  if (!accounts || accounts.length === 0 || accounts[0] === '') {
3309
3347
  this.clearSession();
3310
3348
  } else {
@@ -3326,11 +3364,11 @@ class Wallet {
3326
3364
  }, true);
3327
3365
  }); // Load existing session from localStorage
3328
3366
 
3329
- const session = this.loadSession();
3330
-
3331
- if (session) {
3332
- this.useSession(session, false);
3333
- }
3367
+ this.loadSession().then(session => {
3368
+ if (session) {
3369
+ this.useSession(session, false);
3370
+ }
3371
+ });
3334
3372
  };
3335
3373
 
3336
3374
  this.connect = async function (options) {
@@ -3338,7 +3376,7 @@ class Wallet {
3338
3376
  _this.disconnect();
3339
3377
  }
3340
3378
 
3341
- if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
3379
+ if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
3342
3380
  return {
3343
3381
  connected: true,
3344
3382
  session: _this.session,
@@ -3464,8 +3502,8 @@ class Wallet {
3464
3502
  this.transport.messageProvider.closeWallet();
3465
3503
  };
3466
3504
 
3467
- this.loadSession = () => {
3468
- const data = window.localStorage.getItem('@sequence.session');
3505
+ this.loadSession = async function () {
3506
+ const data = await LocalStorage.getInstance().getItem('@sequence.session');
3469
3507
 
3470
3508
  if (!data || data === '') {
3471
3509
  return undefined;
@@ -3483,7 +3521,7 @@ class Wallet {
3483
3521
  this.saveSession = session => {
3484
3522
  utils.logger.debug('wallet provider: saving session');
3485
3523
  const data = JSON.stringify(session);
3486
- window.localStorage.setItem('@sequence.session', data);
3524
+ LocalStorage.getInstance().setItem('@sequence.session', data);
3487
3525
  };
3488
3526
 
3489
3527
  this.useSession = async function (session, autoSave = true) {
@@ -3530,6 +3568,10 @@ class Wallet {
3530
3568
  this.config.defaultNetworkId = 'mainnet';
3531
3569
  }
3532
3570
 
3571
+ if (config != null && config.localStorage) {
3572
+ LocalStorage.use(config.localStorage);
3573
+ }
3574
+
3533
3575
  this.transport = {};
3534
3576
  this.networks = [];
3535
3577
  this.providers = {};
@@ -3538,9 +3580,9 @@ class Wallet {
3538
3580
  this.init();
3539
3581
  }
3540
3582
 
3541
- addConnectedSite(origin) {
3583
+ async addConnectedSite(origin) {
3542
3584
  origin = origin || window.location.origin;
3543
- const connectedSites = this.connectedSites.get();
3585
+ const connectedSites = await this.connectedSites.get();
3544
3586
 
3545
3587
  if (connectedSites) {
3546
3588
  if (connectedSites.includes(origin)) {
@@ -3553,8 +3595,8 @@ class Wallet {
3553
3595
  }
3554
3596
  }
3555
3597
 
3556
- removeConnectedSite(origin) {
3557
- const authorized = this.connectedSites.get();
3598
+ async removeConnectedSite(origin) {
3599
+ const authorized = await this.connectedSites.get();
3558
3600
 
3559
3601
  if (authorized) {
3560
3602
  this.connectedSites.set(authorized.filter(domain => domain !== origin));
@@ -3565,8 +3607,8 @@ class Wallet {
3565
3607
  return this.connectedSites.get();
3566
3608
  }
3567
3609
 
3568
- isSiteConnected(origin) {
3569
- const authorized = this.connectedSites.get();
3610
+ async isSiteConnected(origin) {
3611
+ const authorized = await this.connectedSites.get();
3570
3612
  return !!authorized && authorized.includes(origin || window.location.origin);
3571
3613
  }
3572
3614
 
@@ -3730,7 +3772,7 @@ class Wallet {
3730
3772
  var _this$transport$cache;
3731
3773
 
3732
3774
  utils.logger.debug('wallet provider: clearing session');
3733
- window.localStorage.removeItem('@sequence.session');
3775
+ LocalStorage.getInstance().removeItem('@sequence.session');
3734
3776
  this.session = undefined;
3735
3777
  this.networks = [];
3736
3778
  this.providers = {};
@@ -3759,6 +3801,7 @@ exports.DefaultProviderConfig = DefaultProviderConfig;
3759
3801
  exports.ErrSignedInRequired = ErrSignedInRequired;
3760
3802
  exports.ExtensionMessageHandler = ExtensionMessageHandler;
3761
3803
  exports.ExtensionMessageProvider = ExtensionMessageProvider;
3804
+ exports.LocalStorage = LocalStorage;
3762
3805
  exports.LocalStore = LocalStore;
3763
3806
  exports.LocalWeb3Provider = LocalWeb3Provider;
3764
3807
  exports.MuxMessageProvider = MuxMessageProvider;
@@ -378,13 +378,18 @@ class BaseProviderTransport {
378
378
 
379
379
 
380
380
  if (message.type === exports.EventType.ACCOUNTS_CHANGED) {
381
- this.accountsChangedPayload = undefined;
381
+ this.accountsChangedPayload = {
382
+ accounts: []
383
+ };
382
384
 
383
385
  if (message.data && message.data.length > 0) {
384
- this.accountsChangedPayload = ethers.ethers.utils.getAddress(message.data[0]);
385
- this.events.emit('accountsChanged', [this.accountsChangedPayload]);
386
+ this.accountsChangedPayload = {
387
+ accounts: [ethers.ethers.utils.getAddress(message.data[0])],
388
+ origin: message.origin
389
+ };
390
+ this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin);
386
391
  } else {
387
- this.events.emit('accountsChanged', []);
392
+ this.events.emit('accountsChanged', [], message.origin);
388
393
  }
389
394
 
390
395
  return;
@@ -1192,7 +1197,7 @@ class WalletRequestHandler {
1192
1197
  };
1193
1198
  }
1194
1199
 
1195
- notifyConnect(connectDetails) {
1200
+ notifyConnect(connectDetails, origin) {
1196
1201
  var _connectDetails$sessi;
1197
1202
 
1198
1203
  this.events.emit('connect', connectDetails);
@@ -1200,13 +1205,12 @@ class WalletRequestHandler {
1200
1205
  if ((_connectDetails$sessi = connectDetails.session) != null && _connectDetails$sessi.accountAddress) {
1201
1206
  var _connectDetails$sessi2;
1202
1207
 
1203
- this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress]);
1208
+ this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress], origin);
1204
1209
  }
1205
1210
  }
1206
1211
 
1207
- notifyDisconnect() {
1208
- this.events.emit('accountsChanged', []);
1209
- this.events.emit('networks', []);
1212
+ notifyDisconnect(origin) {
1213
+ this.events.emit('accountsChanged', [], origin);
1210
1214
  this.events.emit('disconnect');
1211
1215
  }
1212
1216
 
@@ -1703,7 +1707,7 @@ const hexlifyTransaction = (transaction, allowExtra) => {
1703
1707
  return result;
1704
1708
  };
1705
1709
 
1706
- const eip191prefix = ethers.ethers.utils.toUtf8Bytes("\x19Ethereum Signed Message:\n");
1710
+ const eip191prefix = ethers.ethers.utils.toUtf8Bytes('\x19Ethereum Signed Message:\n');
1707
1711
  const messageToBytes = message => {
1708
1712
  if (ethers.ethers.utils.isBytes(message) || ethers.ethers.utils.isHexString(message)) {
1709
1713
  return ethers.ethers.utils.arrayify(message);
@@ -1799,8 +1803,29 @@ const isWalletUpToDate = async (signer, chainId) => {
1799
1803
 
1800
1804
  const isUpToDate = config.isConfigEqual(authChainConfig, requiredChainConfig);
1801
1805
  return isDeployed && isUpToDate;
1802
- }; // window.localstorage helper
1806
+ };
1807
+ class LocalStorage {
1808
+ constructor() {}
1809
+
1810
+ static getInstance() {
1811
+ if (!LocalStorage._instance) {
1812
+ LocalStorage._instance = {
1813
+ getItem: key => Promise.resolve(window.localStorage.getItem(key)),
1814
+ setItem: (key, value) => Promise.resolve(window.localStorage.setItem(key, value)),
1815
+ removeItem: key => Promise.resolve(window.localStorage.removeItem(key))
1816
+ };
1817
+ }
1818
+
1819
+ return this._instance;
1820
+ }
1821
+
1822
+ static use(instance) {
1823
+ LocalStorage._instance = instance;
1824
+ }
1825
+
1826
+ } // window.localstorage helper
1803
1827
 
1828
+ LocalStorage._instance = void 0;
1804
1829
  class LocalStore {
1805
1830
  constructor(key, def) {
1806
1831
  this.def = def;
@@ -1808,8 +1833,8 @@ class LocalStore {
1808
1833
  this.key = key;
1809
1834
  }
1810
1835
 
1811
- get() {
1812
- const val = window.localStorage.getItem(this.key);
1836
+ async get() {
1837
+ const val = await LocalStorage.getInstance().getItem(this.key);
1813
1838
 
1814
1839
  if (val === null) {
1815
1840
  return this.def;
@@ -1825,11 +1850,11 @@ class LocalStore {
1825
1850
  }
1826
1851
 
1827
1852
  set(val) {
1828
- val ? window.localStorage.setItem(this.key, JSON.stringify(val)) : window.localStorage.removeItem(this.key);
1853
+ val ? LocalStorage.getInstance().setItem(this.key, JSON.stringify(val)) : LocalStorage.getInstance().removeItem(this.key);
1829
1854
  }
1830
1855
 
1831
1856
  del() {
1832
- window.localStorage.removeItem(this.key);
1857
+ LocalStorage.getInstance().removeItem(this.key);
1833
1858
  }
1834
1859
 
1835
1860
  }
@@ -2052,11 +2077,11 @@ class BaseWalletTransport {
2052
2077
  };
2053
2078
 
2054
2079
  this.saveTransportSession = session => {
2055
- window.localStorage.setItem(TRANSPORT_SESSION_LS_KEY, JSON.stringify(session));
2080
+ LocalStorage.getInstance().setItem(TRANSPORT_SESSION_LS_KEY, JSON.stringify(session));
2056
2081
  };
2057
2082
 
2058
- this.getCachedTransportSession = () => {
2059
- const session = window.localStorage.getItem(TRANSPORT_SESSION_LS_KEY);
2083
+ this.getCachedTransportSession = async function () {
2084
+ const session = await LocalStorage.getInstance().getItem(TRANSPORT_SESSION_LS_KEY);
2060
2085
 
2061
2086
  try {
2062
2087
  return session ? JSON.parse(session) : null;
@@ -2078,9 +2103,9 @@ class BaseWalletTransport {
2078
2103
 
2079
2104
  this.notifyDisconnect(error);
2080
2105
  });
2081
- this.walletRequestHandler.on('accountsChanged', accounts => {
2106
+ this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
2082
2107
  if (!this.registered) return;
2083
- this.notifyAccountsChanged(accounts);
2108
+ this.notifyAccountsChanged(accounts, origin);
2084
2109
  });
2085
2110
  this.walletRequestHandler.on('networks', networks => {
2086
2111
  if (!this.registered) return;
@@ -2165,11 +2190,12 @@ class BaseWalletTransport {
2165
2190
  });
2166
2191
  }
2167
2192
 
2168
- notifyAccountsChanged(accounts) {
2193
+ notifyAccountsChanged(accounts, origin) {
2169
2194
  this.sendMessage({
2170
2195
  idx: -1,
2171
2196
  type: exports.EventType.ACCOUNTS_CHANGED,
2172
- data: accounts
2197
+ data: accounts,
2198
+ origin: origin
2173
2199
  });
2174
2200
  }
2175
2201
 
@@ -2433,14 +2459,14 @@ class ProxyMessageHandler extends BaseWalletTransport {
2433
2459
  this._registered = true;
2434
2460
  } // note: we can't decide whether to restore the session within register(), because session info is
2435
2461
  // received asyncronously via EventType.OPEN after register() is executed.
2436
- // And in the case of a redirect/reload, EventType.OPEN is not sent at all,
2462
+ // And in the case of a redirect/reload, EventType.OPEN is not sent at all,
2437
2463
  // because the wallet is already open.
2438
2464
  //
2439
2465
  // call this method from wallet redirect hander when a session restore is needed
2440
2466
 
2441
2467
 
2442
- restoreSession() {
2443
- const cachedSession = this.getCachedTransportSession();
2468
+ async restoreSession() {
2469
+ const cachedSession = await this.getCachedTransportSession();
2444
2470
 
2445
2471
  if (cachedSession) {
2446
2472
  this.open(cachedSession);
@@ -2864,7 +2890,7 @@ class WindowMessageHandler extends BaseWalletTransport {
2864
2890
  this._init = exports.InitState.NIL;
2865
2891
  }
2866
2892
 
2867
- register(windowHref) {
2893
+ async register(windowHref) {
2868
2894
  const isPopup = parent.window.opener !== null;
2869
2895
  this._isPopup = isPopup;
2870
2896
 
@@ -2882,7 +2908,7 @@ class WindowMessageHandler extends BaseWalletTransport {
2882
2908
  const isNewWindowSession = !!session.sessionId; // attempt to restore previous session in the case of a redirect or window reload
2883
2909
 
2884
2910
  if (!isNewWindowSession) {
2885
- session = this.getCachedTransportSession();
2911
+ session = await this.getCachedTransportSession();
2886
2912
  }
2887
2913
 
2888
2914
  if (!session) {
@@ -3302,9 +3328,21 @@ class Wallet {
3302
3328
  } else {
3303
3329
  this.useSession(session, true);
3304
3330
  }
3305
- }); // below will update the account upon wallet connect/disconnect (aka, login/logout)
3331
+ }); // below will update the account upon wallet connect/disconnect - aka, login/logout.
3332
+ // if an origin is provided, this operation should be performed only on that origin
3333
+ // and shouldn't affect the session of the wallet.
3334
+
3335
+ this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
3336
+ if (origin) {
3337
+ if (accounts.length > 0) {
3338
+ this.useSession({
3339
+ accountAddress: accounts[0]
3340
+ }, true);
3341
+ }
3342
+
3343
+ return;
3344
+ }
3306
3345
 
3307
- this.transport.messageProvider.on('accountsChanged', accounts => {
3308
3346
  if (!accounts || accounts.length === 0 || accounts[0] === '') {
3309
3347
  this.clearSession();
3310
3348
  } else {
@@ -3326,11 +3364,11 @@ class Wallet {
3326
3364
  }, true);
3327
3365
  }); // Load existing session from localStorage
3328
3366
 
3329
- const session = this.loadSession();
3330
-
3331
- if (session) {
3332
- this.useSession(session, false);
3333
- }
3367
+ this.loadSession().then(session => {
3368
+ if (session) {
3369
+ this.useSession(session, false);
3370
+ }
3371
+ });
3334
3372
  };
3335
3373
 
3336
3374
  this.connect = async function (options) {
@@ -3338,7 +3376,7 @@ class Wallet {
3338
3376
  _this.disconnect();
3339
3377
  }
3340
3378
 
3341
- if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
3379
+ if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
3342
3380
  return {
3343
3381
  connected: true,
3344
3382
  session: _this.session,
@@ -3464,8 +3502,8 @@ class Wallet {
3464
3502
  this.transport.messageProvider.closeWallet();
3465
3503
  };
3466
3504
 
3467
- this.loadSession = () => {
3468
- const data = window.localStorage.getItem('@sequence.session');
3505
+ this.loadSession = async function () {
3506
+ const data = await LocalStorage.getInstance().getItem('@sequence.session');
3469
3507
 
3470
3508
  if (!data || data === '') {
3471
3509
  return undefined;
@@ -3483,7 +3521,7 @@ class Wallet {
3483
3521
  this.saveSession = session => {
3484
3522
  utils.logger.debug('wallet provider: saving session');
3485
3523
  const data = JSON.stringify(session);
3486
- window.localStorage.setItem('@sequence.session', data);
3524
+ LocalStorage.getInstance().setItem('@sequence.session', data);
3487
3525
  };
3488
3526
 
3489
3527
  this.useSession = async function (session, autoSave = true) {
@@ -3530,6 +3568,10 @@ class Wallet {
3530
3568
  this.config.defaultNetworkId = 'mainnet';
3531
3569
  }
3532
3570
 
3571
+ if (config != null && config.localStorage) {
3572
+ LocalStorage.use(config.localStorage);
3573
+ }
3574
+
3533
3575
  this.transport = {};
3534
3576
  this.networks = [];
3535
3577
  this.providers = {};
@@ -3538,9 +3580,9 @@ class Wallet {
3538
3580
  this.init();
3539
3581
  }
3540
3582
 
3541
- addConnectedSite(origin) {
3583
+ async addConnectedSite(origin) {
3542
3584
  origin = origin || window.location.origin;
3543
- const connectedSites = this.connectedSites.get();
3585
+ const connectedSites = await this.connectedSites.get();
3544
3586
 
3545
3587
  if (connectedSites) {
3546
3588
  if (connectedSites.includes(origin)) {
@@ -3553,8 +3595,8 @@ class Wallet {
3553
3595
  }
3554
3596
  }
3555
3597
 
3556
- removeConnectedSite(origin) {
3557
- const authorized = this.connectedSites.get();
3598
+ async removeConnectedSite(origin) {
3599
+ const authorized = await this.connectedSites.get();
3558
3600
 
3559
3601
  if (authorized) {
3560
3602
  this.connectedSites.set(authorized.filter(domain => domain !== origin));
@@ -3565,8 +3607,8 @@ class Wallet {
3565
3607
  return this.connectedSites.get();
3566
3608
  }
3567
3609
 
3568
- isSiteConnected(origin) {
3569
- const authorized = this.connectedSites.get();
3610
+ async isSiteConnected(origin) {
3611
+ const authorized = await this.connectedSites.get();
3570
3612
  return !!authorized && authorized.includes(origin || window.location.origin);
3571
3613
  }
3572
3614
 
@@ -3730,7 +3772,7 @@ class Wallet {
3730
3772
  var _this$transport$cache;
3731
3773
 
3732
3774
  utils.logger.debug('wallet provider: clearing session');
3733
- window.localStorage.removeItem('@sequence.session');
3775
+ LocalStorage.getInstance().removeItem('@sequence.session');
3734
3776
  this.session = undefined;
3735
3777
  this.networks = [];
3736
3778
  this.providers = {};
@@ -3759,6 +3801,7 @@ exports.DefaultProviderConfig = DefaultProviderConfig;
3759
3801
  exports.ErrSignedInRequired = ErrSignedInRequired;
3760
3802
  exports.ExtensionMessageHandler = ExtensionMessageHandler;
3761
3803
  exports.ExtensionMessageProvider = ExtensionMessageProvider;
3804
+ exports.LocalStorage = LocalStorage;
3762
3805
  exports.LocalStore = LocalStore;
3763
3806
  exports.LocalWeb3Provider = LocalWeb3Provider;
3764
3807
  exports.MuxMessageProvider = MuxMessageProvider;