@0xsequence/provider 0.0.0-20230726105834 → 0.0.0-20230726163002
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/0xsequence-provider.cjs.dev.js +32 -17
- package/dist/0xsequence-provider.cjs.prod.js +32 -17
- package/dist/0xsequence-provider.esm.js +33 -19
- package/dist/declarations/src/provider.d.ts +2 -1
- package/dist/declarations/src/types.d.ts +8 -1
- package/package.json +10 -10
- package/src/client.ts +12 -4
- package/src/init.ts +17 -10
- package/src/provider.ts +4 -3
- package/src/types.ts +22 -1
|
@@ -24,6 +24,10 @@ function _extends() {
|
|
|
24
24
|
return _extends.apply(this, arguments);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function isProviderTransport(transport) {
|
|
28
|
+
return transport && typeof transport === 'object' && typeof transport.register === 'function' && typeof transport.unregister === 'function' && typeof transport.openWallet === 'function' && typeof transport.closeWallet === 'function' && typeof transport.isOpened === 'function' && typeof transport.isConnected === 'function' && typeof transport.on === 'function';
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
28
32
|
// argument is for exceptions during the execution, and response is the response payload
|
|
29
33
|
// which may contain the result or an error payload from the wallet.
|
|
@@ -3087,7 +3091,7 @@ class WalletUtils {
|
|
|
3087
3091
|
}
|
|
3088
3092
|
|
|
3089
3093
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3090
|
-
constructor(client, providerFor) {
|
|
3094
|
+
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3091
3095
|
var _this;
|
|
3092
3096
|
// We support a lot of networks
|
|
3093
3097
|
// but we start with the default one
|
|
@@ -3097,6 +3101,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3097
3101
|
this._isSequenceProvider = true;
|
|
3098
3102
|
this.client = client;
|
|
3099
3103
|
this.providerFor = providerFor;
|
|
3104
|
+
this.networks = networks;
|
|
3100
3105
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3101
3106
|
// TODO: Maybe we should emit more events here
|
|
3102
3107
|
_this.emit('chainChanged', chainId);
|
|
@@ -3171,7 +3176,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3171
3176
|
if (chainId === undefined) {
|
|
3172
3177
|
return undefined;
|
|
3173
3178
|
}
|
|
3174
|
-
const resolved = network.findNetworkConfig(
|
|
3179
|
+
const resolved = network.findNetworkConfig(this.networks, chainId);
|
|
3175
3180
|
if (!resolved) {
|
|
3176
3181
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3177
3182
|
}
|
|
@@ -3261,7 +3266,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3261
3266
|
}
|
|
3262
3267
|
async detectNetwork() {
|
|
3263
3268
|
const chainId = this.client.getChainId();
|
|
3264
|
-
const network$1 = network.findNetworkConfig(
|
|
3269
|
+
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
3265
3270
|
if (!network$1) {
|
|
3266
3271
|
throw new Error(`Unknown network ${chainId}`);
|
|
3267
3272
|
}
|
|
@@ -3524,8 +3529,10 @@ class SequenceClient {
|
|
|
3524
3529
|
this.callbacks = {};
|
|
3525
3530
|
if (isMuxTransportTemplate(transport)) {
|
|
3526
3531
|
this.transport = MuxMessageProvider.new(transport);
|
|
3527
|
-
} else {
|
|
3532
|
+
} else if (isProviderTransport(transport)) {
|
|
3528
3533
|
this.transport = transport;
|
|
3534
|
+
} else {
|
|
3535
|
+
throw new Error('Invalid transport');
|
|
3529
3536
|
}
|
|
3530
3537
|
this.session = new SequenceClientSession(store);
|
|
3531
3538
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
@@ -3602,7 +3609,7 @@ class SequenceClient {
|
|
|
3602
3609
|
// Proxy transport methods
|
|
3603
3610
|
|
|
3604
3611
|
async openWallet(path, intent) {
|
|
3605
|
-
this.transport.openWallet(path, intent,
|
|
3612
|
+
this.transport.openWallet(path, intent, this.getChainId());
|
|
3606
3613
|
await this.transport.waitUntilOpened();
|
|
3607
3614
|
return this.isOpened();
|
|
3608
3615
|
}
|
|
@@ -3644,7 +3651,9 @@ class SequenceClient {
|
|
|
3644
3651
|
}
|
|
3645
3652
|
await this.openWallet(undefined, {
|
|
3646
3653
|
type: 'connect',
|
|
3647
|
-
options
|
|
3654
|
+
options: _extends({}, options, {
|
|
3655
|
+
networkId: this.getChainId()
|
|
3656
|
+
})
|
|
3648
3657
|
});
|
|
3649
3658
|
const connectDetails = await this.transport.waitUntilConnected().catch(error => {
|
|
3650
3659
|
if (error instanceof Error) {
|
|
@@ -3659,6 +3668,12 @@ class SequenceClient {
|
|
|
3659
3668
|
};
|
|
3660
3669
|
}
|
|
3661
3670
|
});
|
|
3671
|
+
|
|
3672
|
+
// Normalize chainId into a decimal string
|
|
3673
|
+
// TODO: Remove this once wallet-webapp returns chainId as a string
|
|
3674
|
+
if (connectDetails.chainId) {
|
|
3675
|
+
connectDetails.chainId = ethers.ethers.BigNumber.from(connectDetails.chainId).toString();
|
|
3676
|
+
}
|
|
3662
3677
|
if (connectDetails.connected) {
|
|
3663
3678
|
if (!connectDetails.session) {
|
|
3664
3679
|
throw new Error('impossible state, connect response is missing session');
|
|
@@ -3774,30 +3789,29 @@ const DefaultProviderConfig = {
|
|
|
3774
3789
|
};
|
|
3775
3790
|
let sequenceWalletProvider;
|
|
3776
3791
|
const initWallet = partialConfig => {
|
|
3777
|
-
var _config$networks, _findNetworkConfig;
|
|
3792
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3778
3793
|
if (sequenceWalletProvider) {
|
|
3779
3794
|
return sequenceWalletProvider;
|
|
3780
3795
|
}
|
|
3781
3796
|
|
|
3782
3797
|
// Combine both the provided config and the default config
|
|
3783
|
-
const config = _extends({}, DefaultProviderConfig, partialConfig
|
|
3798
|
+
const config = _extends({}, DefaultProviderConfig, partialConfig, {
|
|
3799
|
+
transports: _extends({}, DefaultProviderConfig.transports, partialConfig == null ? void 0 : partialConfig.transports)
|
|
3800
|
+
});
|
|
3784
3801
|
const rpcProviders = {};
|
|
3785
3802
|
|
|
3786
|
-
//
|
|
3787
|
-
//
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
})) {
|
|
3792
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3793
|
-
}
|
|
3803
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3804
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3805
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3806
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !network.allNetworks.find(an => an.chainId === n.chainId);
|
|
3807
|
+
})) != null ? _config$networks$filt : [];
|
|
3794
3808
|
|
|
3795
3809
|
// Override any information about the networks using the config
|
|
3796
3810
|
const combinedNetworks = network.allNetworks.map(n => {
|
|
3797
3811
|
var _config$networks2;
|
|
3798
3812
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3799
3813
|
return network ? _extends({}, n, network) : n;
|
|
3800
|
-
});
|
|
3814
|
+
}).concat(newNetworks);
|
|
3801
3815
|
|
|
3802
3816
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3803
3817
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -3881,6 +3895,7 @@ exports.getWallet = getWallet;
|
|
|
3881
3895
|
exports.initWallet = initWallet;
|
|
3882
3896
|
exports.isBrowserExtension = isBrowserExtension;
|
|
3883
3897
|
exports.isMuxTransportTemplate = isMuxTransportTemplate;
|
|
3898
|
+
exports.isProviderTransport = isProviderTransport;
|
|
3884
3899
|
exports.isUnityPlugin = isUnityPlugin;
|
|
3885
3900
|
exports.isValidMessageSignature = isValidMessageSignature;
|
|
3886
3901
|
exports.isValidSignature = isValidSignature;
|
|
@@ -24,6 +24,10 @@ function _extends() {
|
|
|
24
24
|
return _extends.apply(this, arguments);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function isProviderTransport(transport) {
|
|
28
|
+
return transport && typeof transport === 'object' && typeof transport.register === 'function' && typeof transport.unregister === 'function' && typeof transport.openWallet === 'function' && typeof transport.closeWallet === 'function' && typeof transport.isOpened === 'function' && typeof transport.isConnected === 'function' && typeof transport.on === 'function';
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
28
32
|
// argument is for exceptions during the execution, and response is the response payload
|
|
29
33
|
// which may contain the result or an error payload from the wallet.
|
|
@@ -3087,7 +3091,7 @@ class WalletUtils {
|
|
|
3087
3091
|
}
|
|
3088
3092
|
|
|
3089
3093
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3090
|
-
constructor(client, providerFor) {
|
|
3094
|
+
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3091
3095
|
var _this;
|
|
3092
3096
|
// We support a lot of networks
|
|
3093
3097
|
// but we start with the default one
|
|
@@ -3097,6 +3101,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3097
3101
|
this._isSequenceProvider = true;
|
|
3098
3102
|
this.client = client;
|
|
3099
3103
|
this.providerFor = providerFor;
|
|
3104
|
+
this.networks = networks;
|
|
3100
3105
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3101
3106
|
// TODO: Maybe we should emit more events here
|
|
3102
3107
|
_this.emit('chainChanged', chainId);
|
|
@@ -3171,7 +3176,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3171
3176
|
if (chainId === undefined) {
|
|
3172
3177
|
return undefined;
|
|
3173
3178
|
}
|
|
3174
|
-
const resolved = network.findNetworkConfig(
|
|
3179
|
+
const resolved = network.findNetworkConfig(this.networks, chainId);
|
|
3175
3180
|
if (!resolved) {
|
|
3176
3181
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3177
3182
|
}
|
|
@@ -3261,7 +3266,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3261
3266
|
}
|
|
3262
3267
|
async detectNetwork() {
|
|
3263
3268
|
const chainId = this.client.getChainId();
|
|
3264
|
-
const network$1 = network.findNetworkConfig(
|
|
3269
|
+
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
3265
3270
|
if (!network$1) {
|
|
3266
3271
|
throw new Error(`Unknown network ${chainId}`);
|
|
3267
3272
|
}
|
|
@@ -3524,8 +3529,10 @@ class SequenceClient {
|
|
|
3524
3529
|
this.callbacks = {};
|
|
3525
3530
|
if (isMuxTransportTemplate(transport)) {
|
|
3526
3531
|
this.transport = MuxMessageProvider.new(transport);
|
|
3527
|
-
} else {
|
|
3532
|
+
} else if (isProviderTransport(transport)) {
|
|
3528
3533
|
this.transport = transport;
|
|
3534
|
+
} else {
|
|
3535
|
+
throw new Error('Invalid transport');
|
|
3529
3536
|
}
|
|
3530
3537
|
this.session = new SequenceClientSession(store);
|
|
3531
3538
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
@@ -3602,7 +3609,7 @@ class SequenceClient {
|
|
|
3602
3609
|
// Proxy transport methods
|
|
3603
3610
|
|
|
3604
3611
|
async openWallet(path, intent) {
|
|
3605
|
-
this.transport.openWallet(path, intent,
|
|
3612
|
+
this.transport.openWallet(path, intent, this.getChainId());
|
|
3606
3613
|
await this.transport.waitUntilOpened();
|
|
3607
3614
|
return this.isOpened();
|
|
3608
3615
|
}
|
|
@@ -3644,7 +3651,9 @@ class SequenceClient {
|
|
|
3644
3651
|
}
|
|
3645
3652
|
await this.openWallet(undefined, {
|
|
3646
3653
|
type: 'connect',
|
|
3647
|
-
options
|
|
3654
|
+
options: _extends({}, options, {
|
|
3655
|
+
networkId: this.getChainId()
|
|
3656
|
+
})
|
|
3648
3657
|
});
|
|
3649
3658
|
const connectDetails = await this.transport.waitUntilConnected().catch(error => {
|
|
3650
3659
|
if (error instanceof Error) {
|
|
@@ -3659,6 +3668,12 @@ class SequenceClient {
|
|
|
3659
3668
|
};
|
|
3660
3669
|
}
|
|
3661
3670
|
});
|
|
3671
|
+
|
|
3672
|
+
// Normalize chainId into a decimal string
|
|
3673
|
+
// TODO: Remove this once wallet-webapp returns chainId as a string
|
|
3674
|
+
if (connectDetails.chainId) {
|
|
3675
|
+
connectDetails.chainId = ethers.ethers.BigNumber.from(connectDetails.chainId).toString();
|
|
3676
|
+
}
|
|
3662
3677
|
if (connectDetails.connected) {
|
|
3663
3678
|
if (!connectDetails.session) {
|
|
3664
3679
|
throw new Error('impossible state, connect response is missing session');
|
|
@@ -3774,30 +3789,29 @@ const DefaultProviderConfig = {
|
|
|
3774
3789
|
};
|
|
3775
3790
|
let sequenceWalletProvider;
|
|
3776
3791
|
const initWallet = partialConfig => {
|
|
3777
|
-
var _config$networks, _findNetworkConfig;
|
|
3792
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3778
3793
|
if (sequenceWalletProvider) {
|
|
3779
3794
|
return sequenceWalletProvider;
|
|
3780
3795
|
}
|
|
3781
3796
|
|
|
3782
3797
|
// Combine both the provided config and the default config
|
|
3783
|
-
const config = _extends({}, DefaultProviderConfig, partialConfig
|
|
3798
|
+
const config = _extends({}, DefaultProviderConfig, partialConfig, {
|
|
3799
|
+
transports: _extends({}, DefaultProviderConfig.transports, partialConfig == null ? void 0 : partialConfig.transports)
|
|
3800
|
+
});
|
|
3784
3801
|
const rpcProviders = {};
|
|
3785
3802
|
|
|
3786
|
-
//
|
|
3787
|
-
//
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
})) {
|
|
3792
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3793
|
-
}
|
|
3803
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3804
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3805
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3806
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !network.allNetworks.find(an => an.chainId === n.chainId);
|
|
3807
|
+
})) != null ? _config$networks$filt : [];
|
|
3794
3808
|
|
|
3795
3809
|
// Override any information about the networks using the config
|
|
3796
3810
|
const combinedNetworks = network.allNetworks.map(n => {
|
|
3797
3811
|
var _config$networks2;
|
|
3798
3812
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3799
3813
|
return network ? _extends({}, n, network) : n;
|
|
3800
|
-
});
|
|
3814
|
+
}).concat(newNetworks);
|
|
3801
3815
|
|
|
3802
3816
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3803
3817
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -3881,6 +3895,7 @@ exports.getWallet = getWallet;
|
|
|
3881
3895
|
exports.initWallet = initWallet;
|
|
3882
3896
|
exports.isBrowserExtension = isBrowserExtension;
|
|
3883
3897
|
exports.isMuxTransportTemplate = isMuxTransportTemplate;
|
|
3898
|
+
exports.isProviderTransport = isProviderTransport;
|
|
3884
3899
|
exports.isUnityPlugin = isUnityPlugin;
|
|
3885
3900
|
exports.isValidMessageSignature = isValidMessageSignature;
|
|
3886
3901
|
exports.isValidSignature = isValidSignature;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
2
|
import { logger, encodeMessageDigest, encodeTypedDataDigest, sanitizeNumberString, sanitizeHost, sanitizeAlphanumeric, base64EncodeObject, base64DecodeObject } from '@0xsequence/utils';
|
|
3
3
|
import { ethers, BigNumber } from 'ethers';
|
|
4
|
-
import { findSupportedNetwork,
|
|
4
|
+
import { findSupportedNetwork, allNetworks, findNetworkConfig, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, CachedProvider, JsonRpcSender } from '@0xsequence/network';
|
|
5
5
|
import { commons } from '@0xsequence/core';
|
|
6
6
|
import { signAuthorization } from '@0xsequence/auth';
|
|
7
7
|
|
|
@@ -20,6 +20,10 @@ function _extends() {
|
|
|
20
20
|
return _extends.apply(this, arguments);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function isProviderTransport(transport) {
|
|
24
|
+
return transport && typeof transport === 'object' && typeof transport.register === 'function' && typeof transport.unregister === 'function' && typeof transport.openWallet === 'function' && typeof transport.closeWallet === 'function' && typeof transport.isOpened === 'function' && typeof transport.isConnected === 'function' && typeof transport.on === 'function';
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
// ProviderMessageCallback is used to respond to ProviderMessage requests. The error
|
|
24
28
|
// argument is for exceptions during the execution, and response is the response payload
|
|
25
29
|
// which may contain the result or an error payload from the wallet.
|
|
@@ -3083,7 +3087,7 @@ class WalletUtils {
|
|
|
3083
3087
|
}
|
|
3084
3088
|
|
|
3085
3089
|
class SequenceProvider extends ethers.providers.BaseProvider {
|
|
3086
|
-
constructor(client, providerFor) {
|
|
3090
|
+
constructor(client, providerFor, networks = allNetworks) {
|
|
3087
3091
|
var _this;
|
|
3088
3092
|
// We support a lot of networks
|
|
3089
3093
|
// but we start with the default one
|
|
@@ -3093,6 +3097,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3093
3097
|
this._isSequenceProvider = true;
|
|
3094
3098
|
this.client = client;
|
|
3095
3099
|
this.providerFor = providerFor;
|
|
3100
|
+
this.networks = networks;
|
|
3096
3101
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3097
3102
|
// TODO: Maybe we should emit more events here
|
|
3098
3103
|
_this.emit('chainChanged', chainId);
|
|
@@ -3167,7 +3172,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3167
3172
|
if (chainId === undefined) {
|
|
3168
3173
|
return undefined;
|
|
3169
3174
|
}
|
|
3170
|
-
const resolved = findNetworkConfig(
|
|
3175
|
+
const resolved = findNetworkConfig(this.networks, chainId);
|
|
3171
3176
|
if (!resolved) {
|
|
3172
3177
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3173
3178
|
}
|
|
@@ -3257,7 +3262,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3257
3262
|
}
|
|
3258
3263
|
async detectNetwork() {
|
|
3259
3264
|
const chainId = this.client.getChainId();
|
|
3260
|
-
const network = findNetworkConfig(
|
|
3265
|
+
const network = findNetworkConfig(this.networks, chainId);
|
|
3261
3266
|
if (!network) {
|
|
3262
3267
|
throw new Error(`Unknown network ${chainId}`);
|
|
3263
3268
|
}
|
|
@@ -3520,8 +3525,10 @@ class SequenceClient {
|
|
|
3520
3525
|
this.callbacks = {};
|
|
3521
3526
|
if (isMuxTransportTemplate(transport)) {
|
|
3522
3527
|
this.transport = MuxMessageProvider.new(transport);
|
|
3523
|
-
} else {
|
|
3528
|
+
} else if (isProviderTransport(transport)) {
|
|
3524
3529
|
this.transport = transport;
|
|
3530
|
+
} else {
|
|
3531
|
+
throw new Error('Invalid transport');
|
|
3525
3532
|
}
|
|
3526
3533
|
this.session = new SequenceClientSession(store);
|
|
3527
3534
|
this.defaultChainId = new DefaultChainIdTracker(store, defaultChainId);
|
|
@@ -3598,7 +3605,7 @@ class SequenceClient {
|
|
|
3598
3605
|
// Proxy transport methods
|
|
3599
3606
|
|
|
3600
3607
|
async openWallet(path, intent) {
|
|
3601
|
-
this.transport.openWallet(path, intent,
|
|
3608
|
+
this.transport.openWallet(path, intent, this.getChainId());
|
|
3602
3609
|
await this.transport.waitUntilOpened();
|
|
3603
3610
|
return this.isOpened();
|
|
3604
3611
|
}
|
|
@@ -3640,7 +3647,9 @@ class SequenceClient {
|
|
|
3640
3647
|
}
|
|
3641
3648
|
await this.openWallet(undefined, {
|
|
3642
3649
|
type: 'connect',
|
|
3643
|
-
options
|
|
3650
|
+
options: _extends({}, options, {
|
|
3651
|
+
networkId: this.getChainId()
|
|
3652
|
+
})
|
|
3644
3653
|
});
|
|
3645
3654
|
const connectDetails = await this.transport.waitUntilConnected().catch(error => {
|
|
3646
3655
|
if (error instanceof Error) {
|
|
@@ -3655,6 +3664,12 @@ class SequenceClient {
|
|
|
3655
3664
|
};
|
|
3656
3665
|
}
|
|
3657
3666
|
});
|
|
3667
|
+
|
|
3668
|
+
// Normalize chainId into a decimal string
|
|
3669
|
+
// TODO: Remove this once wallet-webapp returns chainId as a string
|
|
3670
|
+
if (connectDetails.chainId) {
|
|
3671
|
+
connectDetails.chainId = ethers.BigNumber.from(connectDetails.chainId).toString();
|
|
3672
|
+
}
|
|
3658
3673
|
if (connectDetails.connected) {
|
|
3659
3674
|
if (!connectDetails.session) {
|
|
3660
3675
|
throw new Error('impossible state, connect response is missing session');
|
|
@@ -3770,30 +3785,29 @@ const DefaultProviderConfig = {
|
|
|
3770
3785
|
};
|
|
3771
3786
|
let sequenceWalletProvider;
|
|
3772
3787
|
const initWallet = partialConfig => {
|
|
3773
|
-
var _config$networks, _findNetworkConfig;
|
|
3788
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3774
3789
|
if (sequenceWalletProvider) {
|
|
3775
3790
|
return sequenceWalletProvider;
|
|
3776
3791
|
}
|
|
3777
3792
|
|
|
3778
3793
|
// Combine both the provided config and the default config
|
|
3779
|
-
const config = _extends({}, DefaultProviderConfig, partialConfig
|
|
3794
|
+
const config = _extends({}, DefaultProviderConfig, partialConfig, {
|
|
3795
|
+
transports: _extends({}, DefaultProviderConfig.transports, partialConfig == null ? void 0 : partialConfig.transports)
|
|
3796
|
+
});
|
|
3780
3797
|
const rpcProviders = {};
|
|
3781
3798
|
|
|
3782
|
-
//
|
|
3783
|
-
//
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
})) {
|
|
3788
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3789
|
-
}
|
|
3799
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3800
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3801
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3802
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !allNetworks.find(an => an.chainId === n.chainId);
|
|
3803
|
+
})) != null ? _config$networks$filt : [];
|
|
3790
3804
|
|
|
3791
3805
|
// Override any information about the networks using the config
|
|
3792
3806
|
const combinedNetworks = allNetworks.map(n => {
|
|
3793
3807
|
var _config$networks2;
|
|
3794
3808
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3795
3809
|
return network ? _extends({}, n, network) : n;
|
|
3796
|
-
});
|
|
3810
|
+
}).concat(newNetworks);
|
|
3797
3811
|
|
|
3798
3812
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3799
3813
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -3840,4 +3854,4 @@ const getWallet = () => {
|
|
|
3840
3854
|
return sequenceWalletProvider;
|
|
3841
3855
|
};
|
|
3842
3856
|
|
|
3843
|
-
export { BaseInjectedTransport, BaseProviderTransport, BaseWalletTransport, CHANNEL_ID, DefaultChainIdTracker, DefaultProviderConfig, ErrSignedInRequired, EventType, ExtensionMessageHandler, ExtensionMessageProvider, InitState, LocalStorage, MemoryItemStore, MuxMessageProvider, OpenState, PROVIDER_OPEN_TIMEOUT, ProviderError, ProxyMessageChannel, ProxyMessageChannelPort, ProxyMessageHandler, ProxyMessageProvider, SequenceClient, SequenceClientSession, SequenceProvider, SequenceSigner, SingleNetworkSequenceProvider, SingleNetworkSequenceSigner, UnrealMessageHandler, UnrealMessageProvider, WalletRequestHandler, WindowMessageHandler, WindowMessageProvider, WindowSessionParams, getWallet, initWallet, isBrowserExtension, isMuxTransportTemplate, isUnityPlugin, isValidMessageSignature, isValidSignature, isValidTypedDataSignature, isWalletUpToDate, messageToBytes, nextMessageIdx, prefixEIP191Message, resolveArrayProperties, trimEIP191Prefix, unregisterWallet, useBestStore };
|
|
3857
|
+
export { BaseInjectedTransport, BaseProviderTransport, BaseWalletTransport, CHANNEL_ID, DefaultChainIdTracker, DefaultProviderConfig, ErrSignedInRequired, EventType, ExtensionMessageHandler, ExtensionMessageProvider, InitState, LocalStorage, MemoryItemStore, MuxMessageProvider, OpenState, PROVIDER_OPEN_TIMEOUT, ProviderError, ProxyMessageChannel, ProxyMessageChannelPort, ProxyMessageHandler, ProxyMessageProvider, SequenceClient, SequenceClientSession, SequenceProvider, SequenceSigner, SingleNetworkSequenceProvider, SingleNetworkSequenceSigner, UnrealMessageHandler, UnrealMessageProvider, WalletRequestHandler, WindowMessageHandler, WindowMessageProvider, WindowSessionParams, getWallet, initWallet, isBrowserExtension, isMuxTransportTemplate, isProviderTransport, isUnityPlugin, isValidMessageSignature, isValidSignature, isValidTypedDataSignature, isWalletUpToDate, messageToBytes, nextMessageIdx, prefixEIP191Message, resolveArrayProperties, trimEIP191Prefix, unregisterWallet, useBestStore };
|
|
@@ -32,11 +32,12 @@ export interface ISequenceProvider {
|
|
|
32
32
|
export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider {
|
|
33
33
|
readonly client: SequenceClient;
|
|
34
34
|
private readonly providerFor;
|
|
35
|
+
readonly networks: NetworkConfig[];
|
|
35
36
|
private readonly singleNetworkProviders;
|
|
36
37
|
readonly _isSequenceProvider = true;
|
|
37
38
|
readonly utils: WalletUtils;
|
|
38
39
|
readonly signer: SequenceSigner;
|
|
39
|
-
constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.providers.JsonRpcProvider);
|
|
40
|
+
constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.providers.JsonRpcProvider, networks?: NetworkConfig[]);
|
|
40
41
|
getSigner(): SequenceSigner;
|
|
41
42
|
getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
|
|
42
43
|
getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
|
|
@@ -15,6 +15,7 @@ export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransp
|
|
|
15
15
|
waitUntilOpened(): Promise<WalletSession | undefined>;
|
|
16
16
|
waitUntilConnected(): Promise<ConnectDetails>;
|
|
17
17
|
}
|
|
18
|
+
export declare function isProviderTransport(transport: any): transport is ProviderTransport;
|
|
18
19
|
export interface WalletTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
19
20
|
register(): void;
|
|
20
21
|
unregister(): void;
|
|
@@ -126,6 +127,12 @@ export interface ConnectOptions {
|
|
|
126
127
|
/** Options to further customize the wallet experience. */
|
|
127
128
|
settings?: Settings;
|
|
128
129
|
}
|
|
130
|
+
export interface NetworkedConnectOptions extends ConnectOptions {
|
|
131
|
+
/** chainId is the chainId to connect to. If not specified, the default chainId
|
|
132
|
+
* will be used. This does not define a default chain id, it is only used for the connect
|
|
133
|
+
* authorization signature. */
|
|
134
|
+
networkId?: string | number;
|
|
135
|
+
}
|
|
129
136
|
/** Options to further customize the wallet experience. */
|
|
130
137
|
export interface Settings {
|
|
131
138
|
/** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
|
|
@@ -189,7 +196,7 @@ export interface ConnectDetails {
|
|
|
189
196
|
export type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'error' | 'connected' | 'proof' | 'email'>;
|
|
190
197
|
export type OpenWalletIntent = {
|
|
191
198
|
type: 'connect';
|
|
192
|
-
options?:
|
|
199
|
+
options?: NetworkedConnectOptions;
|
|
193
200
|
} | {
|
|
194
201
|
type: 'openWithOptions';
|
|
195
202
|
options?: ConnectOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20230726163002",
|
|
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",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"eventemitter2": "^6.4.5",
|
|
13
13
|
"webextension-polyfill": "^0.10.0",
|
|
14
|
-
"@0xsequence/abi": "0.0.0-
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/
|
|
20
|
-
"@0xsequence/
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/abi": "0.0.0-20230726163002",
|
|
15
|
+
"@0xsequence/account": "0.0.0-20230726163002",
|
|
16
|
+
"@0xsequence/migration": "0.0.0-20230726163002",
|
|
17
|
+
"@0xsequence/core": "0.0.0-20230726163002",
|
|
18
|
+
"@0xsequence/network": "0.0.0-20230726163002",
|
|
19
|
+
"@0xsequence/wallet": "0.0.0-20230726163002",
|
|
20
|
+
"@0xsequence/auth": "0.0.0-20230726163002",
|
|
21
|
+
"@0xsequence/relayer": "0.0.0-20230726163002",
|
|
22
|
+
"@0xsequence/utils": "0.0.0-20230726163002"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonRpcRequest, JsonRpcResponse, NetworkConfig } from "@0xsequence/network"
|
|
2
|
-
import { ConnectDetails, ConnectOptions, ItemStore, MuxMessageProvider, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletSession, isMuxTransportTemplate } from "."
|
|
2
|
+
import { ConnectDetails, ConnectOptions, ItemStore, MuxMessageProvider, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletSession, isMuxTransportTemplate, isProviderTransport } from "."
|
|
3
3
|
import { commons } from "@0xsequence/core"
|
|
4
4
|
import { TypedData } from "@0xsequence/utils"
|
|
5
5
|
import { toExtended } from "./extended"
|
|
@@ -134,8 +134,10 @@ export class SequenceClient {
|
|
|
134
134
|
) {
|
|
135
135
|
if (isMuxTransportTemplate(transport)) {
|
|
136
136
|
this.transport = MuxMessageProvider.new(transport)
|
|
137
|
-
} else {
|
|
137
|
+
} else if (isProviderTransport(transport)) {
|
|
138
138
|
this.transport = transport
|
|
139
|
+
} else {
|
|
140
|
+
throw new Error('Invalid transport')
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
this.session = new SequenceClientSession(store)
|
|
@@ -222,7 +224,7 @@ export class SequenceClient {
|
|
|
222
224
|
// Proxy transport methods
|
|
223
225
|
|
|
224
226
|
async openWallet(path?: string, intent?: OpenWalletIntent) {
|
|
225
|
-
this.transport.openWallet(path, intent,
|
|
227
|
+
this.transport.openWallet(path, intent, this.getChainId())
|
|
226
228
|
await this.transport.waitUntilOpened()
|
|
227
229
|
return this.isOpened()
|
|
228
230
|
}
|
|
@@ -271,7 +273,7 @@ export class SequenceClient {
|
|
|
271
273
|
}
|
|
272
274
|
}
|
|
273
275
|
|
|
274
|
-
await this.openWallet(undefined, { type: 'connect', options })
|
|
276
|
+
await this.openWallet(undefined, { type: 'connect', options: { ...options, networkId: this.getChainId() } })
|
|
275
277
|
|
|
276
278
|
const connectDetails = await this.transport.waitUntilConnected().catch((error): ConnectDetails => {
|
|
277
279
|
if (error instanceof Error) {
|
|
@@ -281,6 +283,12 @@ export class SequenceClient {
|
|
|
281
283
|
}
|
|
282
284
|
})
|
|
283
285
|
|
|
286
|
+
// Normalize chainId into a decimal string
|
|
287
|
+
// TODO: Remove this once wallet-webapp returns chainId as a string
|
|
288
|
+
if (connectDetails.chainId) {
|
|
289
|
+
connectDetails.chainId = ethers.BigNumber.from(connectDetails.chainId).toString()
|
|
290
|
+
}
|
|
291
|
+
|
|
284
292
|
if (connectDetails.connected) {
|
|
285
293
|
if (!connectDetails.session) {
|
|
286
294
|
throw new Error('impossible state, connect response is missing session')
|
package/src/init.ts
CHANGED
|
@@ -50,23 +50,30 @@ export const initWallet = (
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Combine both the provided config and the default config
|
|
53
|
-
const config = {
|
|
53
|
+
const config = {
|
|
54
|
+
...DefaultProviderConfig,
|
|
55
|
+
...partialConfig,
|
|
56
|
+
transports: {
|
|
57
|
+
...DefaultProviderConfig.transports,
|
|
58
|
+
...partialConfig?.transports,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
const rpcProviders: Record<number, ethers.providers.JsonRpcProvider> = {}
|
|
55
63
|
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
65
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
66
|
+
const newNetworks = (config.networks?.filter((n) => {
|
|
67
|
+
n.rpcUrl !== undefined &&
|
|
68
|
+
n.chainId !== undefined &&
|
|
69
|
+
!allNetworks.find((an) => an.chainId === n.chainId)
|
|
70
|
+
}) ?? []) as NetworkConfig[]
|
|
64
71
|
|
|
65
72
|
// Override any information about the networks using the config
|
|
66
73
|
const combinedNetworks = allNetworks.map((n) => {
|
|
67
74
|
const network = config.networks?.find((cn) => cn.chainId === n.chainId)
|
|
68
75
|
return network ? { ...n, ...network } : n
|
|
69
|
-
})
|
|
76
|
+
}).concat(newNetworks)
|
|
70
77
|
|
|
71
78
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
72
79
|
// generate a bunch of providers for networks that aren't used.
|
package/src/provider.ts
CHANGED
|
@@ -57,7 +57,8 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
57
57
|
|
|
58
58
|
constructor (
|
|
59
59
|
public readonly client: SequenceClient,
|
|
60
|
-
private readonly providerFor: (networkId: number) => ethers.providers.JsonRpcProvider
|
|
60
|
+
private readonly providerFor: (networkId: number) => ethers.providers.JsonRpcProvider,
|
|
61
|
+
public readonly networks: NetworkConfig[] = allNetworks
|
|
61
62
|
) {
|
|
62
63
|
// We support a lot of networks
|
|
63
64
|
// but we start with the default one
|
|
@@ -158,7 +159,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
158
159
|
return undefined
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
const resolved = findNetworkConfig(
|
|
162
|
+
const resolved = findNetworkConfig(this.networks, chainId as ChainIdLike)
|
|
162
163
|
|
|
163
164
|
if (!resolved) {
|
|
164
165
|
throw new Error(`Unsupported network ${chainId}`)
|
|
@@ -270,7 +271,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
270
271
|
|
|
271
272
|
async detectNetwork(): Promise<ethers.providers.Network> {
|
|
272
273
|
const chainId = this.client.getChainId()
|
|
273
|
-
const network = findNetworkConfig(
|
|
274
|
+
const network = findNetworkConfig(this.networks, chainId)
|
|
274
275
|
|
|
275
276
|
if (!network) {
|
|
276
277
|
throw new Error(`Unknown network ${chainId}`)
|
package/src/types.ts
CHANGED
|
@@ -21,6 +21,20 @@ export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransp
|
|
|
21
21
|
waitUntilConnected(): Promise<ConnectDetails>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export function isProviderTransport(transport: any): transport is ProviderTransport {
|
|
25
|
+
return (
|
|
26
|
+
transport &&
|
|
27
|
+
typeof transport === 'object' &&
|
|
28
|
+
typeof transport.register === 'function' &&
|
|
29
|
+
typeof transport.unregister === 'function' &&
|
|
30
|
+
typeof transport.openWallet === 'function' &&
|
|
31
|
+
typeof transport.closeWallet === 'function' &&
|
|
32
|
+
typeof transport.isOpened === 'function' &&
|
|
33
|
+
typeof transport.isConnected === 'function' &&
|
|
34
|
+
typeof transport.on === 'function'
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
24
38
|
export interface WalletTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
25
39
|
register(): void
|
|
26
40
|
unregister(): void
|
|
@@ -167,6 +181,13 @@ export interface ConnectOptions {
|
|
|
167
181
|
settings?: Settings
|
|
168
182
|
}
|
|
169
183
|
|
|
184
|
+
export interface NetworkedConnectOptions extends ConnectOptions {
|
|
185
|
+
/** chainId is the chainId to connect to. If not specified, the default chainId
|
|
186
|
+
* will be used. This does not define a default chain id, it is only used for the connect
|
|
187
|
+
* authorization signature. */
|
|
188
|
+
networkId?: string | number;
|
|
189
|
+
}
|
|
190
|
+
|
|
170
191
|
/** Options to further customize the wallet experience. */
|
|
171
192
|
export interface Settings {
|
|
172
193
|
/** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
|
|
@@ -252,7 +273,7 @@ export interface ConnectDetails {
|
|
|
252
273
|
export type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'error' | 'connected' | 'proof' | 'email'>
|
|
253
274
|
|
|
254
275
|
export type OpenWalletIntent =
|
|
255
|
-
| { type: 'connect'; options?:
|
|
276
|
+
| { type: 'connect'; options?: NetworkedConnectOptions }
|
|
256
277
|
| { type: 'openWithOptions'; options?: ConnectOptions }
|
|
257
278
|
| { type: 'jsonRpcRequest'; method: string }
|
|
258
279
|
|