@0xsequence/provider 0.0.0-20230726160744 → 0.0.0-20230726172246
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 +16 -13
- package/dist/0xsequence-provider.cjs.prod.js +16 -13
- package/dist/0xsequence-provider.esm.js +17 -14
- package/dist/declarations/src/provider.d.ts +8 -3
- package/dist/declarations/src/types.d.ts +6 -0
- package/package.json +10 -10
- package/src/init.ts +8 -9
- package/src/provider.ts +10 -5
- package/src/types.ts +5 -0
|
@@ -79,6 +79,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
79
79
|
|
|
80
80
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
81
81
|
|
|
82
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
83
|
+
|
|
82
84
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
83
85
|
|
|
84
86
|
let _messageIdx = 0;
|
|
@@ -3091,7 +3093,7 @@ class WalletUtils {
|
|
|
3091
3093
|
}
|
|
3092
3094
|
|
|
3093
3095
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3094
|
-
constructor(client, providerFor) {
|
|
3096
|
+
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3095
3097
|
var _this;
|
|
3096
3098
|
// We support a lot of networks
|
|
3097
3099
|
// but we start with the default one
|
|
@@ -3101,6 +3103,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3101
3103
|
this._isSequenceProvider = true;
|
|
3102
3104
|
this.client = client;
|
|
3103
3105
|
this.providerFor = providerFor;
|
|
3106
|
+
this.networks = networks;
|
|
3104
3107
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3105
3108
|
// TODO: Maybe we should emit more events here
|
|
3106
3109
|
_this.emit('chainChanged', chainId);
|
|
@@ -3175,7 +3178,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3175
3178
|
if (chainId === undefined) {
|
|
3176
3179
|
return undefined;
|
|
3177
3180
|
}
|
|
3178
|
-
const resolved = network.findNetworkConfig(
|
|
3181
|
+
const resolved = network.findNetworkConfig(this.networks, chainId);
|
|
3179
3182
|
if (!resolved) {
|
|
3180
3183
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3181
3184
|
}
|
|
@@ -3263,9 +3266,12 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3263
3266
|
send(method, params) {
|
|
3264
3267
|
return this.perform(method, params);
|
|
3265
3268
|
}
|
|
3269
|
+
request(request) {
|
|
3270
|
+
return this.perform(request.method, request.params);
|
|
3271
|
+
}
|
|
3266
3272
|
async detectNetwork() {
|
|
3267
3273
|
const chainId = this.client.getChainId();
|
|
3268
|
-
const network$1 = network.findNetworkConfig(
|
|
3274
|
+
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
3269
3275
|
if (!network$1) {
|
|
3270
3276
|
throw new Error(`Unknown network ${chainId}`);
|
|
3271
3277
|
}
|
|
@@ -3788,7 +3794,7 @@ const DefaultProviderConfig = {
|
|
|
3788
3794
|
};
|
|
3789
3795
|
let sequenceWalletProvider;
|
|
3790
3796
|
const initWallet = partialConfig => {
|
|
3791
|
-
var _config$networks, _findNetworkConfig;
|
|
3797
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3792
3798
|
if (sequenceWalletProvider) {
|
|
3793
3799
|
return sequenceWalletProvider;
|
|
3794
3800
|
}
|
|
@@ -3799,21 +3805,18 @@ const initWallet = partialConfig => {
|
|
|
3799
3805
|
});
|
|
3800
3806
|
const rpcProviders = {};
|
|
3801
3807
|
|
|
3802
|
-
//
|
|
3803
|
-
//
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
})) {
|
|
3808
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3809
|
-
}
|
|
3808
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3809
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3810
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3811
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !network.allNetworks.find(an => an.chainId === n.chainId);
|
|
3812
|
+
})) != null ? _config$networks$filt : [];
|
|
3810
3813
|
|
|
3811
3814
|
// Override any information about the networks using the config
|
|
3812
3815
|
const combinedNetworks = network.allNetworks.map(n => {
|
|
3813
3816
|
var _config$networks2;
|
|
3814
3817
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3815
3818
|
return network ? _extends({}, n, network) : n;
|
|
3816
|
-
});
|
|
3819
|
+
}).concat(newNetworks);
|
|
3817
3820
|
|
|
3818
3821
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3819
3822
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -79,6 +79,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
79
79
|
|
|
80
80
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
81
81
|
|
|
82
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
83
|
+
|
|
82
84
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
83
85
|
|
|
84
86
|
let _messageIdx = 0;
|
|
@@ -3091,7 +3093,7 @@ class WalletUtils {
|
|
|
3091
3093
|
}
|
|
3092
3094
|
|
|
3093
3095
|
class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
3094
|
-
constructor(client, providerFor) {
|
|
3096
|
+
constructor(client, providerFor, networks = network.allNetworks) {
|
|
3095
3097
|
var _this;
|
|
3096
3098
|
// We support a lot of networks
|
|
3097
3099
|
// but we start with the default one
|
|
@@ -3101,6 +3103,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3101
3103
|
this._isSequenceProvider = true;
|
|
3102
3104
|
this.client = client;
|
|
3103
3105
|
this.providerFor = providerFor;
|
|
3106
|
+
this.networks = networks;
|
|
3104
3107
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3105
3108
|
// TODO: Maybe we should emit more events here
|
|
3106
3109
|
_this.emit('chainChanged', chainId);
|
|
@@ -3175,7 +3178,7 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3175
3178
|
if (chainId === undefined) {
|
|
3176
3179
|
return undefined;
|
|
3177
3180
|
}
|
|
3178
|
-
const resolved = network.findNetworkConfig(
|
|
3181
|
+
const resolved = network.findNetworkConfig(this.networks, chainId);
|
|
3179
3182
|
if (!resolved) {
|
|
3180
3183
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3181
3184
|
}
|
|
@@ -3263,9 +3266,12 @@ class SequenceProvider extends ethers.ethers.providers.BaseProvider {
|
|
|
3263
3266
|
send(method, params) {
|
|
3264
3267
|
return this.perform(method, params);
|
|
3265
3268
|
}
|
|
3269
|
+
request(request) {
|
|
3270
|
+
return this.perform(request.method, request.params);
|
|
3271
|
+
}
|
|
3266
3272
|
async detectNetwork() {
|
|
3267
3273
|
const chainId = this.client.getChainId();
|
|
3268
|
-
const network$1 = network.findNetworkConfig(
|
|
3274
|
+
const network$1 = network.findNetworkConfig(this.networks, chainId);
|
|
3269
3275
|
if (!network$1) {
|
|
3270
3276
|
throw new Error(`Unknown network ${chainId}`);
|
|
3271
3277
|
}
|
|
@@ -3788,7 +3794,7 @@ const DefaultProviderConfig = {
|
|
|
3788
3794
|
};
|
|
3789
3795
|
let sequenceWalletProvider;
|
|
3790
3796
|
const initWallet = partialConfig => {
|
|
3791
|
-
var _config$networks, _findNetworkConfig;
|
|
3797
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3792
3798
|
if (sequenceWalletProvider) {
|
|
3793
3799
|
return sequenceWalletProvider;
|
|
3794
3800
|
}
|
|
@@ -3799,21 +3805,18 @@ const initWallet = partialConfig => {
|
|
|
3799
3805
|
});
|
|
3800
3806
|
const rpcProviders = {};
|
|
3801
3807
|
|
|
3802
|
-
//
|
|
3803
|
-
//
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
})) {
|
|
3808
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3809
|
-
}
|
|
3808
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3809
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3810
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3811
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !network.allNetworks.find(an => an.chainId === n.chainId);
|
|
3812
|
+
})) != null ? _config$networks$filt : [];
|
|
3810
3813
|
|
|
3811
3814
|
// Override any information about the networks using the config
|
|
3812
3815
|
const combinedNetworks = network.allNetworks.map(n => {
|
|
3813
3816
|
var _config$networks2;
|
|
3814
3817
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3815
3818
|
return network ? _extends({}, n, network) : n;
|
|
3816
|
-
});
|
|
3819
|
+
}).concat(newNetworks);
|
|
3817
3820
|
|
|
3818
3821
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3819
3822
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -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
|
|
|
@@ -75,6 +75,8 @@ const ErrSignedInRequired = new ProviderError('Wallet is not signed in. Connect
|
|
|
75
75
|
|
|
76
76
|
// TODO: lets build some nice error handling tools, prob in /utils ...
|
|
77
77
|
|
|
78
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
79
|
+
|
|
78
80
|
const PROVIDER_OPEN_TIMEOUT = 30000; // in ms
|
|
79
81
|
|
|
80
82
|
let _messageIdx = 0;
|
|
@@ -3087,7 +3089,7 @@ class WalletUtils {
|
|
|
3087
3089
|
}
|
|
3088
3090
|
|
|
3089
3091
|
class SequenceProvider extends ethers.providers.BaseProvider {
|
|
3090
|
-
constructor(client, providerFor) {
|
|
3092
|
+
constructor(client, providerFor, networks = allNetworks) {
|
|
3091
3093
|
var _this;
|
|
3092
3094
|
// We support a lot of networks
|
|
3093
3095
|
// but we start with the default one
|
|
@@ -3097,6 +3099,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3097
3099
|
this._isSequenceProvider = true;
|
|
3098
3100
|
this.client = client;
|
|
3099
3101
|
this.providerFor = providerFor;
|
|
3102
|
+
this.networks = networks;
|
|
3100
3103
|
client.onDefaultChainIdChanged(async function (chainId) {
|
|
3101
3104
|
// TODO: Maybe we should emit more events here
|
|
3102
3105
|
_this.emit('chainChanged', chainId);
|
|
@@ -3171,7 +3174,7 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3171
3174
|
if (chainId === undefined) {
|
|
3172
3175
|
return undefined;
|
|
3173
3176
|
}
|
|
3174
|
-
const resolved = findNetworkConfig(
|
|
3177
|
+
const resolved = findNetworkConfig(this.networks, chainId);
|
|
3175
3178
|
if (!resolved) {
|
|
3176
3179
|
throw new Error(`Unsupported network ${chainId}`);
|
|
3177
3180
|
}
|
|
@@ -3259,9 +3262,12 @@ class SequenceProvider extends ethers.providers.BaseProvider {
|
|
|
3259
3262
|
send(method, params) {
|
|
3260
3263
|
return this.perform(method, params);
|
|
3261
3264
|
}
|
|
3265
|
+
request(request) {
|
|
3266
|
+
return this.perform(request.method, request.params);
|
|
3267
|
+
}
|
|
3262
3268
|
async detectNetwork() {
|
|
3263
3269
|
const chainId = this.client.getChainId();
|
|
3264
|
-
const network = findNetworkConfig(
|
|
3270
|
+
const network = findNetworkConfig(this.networks, chainId);
|
|
3265
3271
|
if (!network) {
|
|
3266
3272
|
throw new Error(`Unknown network ${chainId}`);
|
|
3267
3273
|
}
|
|
@@ -3784,7 +3790,7 @@ const DefaultProviderConfig = {
|
|
|
3784
3790
|
};
|
|
3785
3791
|
let sequenceWalletProvider;
|
|
3786
3792
|
const initWallet = partialConfig => {
|
|
3787
|
-
var _config$networks, _findNetworkConfig;
|
|
3793
|
+
var _config$networks$filt, _config$networks, _findNetworkConfig;
|
|
3788
3794
|
if (sequenceWalletProvider) {
|
|
3789
3795
|
return sequenceWalletProvider;
|
|
3790
3796
|
}
|
|
@@ -3795,21 +3801,18 @@ const initWallet = partialConfig => {
|
|
|
3795
3801
|
});
|
|
3796
3802
|
const rpcProviders = {};
|
|
3797
3803
|
|
|
3798
|
-
//
|
|
3799
|
-
//
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
})) {
|
|
3804
|
-
throw new Error('networks config must only contain networks defined in sequence.js');
|
|
3805
|
-
}
|
|
3804
|
+
// Find any new networks that aren't already defined in sequence.js
|
|
3805
|
+
// and add them to the list of networks, (they must have a rpcUrl and chainId)
|
|
3806
|
+
const newNetworks = (_config$networks$filt = (_config$networks = config.networks) == null ? void 0 : _config$networks.filter(n => {
|
|
3807
|
+
n.rpcUrl !== undefined && n.chainId !== undefined && !allNetworks.find(an => an.chainId === n.chainId);
|
|
3808
|
+
})) != null ? _config$networks$filt : [];
|
|
3806
3809
|
|
|
3807
3810
|
// Override any information about the networks using the config
|
|
3808
3811
|
const combinedNetworks = allNetworks.map(n => {
|
|
3809
3812
|
var _config$networks2;
|
|
3810
3813
|
const network = (_config$networks2 = config.networks) == null ? void 0 : _config$networks2.find(cn => cn.chainId === n.chainId);
|
|
3811
3814
|
return network ? _extends({}, n, network) : n;
|
|
3812
|
-
});
|
|
3815
|
+
}).concat(newNetworks);
|
|
3813
3816
|
|
|
3814
3817
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
3815
3818
|
// generate a bunch of providers for networks that aren't used.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { SequenceClient } from "./client.js";
|
|
3
3
|
import { ChainIdLike, NetworkConfig } from "@0xsequence/network";
|
|
4
|
-
import { ConnectDetails, ConnectOptions, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
|
|
4
|
+
import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
|
|
5
5
|
import { commons } from "@0xsequence/core";
|
|
6
6
|
import { WalletUtils } from "./utils/index.js";
|
|
7
7
|
import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer.js";
|
|
@@ -29,14 +29,15 @@ export interface ISequenceProvider {
|
|
|
29
29
|
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
30
30
|
utils: WalletUtils;
|
|
31
31
|
}
|
|
32
|
-
export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider {
|
|
32
|
+
export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider, EIP1193Provider {
|
|
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;
|
|
@@ -78,6 +79,10 @@ export declare class SequenceProvider extends ethers.providers.BaseProvider impl
|
|
|
78
79
|
_getSubprovider(chainId?: ChainIdLike): Promise<ethers.providers.JsonRpcProvider>;
|
|
79
80
|
perform(method: string, params: any): Promise<any>;
|
|
80
81
|
send(method: string, params: any): Promise<any>;
|
|
82
|
+
request(request: {
|
|
83
|
+
method: string;
|
|
84
|
+
params?: any[] | undefined;
|
|
85
|
+
}): Promise<any>;
|
|
81
86
|
detectNetwork(): Promise<ethers.providers.Network>;
|
|
82
87
|
waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number, optionals?: OptionalChainIdLike): Promise<ethers.providers.TransactionReceipt>;
|
|
83
88
|
getBlockNumber(optionals?: OptionalChainIdLike): Promise<number>;
|
|
@@ -244,4 +244,10 @@ export type OptionalChainId = {
|
|
|
244
244
|
export type OptionalEIP6492 = {
|
|
245
245
|
eip6492?: boolean;
|
|
246
246
|
} | undefined;
|
|
247
|
+
export interface EIP1193Provider {
|
|
248
|
+
request: (request: {
|
|
249
|
+
method: string;
|
|
250
|
+
params?: Array<any>;
|
|
251
|
+
}) => Promise<any>;
|
|
252
|
+
}
|
|
247
253
|
export {};
|
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-20230726172246",
|
|
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/migration": "0.0.0-
|
|
18
|
-
"@0xsequence/account": "0.0.0-
|
|
19
|
-
"@0xsequence/network": "0.0.0-
|
|
20
|
-
"@0xsequence/utils": "0.0.0-
|
|
21
|
-
"@0xsequence/
|
|
22
|
-
"@0xsequence/
|
|
14
|
+
"@0xsequence/abi": "0.0.0-20230726172246",
|
|
15
|
+
"@0xsequence/core": "0.0.0-20230726172246",
|
|
16
|
+
"@0xsequence/auth": "0.0.0-20230726172246",
|
|
17
|
+
"@0xsequence/migration": "0.0.0-20230726172246",
|
|
18
|
+
"@0xsequence/account": "0.0.0-20230726172246",
|
|
19
|
+
"@0xsequence/network": "0.0.0-20230726172246",
|
|
20
|
+
"@0xsequence/utils": "0.0.0-20230726172246",
|
|
21
|
+
"@0xsequence/wallet": "0.0.0-20230726172246",
|
|
22
|
+
"@0xsequence/relayer": "0.0.0-20230726172246"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
package/src/init.ts
CHANGED
|
@@ -61,20 +61,19 @@ export const initWallet = (
|
|
|
61
61
|
|
|
62
62
|
const rpcProviders: Record<number, ethers.providers.JsonRpcProvider> = {}
|
|
63
63
|
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
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[]
|
|
72
71
|
|
|
73
72
|
// Override any information about the networks using the config
|
|
74
73
|
const combinedNetworks = allNetworks.map((n) => {
|
|
75
74
|
const network = config.networks?.find((cn) => cn.chainId === n.chainId)
|
|
76
75
|
return network ? { ...n, ...network } : n
|
|
77
|
-
})
|
|
76
|
+
}).concat(newNetworks)
|
|
78
77
|
|
|
79
78
|
// This build a "public rpc" on demand, we build them on demand because we don't want to
|
|
80
79
|
// generate a bunch of providers for networks that aren't used.
|
package/src/provider.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ethers } from "ethers"
|
|
3
3
|
import { SequenceClient } from "./client"
|
|
4
4
|
import { ChainIdLike, NetworkConfig, allNetworks, findNetworkConfig } from "@0xsequence/network"
|
|
5
|
-
import { ConnectDetails, ConnectOptions, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types"
|
|
5
|
+
import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types"
|
|
6
6
|
import { commons } from "@0xsequence/core"
|
|
7
7
|
import { WalletUtils } from "./utils/index"
|
|
8
8
|
import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer"
|
|
@@ -47,7 +47,7 @@ export interface ISequenceProvider {
|
|
|
47
47
|
utils: WalletUtils
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider {
|
|
50
|
+
export class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider, EIP1193Provider {
|
|
51
51
|
private readonly singleNetworkProviders: { [chainId: number]: SingleNetworkSequenceProvider } = {}
|
|
52
52
|
|
|
53
53
|
readonly _isSequenceProvider = true
|
|
@@ -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}`)
|
|
@@ -268,9 +269,13 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
|
|
|
268
269
|
return this.perform(method, params)
|
|
269
270
|
}
|
|
270
271
|
|
|
272
|
+
request (request: { method: string; params?: any[] | undefined }) {
|
|
273
|
+
return this.perform(request.method, request.params)
|
|
274
|
+
}
|
|
275
|
+
|
|
271
276
|
async detectNetwork(): Promise<ethers.providers.Network> {
|
|
272
277
|
const chainId = this.client.getChainId()
|
|
273
|
-
const network = findNetworkConfig(
|
|
278
|
+
const network = findNetworkConfig(this.networks, chainId)
|
|
274
279
|
|
|
275
280
|
if (!network) {
|
|
276
281
|
throw new Error(`Unknown network ${chainId}`)
|
package/src/types.ts
CHANGED
|
@@ -340,3 +340,8 @@ export type OptionalChainId = {
|
|
|
340
340
|
export type OptionalEIP6492 = {
|
|
341
341
|
eip6492?: boolean
|
|
342
342
|
} | undefined
|
|
343
|
+
|
|
344
|
+
// This is required by viem, it expects a provider to have an EIP-1193 compliant `request` attribute.
|
|
345
|
+
export interface EIP1193Provider {
|
|
346
|
+
request: (request: { method: string, params?: Array<any> }) => Promise<any>
|
|
347
|
+
}
|