@0xsequence/provider 0.39.5 → 0.40.1

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.
@@ -3238,7 +3238,7 @@ class WalletUtils {
3238
3238
  }
3239
3239
 
3240
3240
  class Wallet {
3241
- constructor(defaultNetworkId, config) {
3241
+ constructor(_network, config) {
3242
3242
  var _this = this;
3243
3243
 
3244
3244
  this.utils = void 0;
@@ -3566,8 +3566,8 @@ class Wallet {
3566
3566
  this.config = _extends({}, this.config, config);
3567
3567
  }
3568
3568
 
3569
- if (defaultNetworkId) {
3570
- this.config.defaultNetworkId = defaultNetworkId;
3569
+ if (_network) {
3570
+ this.config.defaultNetworkId = _network;
3571
3571
  } else if (!this.config.defaultNetworkId) {
3572
3572
  this.config.defaultNetworkId = 'mainnet';
3573
3573
  }
@@ -3622,7 +3622,9 @@ class Wallet {
3622
3622
  }
3623
3623
 
3624
3624
  this.clearSession();
3625
- }
3625
+ } // TODO: add switchNetwork(network: string | number) which will call wallet_switchEthereumChain
3626
+ // and on successful response, will update the provider info here, etc.
3627
+
3626
3628
 
3627
3629
  getProviderConfig() {
3628
3630
  return this.config;
@@ -3802,6 +3804,22 @@ const DefaultProviderConfig = {
3802
3804
  }
3803
3805
  }
3804
3806
  };
3807
+ let walletInstance;
3808
+ const initWallet = (network, config) => {
3809
+ if (walletInstance && walletInstance.isOpened()) {
3810
+ walletInstance.closeWallet();
3811
+ }
3812
+
3813
+ walletInstance = new Wallet(network, config);
3814
+ return walletInstance;
3815
+ };
3816
+ const getWallet = () => {
3817
+ if (!walletInstance) {
3818
+ throw new Error('Wallet has not been initialized, call sequence.initWallet(network, config) first.');
3819
+ }
3820
+
3821
+ return walletInstance;
3822
+ };
3805
3823
 
3806
3824
  exports.BaseInjectedTransport = BaseInjectedTransport;
3807
3825
  exports.BaseProviderTransport = BaseProviderTransport;
@@ -3828,6 +3846,8 @@ exports.Web3Signer = Web3Signer;
3828
3846
  exports.WindowMessageHandler = WindowMessageHandler;
3829
3847
  exports.WindowMessageProvider = WindowMessageProvider;
3830
3848
  exports.WindowSessionParams = WindowSessionParams;
3849
+ exports.getWallet = getWallet;
3850
+ exports.initWallet = initWallet;
3831
3851
  exports.isBrowserExtension = isBrowserExtension;
3832
3852
  exports.isSequenceProvider = isSequenceProvider;
3833
3853
  exports.isValidMessageSignature = isValidMessageSignature;
@@ -3238,7 +3238,7 @@ class WalletUtils {
3238
3238
  }
3239
3239
 
3240
3240
  class Wallet {
3241
- constructor(defaultNetworkId, config) {
3241
+ constructor(_network, config) {
3242
3242
  var _this = this;
3243
3243
 
3244
3244
  this.utils = void 0;
@@ -3566,8 +3566,8 @@ class Wallet {
3566
3566
  this.config = _extends({}, this.config, config);
3567
3567
  }
3568
3568
 
3569
- if (defaultNetworkId) {
3570
- this.config.defaultNetworkId = defaultNetworkId;
3569
+ if (_network) {
3570
+ this.config.defaultNetworkId = _network;
3571
3571
  } else if (!this.config.defaultNetworkId) {
3572
3572
  this.config.defaultNetworkId = 'mainnet';
3573
3573
  }
@@ -3622,7 +3622,9 @@ class Wallet {
3622
3622
  }
3623
3623
 
3624
3624
  this.clearSession();
3625
- }
3625
+ } // TODO: add switchNetwork(network: string | number) which will call wallet_switchEthereumChain
3626
+ // and on successful response, will update the provider info here, etc.
3627
+
3626
3628
 
3627
3629
  getProviderConfig() {
3628
3630
  return this.config;
@@ -3802,6 +3804,22 @@ const DefaultProviderConfig = {
3802
3804
  }
3803
3805
  }
3804
3806
  };
3807
+ let walletInstance;
3808
+ const initWallet = (network, config) => {
3809
+ if (walletInstance && walletInstance.isOpened()) {
3810
+ walletInstance.closeWallet();
3811
+ }
3812
+
3813
+ walletInstance = new Wallet(network, config);
3814
+ return walletInstance;
3815
+ };
3816
+ const getWallet = () => {
3817
+ if (!walletInstance) {
3818
+ throw new Error('Wallet has not been initialized, call sequence.initWallet(network, config) first.');
3819
+ }
3820
+
3821
+ return walletInstance;
3822
+ };
3805
3823
 
3806
3824
  exports.BaseInjectedTransport = BaseInjectedTransport;
3807
3825
  exports.BaseProviderTransport = BaseProviderTransport;
@@ -3828,6 +3846,8 @@ exports.Web3Signer = Web3Signer;
3828
3846
  exports.WindowMessageHandler = WindowMessageHandler;
3829
3847
  exports.WindowMessageProvider = WindowMessageProvider;
3830
3848
  exports.WindowSessionParams = WindowSessionParams;
3849
+ exports.getWallet = getWallet;
3850
+ exports.initWallet = initWallet;
3831
3851
  exports.isBrowserExtension = isBrowserExtension;
3832
3852
  exports.isSequenceProvider = isSequenceProvider;
3833
3853
  exports.isValidMessageSignature = isValidMessageSignature;
@@ -3234,7 +3234,7 @@ class WalletUtils {
3234
3234
  }
3235
3235
 
3236
3236
  class Wallet {
3237
- constructor(defaultNetworkId, config) {
3237
+ constructor(_network, config) {
3238
3238
  var _this = this;
3239
3239
 
3240
3240
  this.utils = void 0;
@@ -3562,8 +3562,8 @@ class Wallet {
3562
3562
  this.config = _extends({}, this.config, config);
3563
3563
  }
3564
3564
 
3565
- if (defaultNetworkId) {
3566
- this.config.defaultNetworkId = defaultNetworkId;
3565
+ if (_network) {
3566
+ this.config.defaultNetworkId = _network;
3567
3567
  } else if (!this.config.defaultNetworkId) {
3568
3568
  this.config.defaultNetworkId = 'mainnet';
3569
3569
  }
@@ -3618,7 +3618,9 @@ class Wallet {
3618
3618
  }
3619
3619
 
3620
3620
  this.clearSession();
3621
- }
3621
+ } // TODO: add switchNetwork(network: string | number) which will call wallet_switchEthereumChain
3622
+ // and on successful response, will update the provider info here, etc.
3623
+
3622
3624
 
3623
3625
  getProviderConfig() {
3624
3626
  return this.config;
@@ -3798,5 +3800,21 @@ const DefaultProviderConfig = {
3798
3800
  }
3799
3801
  }
3800
3802
  };
3803
+ let walletInstance;
3804
+ const initWallet = (network, config) => {
3805
+ if (walletInstance && walletInstance.isOpened()) {
3806
+ walletInstance.closeWallet();
3807
+ }
3808
+
3809
+ walletInstance = new Wallet(network, config);
3810
+ return walletInstance;
3811
+ };
3812
+ const getWallet = () => {
3813
+ if (!walletInstance) {
3814
+ throw new Error('Wallet has not been initialized, call sequence.initWallet(network, config) first.');
3815
+ }
3816
+
3817
+ return walletInstance;
3818
+ };
3801
3819
 
3802
- export { BaseInjectedTransport, BaseProviderTransport, BaseWalletTransport, CHANNEL_ID, DefaultProviderConfig, ErrSignedInRequired, EventType, ExtensionMessageHandler, ExtensionMessageProvider, InitState, LocalStorage, LocalStore, LocalWeb3Provider, MuxMessageProvider, OpenState, PROVIDER_OPEN_TIMEOUT, ProviderError, ProxyMessageChannel, ProxyMessageChannelPort, ProxyMessageHandler, ProxyMessageProvider, Wallet, WalletRequestHandler, Web3Provider, Web3Signer, WindowMessageHandler, WindowMessageProvider, WindowSessionParams, isBrowserExtension, isSequenceProvider, isValidMessageSignature, isValidSignature, isValidTypedDataSignature, isWalletUpToDate, messageToBytes, nextMessageIdx, prefixEIP191Message, recoverWalletConfig };
3820
+ export { BaseInjectedTransport, BaseProviderTransport, BaseWalletTransport, CHANNEL_ID, DefaultProviderConfig, ErrSignedInRequired, EventType, ExtensionMessageHandler, ExtensionMessageProvider, InitState, LocalStorage, LocalStore, LocalWeb3Provider, MuxMessageProvider, OpenState, PROVIDER_OPEN_TIMEOUT, ProviderError, ProxyMessageChannel, ProxyMessageChannelPort, ProxyMessageHandler, ProxyMessageProvider, Wallet, WalletRequestHandler, Web3Provider, Web3Signer, WindowMessageHandler, WindowMessageProvider, WindowSessionParams, getWallet, initWallet, isBrowserExtension, isSequenceProvider, isValidMessageSignature, isValidSignature, isValidTypedDataSignature, isWalletUpToDate, messageToBytes, nextMessageIdx, prefixEIP191Message, recoverWalletConfig };
@@ -6,6 +6,7 @@ import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, Co
6
6
  import { ItemStore } from './utils';
7
7
  import { WalletUtils } from './utils/index';
8
8
  import { Runtime } from 'webextension-polyfill-ts';
9
+ import { sequence } from '../../0xsequence/src';
9
10
  export interface WalletProvider {
10
11
  connect(options?: ConnectOptions): Promise<ConnectDetails>;
11
12
  disconnect(): void;
@@ -37,7 +38,7 @@ export declare class Wallet implements WalletProvider {
37
38
  private transport;
38
39
  private networks;
39
40
  private providers;
40
- constructor(defaultNetworkId?: string | number, config?: Partial<ProviderConfig>);
41
+ constructor(network?: string | number, config?: Partial<ProviderConfig>);
41
42
  private init;
42
43
  connect: (options?: ConnectOptions | undefined) => Promise<ConnectDetails>;
43
44
  addConnectedSite(origin: string | undefined): Promise<void>;
@@ -99,3 +100,5 @@ export interface ProviderConfig {
99
100
  walletContext?: WalletContext;
100
101
  }
101
102
  export declare const DefaultProviderConfig: ProviderConfig;
103
+ export declare const initWallet: (network?: string | number | undefined, config?: Partial<sequence.provider.ProviderConfig> | undefined) => sequence.provider.Wallet;
104
+ export declare const getWallet: () => sequence.provider.Wallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.39.5",
3
+ "version": "0.40.1",
4
4
  "description": "provider sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
6
6
  "source": "src/index.ts",
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@0xsequence/abi": "^0.39.5",
17
- "@0xsequence/auth": "^0.39.5",
18
- "@0xsequence/config": "^0.39.5",
19
- "@0xsequence/network": "^0.39.5",
20
- "@0xsequence/transactions": "^0.39.5",
21
- "@0xsequence/utils": "^0.39.5",
22
- "@0xsequence/wallet": "^0.39.5",
16
+ "@0xsequence/abi": "^0.40.1",
17
+ "@0xsequence/auth": "^0.40.1",
18
+ "@0xsequence/config": "^0.40.1",
19
+ "@0xsequence/network": "^0.40.1",
20
+ "@0xsequence/transactions": "^0.40.1",
21
+ "@0xsequence/utils": "^0.40.1",
22
+ "@0xsequence/wallet": "^0.40.1",
23
23
  "@ethersproject/abstract-signer": "^5.5.0",
24
24
  "@ethersproject/hash": "^5.5.0",
25
25
  "@ethersproject/providers": "^5.5.1",
package/src/wallet.ts CHANGED
@@ -29,6 +29,7 @@ import { LocalStore, ItemStore, LocalStorage } from './utils'
29
29
  import { WalletUtils } from './utils/index'
30
30
 
31
31
  import { Runtime } from 'webextension-polyfill-ts'
32
+ import { sequence } from '../../0xsequence/src'
32
33
 
33
34
  export interface WalletProvider {
34
35
  connect(options?: ConnectOptions): Promise<ConnectDetails>
@@ -91,15 +92,15 @@ export class Wallet implements WalletProvider {
91
92
  private networks: NetworkConfig[]
92
93
  private providers: { [chainId: number]: Web3Provider }
93
94
 
94
- constructor(defaultNetworkId?: string | number, config?: Partial<ProviderConfig>) {
95
+ constructor(network?: string | number, config?: Partial<ProviderConfig>) {
95
96
  // config is a Partial, so that we may intersect it with the DefaultProviderConfig,
96
97
  // which allows easy overriding and control of the config.
97
98
  this.config = { ...DefaultProviderConfig }
98
99
  if (config) {
99
100
  this.config = { ...this.config, ...config }
100
101
  }
101
- if (defaultNetworkId) {
102
- this.config.defaultNetworkId = defaultNetworkId
102
+ if (network) {
103
+ this.config.defaultNetworkId = network
103
104
  } else if (!this.config.defaultNetworkId) {
104
105
  this.config.defaultNetworkId = 'mainnet'
105
106
  }
@@ -333,6 +334,9 @@ export class Wallet implements WalletProvider {
333
334
  this.clearSession()
334
335
  }
335
336
 
337
+ // TODO: add switchNetwork(network: string | number) which will call wallet_switchEthereumChain
338
+ // and on successful response, will update the provider info here, etc.
339
+
336
340
  getProviderConfig(): ProviderConfig {
337
341
  return this.config
338
342
  }
@@ -713,3 +717,20 @@ export const DefaultProviderConfig: ProviderConfig = {
713
717
  proxyTransport: { enabled: false }
714
718
  }
715
719
  }
720
+
721
+ let walletInstance: Wallet | undefined
722
+
723
+ export const initWallet = (network?: string | number, config?: Partial<ProviderConfig>) => {
724
+ if (walletInstance && walletInstance.isOpened()) {
725
+ walletInstance.closeWallet()
726
+ }
727
+ walletInstance = new Wallet(network, config)
728
+ return walletInstance
729
+ }
730
+
731
+ export const getWallet = () => {
732
+ if (!walletInstance) {
733
+ throw new Error('Wallet has not been initialized, call sequence.initWallet(network, config) first.')
734
+ }
735
+ return walletInstance
736
+ }