@0xsequence/provider 0.39.4 → 0.40.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.
|
@@ -3238,7 +3238,7 @@ class WalletUtils {
|
|
|
3238
3238
|
}
|
|
3239
3239
|
|
|
3240
3240
|
class Wallet {
|
|
3241
|
-
constructor(
|
|
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 (
|
|
3570
|
-
this.config.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;
|
|
@@ -3752,8 +3754,10 @@ class Wallet {
|
|
|
3752
3754
|
if (!this.config.networks && !this.config.networkRpcUrl) {
|
|
3753
3755
|
this.networks = networks;
|
|
3754
3756
|
return;
|
|
3755
|
-
} //
|
|
3757
|
+
} // init networks
|
|
3758
|
+
|
|
3756
3759
|
|
|
3760
|
+
this.networks = networks; // combine custom network config with networks in the session
|
|
3757
3761
|
|
|
3758
3762
|
if (this.config.networks) {
|
|
3759
3763
|
this.networks = networks.map(n => _extends({}, n)); // copy
|
|
@@ -3768,7 +3772,11 @@ class Wallet {
|
|
|
3768
3772
|
|
|
3769
3773
|
|
|
3770
3774
|
if (this.config.networkRpcUrl) {
|
|
3771
|
-
this.networks.find(network => network.isDefaultChain)
|
|
3775
|
+
const network = this.networks.find(network => network.isDefaultChain);
|
|
3776
|
+
|
|
3777
|
+
if (network) {
|
|
3778
|
+
network.rpcUrl = this.config.networkRpcUrl;
|
|
3779
|
+
}
|
|
3772
3780
|
}
|
|
3773
3781
|
}
|
|
3774
3782
|
|
|
@@ -3796,6 +3804,22 @@ const DefaultProviderConfig = {
|
|
|
3796
3804
|
}
|
|
3797
3805
|
}
|
|
3798
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
|
+
};
|
|
3799
3823
|
|
|
3800
3824
|
exports.BaseInjectedTransport = BaseInjectedTransport;
|
|
3801
3825
|
exports.BaseProviderTransport = BaseProviderTransport;
|
|
@@ -3822,6 +3846,8 @@ exports.Web3Signer = Web3Signer;
|
|
|
3822
3846
|
exports.WindowMessageHandler = WindowMessageHandler;
|
|
3823
3847
|
exports.WindowMessageProvider = WindowMessageProvider;
|
|
3824
3848
|
exports.WindowSessionParams = WindowSessionParams;
|
|
3849
|
+
exports.getWallet = getWallet;
|
|
3850
|
+
exports.initWallet = initWallet;
|
|
3825
3851
|
exports.isBrowserExtension = isBrowserExtension;
|
|
3826
3852
|
exports.isSequenceProvider = isSequenceProvider;
|
|
3827
3853
|
exports.isValidMessageSignature = isValidMessageSignature;
|
|
@@ -3238,7 +3238,7 @@ class WalletUtils {
|
|
|
3238
3238
|
}
|
|
3239
3239
|
|
|
3240
3240
|
class Wallet {
|
|
3241
|
-
constructor(
|
|
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 (
|
|
3570
|
-
this.config.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;
|
|
@@ -3752,8 +3754,10 @@ class Wallet {
|
|
|
3752
3754
|
if (!this.config.networks && !this.config.networkRpcUrl) {
|
|
3753
3755
|
this.networks = networks;
|
|
3754
3756
|
return;
|
|
3755
|
-
} //
|
|
3757
|
+
} // init networks
|
|
3758
|
+
|
|
3756
3759
|
|
|
3760
|
+
this.networks = networks; // combine custom network config with networks in the session
|
|
3757
3761
|
|
|
3758
3762
|
if (this.config.networks) {
|
|
3759
3763
|
this.networks = networks.map(n => _extends({}, n)); // copy
|
|
@@ -3768,7 +3772,11 @@ class Wallet {
|
|
|
3768
3772
|
|
|
3769
3773
|
|
|
3770
3774
|
if (this.config.networkRpcUrl) {
|
|
3771
|
-
this.networks.find(network => network.isDefaultChain)
|
|
3775
|
+
const network = this.networks.find(network => network.isDefaultChain);
|
|
3776
|
+
|
|
3777
|
+
if (network) {
|
|
3778
|
+
network.rpcUrl = this.config.networkRpcUrl;
|
|
3779
|
+
}
|
|
3772
3780
|
}
|
|
3773
3781
|
}
|
|
3774
3782
|
|
|
@@ -3796,6 +3804,22 @@ const DefaultProviderConfig = {
|
|
|
3796
3804
|
}
|
|
3797
3805
|
}
|
|
3798
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
|
+
};
|
|
3799
3823
|
|
|
3800
3824
|
exports.BaseInjectedTransport = BaseInjectedTransport;
|
|
3801
3825
|
exports.BaseProviderTransport = BaseProviderTransport;
|
|
@@ -3822,6 +3846,8 @@ exports.Web3Signer = Web3Signer;
|
|
|
3822
3846
|
exports.WindowMessageHandler = WindowMessageHandler;
|
|
3823
3847
|
exports.WindowMessageProvider = WindowMessageProvider;
|
|
3824
3848
|
exports.WindowSessionParams = WindowSessionParams;
|
|
3849
|
+
exports.getWallet = getWallet;
|
|
3850
|
+
exports.initWallet = initWallet;
|
|
3825
3851
|
exports.isBrowserExtension = isBrowserExtension;
|
|
3826
3852
|
exports.isSequenceProvider = isSequenceProvider;
|
|
3827
3853
|
exports.isValidMessageSignature = isValidMessageSignature;
|
|
@@ -3234,7 +3234,7 @@ class WalletUtils {
|
|
|
3234
3234
|
}
|
|
3235
3235
|
|
|
3236
3236
|
class Wallet {
|
|
3237
|
-
constructor(
|
|
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 (
|
|
3566
|
-
this.config.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;
|
|
@@ -3748,8 +3750,10 @@ class Wallet {
|
|
|
3748
3750
|
if (!this.config.networks && !this.config.networkRpcUrl) {
|
|
3749
3751
|
this.networks = networks;
|
|
3750
3752
|
return;
|
|
3751
|
-
} //
|
|
3753
|
+
} // init networks
|
|
3754
|
+
|
|
3752
3755
|
|
|
3756
|
+
this.networks = networks; // combine custom network config with networks in the session
|
|
3753
3757
|
|
|
3754
3758
|
if (this.config.networks) {
|
|
3755
3759
|
this.networks = networks.map(n => _extends({}, n)); // copy
|
|
@@ -3764,7 +3768,11 @@ class Wallet {
|
|
|
3764
3768
|
|
|
3765
3769
|
|
|
3766
3770
|
if (this.config.networkRpcUrl) {
|
|
3767
|
-
this.networks.find(network => network.isDefaultChain)
|
|
3771
|
+
const network = this.networks.find(network => network.isDefaultChain);
|
|
3772
|
+
|
|
3773
|
+
if (network) {
|
|
3774
|
+
network.rpcUrl = this.config.networkRpcUrl;
|
|
3775
|
+
}
|
|
3768
3776
|
}
|
|
3769
3777
|
}
|
|
3770
3778
|
|
|
@@ -3792,5 +3800,21 @@ const DefaultProviderConfig = {
|
|
|
3792
3800
|
}
|
|
3793
3801
|
}
|
|
3794
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
|
+
};
|
|
3795
3819
|
|
|
3796
|
-
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(
|
|
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.
|
|
3
|
+
"version": "0.40.0",
|
|
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.
|
|
17
|
-
"@0xsequence/auth": "^0.
|
|
18
|
-
"@0xsequence/config": "^0.
|
|
19
|
-
"@0xsequence/network": "^0.
|
|
20
|
-
"@0xsequence/transactions": "^0.
|
|
21
|
-
"@0xsequence/utils": "^0.
|
|
22
|
-
"@0xsequence/wallet": "^0.
|
|
16
|
+
"@0xsequence/abi": "^0.40.0",
|
|
17
|
+
"@0xsequence/auth": "^0.40.0",
|
|
18
|
+
"@0xsequence/config": "^0.40.0",
|
|
19
|
+
"@0xsequence/network": "^0.40.0",
|
|
20
|
+
"@0xsequence/transactions": "^0.40.0",
|
|
21
|
+
"@0xsequence/utils": "^0.40.0",
|
|
22
|
+
"@0xsequence/wallet": "^0.40.0",
|
|
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(
|
|
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 (
|
|
102
|
-
this.config.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
|
}
|
|
@@ -619,6 +623,9 @@ export class Wallet implements WalletProvider {
|
|
|
619
623
|
return
|
|
620
624
|
}
|
|
621
625
|
|
|
626
|
+
// init networks
|
|
627
|
+
this.networks = networks
|
|
628
|
+
|
|
622
629
|
// combine custom network config with networks in the session
|
|
623
630
|
if (this.config.networks) {
|
|
624
631
|
this.networks = networks.map(n => ({ ...n })) // copy
|
|
@@ -632,7 +639,10 @@ export class Wallet implements WalletProvider {
|
|
|
632
639
|
|
|
633
640
|
// an extra override for convenience
|
|
634
641
|
if (this.config.networkRpcUrl) {
|
|
635
|
-
this.networks.find(network => network.isDefaultChain)
|
|
642
|
+
const network = this.networks.find(network => network.isDefaultChain)
|
|
643
|
+
if (network) {
|
|
644
|
+
network.rpcUrl = this.config.networkRpcUrl
|
|
645
|
+
}
|
|
636
646
|
}
|
|
637
647
|
}
|
|
638
648
|
|
|
@@ -707,3 +717,20 @@ export const DefaultProviderConfig: ProviderConfig = {
|
|
|
707
717
|
proxyTransport: { enabled: false }
|
|
708
718
|
}
|
|
709
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
|
+
}
|