@0xsequence/provider 1.1.2 → 1.1.4
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 +30 -10
- package/dist/0xsequence-provider.cjs.prod.js +30 -10
- package/dist/0xsequence-provider.esm.js +31 -11
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +5 -5
- package/package.json +10 -10
- package/src/transports/base-wallet-transport.ts +7 -1
- package/src/transports/wallet-request-handler.ts +43 -21
|
@@ -835,6 +835,11 @@ class BaseWalletTransport {
|
|
|
835
835
|
if (connectOptions.app) {
|
|
836
836
|
connectOptions.app = utils.sanitizeAlphanumeric(connectOptions.app);
|
|
837
837
|
}
|
|
838
|
+
if (connectOptions.networkId) {
|
|
839
|
+
networkId = connectOptions.networkId;
|
|
840
|
+
} else if (networkId) {
|
|
841
|
+
connectOptions.networkId = networkId;
|
|
842
|
+
}
|
|
838
843
|
|
|
839
844
|
// Set connect options on the walletRequestHandler as our primary
|
|
840
845
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -901,7 +906,7 @@ class BaseWalletTransport {
|
|
|
901
906
|
_this.notifyOpen({
|
|
902
907
|
sessionId: _this._sessionId,
|
|
903
908
|
chainId: `${chainId}`,
|
|
904
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
909
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
905
910
|
});
|
|
906
911
|
}
|
|
907
912
|
}
|
|
@@ -2152,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2152
2157
|
});
|
|
2153
2158
|
const connectDetails = promptConnectDetails;
|
|
2154
2159
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2155
|
-
connectDetails.session = await _this.walletSession();
|
|
2160
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2156
2161
|
}
|
|
2157
2162
|
return promptConnectDetails;
|
|
2158
2163
|
};
|
|
@@ -2645,7 +2650,7 @@ class WalletRequestHandler {
|
|
|
2645
2650
|
});
|
|
2646
2651
|
}
|
|
2647
2652
|
async connect(options) {
|
|
2648
|
-
var
|
|
2653
|
+
var _ref, _options$networkId;
|
|
2649
2654
|
if (!this.account) {
|
|
2650
2655
|
return {
|
|
2651
2656
|
connected: false,
|
|
@@ -2653,7 +2658,8 @@ class WalletRequestHandler {
|
|
|
2653
2658
|
error: 'unable to connect without signed in account'
|
|
2654
2659
|
};
|
|
2655
2660
|
}
|
|
2656
|
-
const
|
|
2661
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : network.ChainId.MAINNET;
|
|
2662
|
+
const chainId = network.findSupportedNetwork(networkId).chainId;
|
|
2657
2663
|
const connectDetails = {
|
|
2658
2664
|
connected: true,
|
|
2659
2665
|
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
@@ -2684,7 +2690,7 @@ class WalletRequestHandler {
|
|
|
2684
2690
|
}
|
|
2685
2691
|
|
|
2686
2692
|
// Build session response for connect details
|
|
2687
|
-
connectDetails.session = await this.walletSession();
|
|
2693
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2688
2694
|
return connectDetails;
|
|
2689
2695
|
}
|
|
2690
2696
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2730,8 +2736,8 @@ class WalletRequestHandler {
|
|
|
2730
2736
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2731
2737
|
}
|
|
2732
2738
|
async setDefaultChainId(chainId) {
|
|
2733
|
-
var _this$
|
|
2734
|
-
await ((_this$
|
|
2739
|
+
var _this$prompter4;
|
|
2740
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2735
2741
|
return this.defaultChainId();
|
|
2736
2742
|
}
|
|
2737
2743
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2751,9 +2757,11 @@ class WalletRequestHandler {
|
|
|
2751
2757
|
return this.account.networks;
|
|
2752
2758
|
}
|
|
2753
2759
|
}
|
|
2754
|
-
walletSession() {
|
|
2755
|
-
if (!this.account)
|
|
2756
|
-
|
|
2760
|
+
walletSession(networkId) {
|
|
2761
|
+
if (!this.account) {
|
|
2762
|
+
return undefined;
|
|
2763
|
+
}
|
|
2764
|
+
const session = {
|
|
2757
2765
|
walletContext: this.account.contexts,
|
|
2758
2766
|
accountAddress: this.account.address,
|
|
2759
2767
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2762,6 +2770,18 @@ class WalletRequestHandler {
|
|
|
2762
2770
|
relayer: undefined
|
|
2763
2771
|
}))
|
|
2764
2772
|
};
|
|
2773
|
+
if (networkId) {
|
|
2774
|
+
const network$1 = network.findNetworkConfig(session.networks, networkId);
|
|
2775
|
+
if (network$1) {
|
|
2776
|
+
var _session$networks;
|
|
2777
|
+
// Delete the isDefaultChain property from the session network
|
|
2778
|
+
(_session$networks = session.networks) == null ? void 0 : _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2779
|
+
|
|
2780
|
+
// Add the isDefaultChain property to the network with the given networkId
|
|
2781
|
+
network$1.isDefaultChain = true;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
return session;
|
|
2765
2785
|
}
|
|
2766
2786
|
notifyConnect(connectDetails, origin) {
|
|
2767
2787
|
var _connectDetails$sessi;
|
|
@@ -835,6 +835,11 @@ class BaseWalletTransport {
|
|
|
835
835
|
if (connectOptions.app) {
|
|
836
836
|
connectOptions.app = utils.sanitizeAlphanumeric(connectOptions.app);
|
|
837
837
|
}
|
|
838
|
+
if (connectOptions.networkId) {
|
|
839
|
+
networkId = connectOptions.networkId;
|
|
840
|
+
} else if (networkId) {
|
|
841
|
+
connectOptions.networkId = networkId;
|
|
842
|
+
}
|
|
838
843
|
|
|
839
844
|
// Set connect options on the walletRequestHandler as our primary
|
|
840
845
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -901,7 +906,7 @@ class BaseWalletTransport {
|
|
|
901
906
|
_this.notifyOpen({
|
|
902
907
|
sessionId: _this._sessionId,
|
|
903
908
|
chainId: `${chainId}`,
|
|
904
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
909
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
905
910
|
});
|
|
906
911
|
}
|
|
907
912
|
}
|
|
@@ -2152,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2152
2157
|
});
|
|
2153
2158
|
const connectDetails = promptConnectDetails;
|
|
2154
2159
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2155
|
-
connectDetails.session = await _this.walletSession();
|
|
2160
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2156
2161
|
}
|
|
2157
2162
|
return promptConnectDetails;
|
|
2158
2163
|
};
|
|
@@ -2645,7 +2650,7 @@ class WalletRequestHandler {
|
|
|
2645
2650
|
});
|
|
2646
2651
|
}
|
|
2647
2652
|
async connect(options) {
|
|
2648
|
-
var
|
|
2653
|
+
var _ref, _options$networkId;
|
|
2649
2654
|
if (!this.account) {
|
|
2650
2655
|
return {
|
|
2651
2656
|
connected: false,
|
|
@@ -2653,7 +2658,8 @@ class WalletRequestHandler {
|
|
|
2653
2658
|
error: 'unable to connect without signed in account'
|
|
2654
2659
|
};
|
|
2655
2660
|
}
|
|
2656
|
-
const
|
|
2661
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : network.ChainId.MAINNET;
|
|
2662
|
+
const chainId = network.findSupportedNetwork(networkId).chainId;
|
|
2657
2663
|
const connectDetails = {
|
|
2658
2664
|
connected: true,
|
|
2659
2665
|
chainId: ethers.ethers.utils.hexValue(chainId)
|
|
@@ -2684,7 +2690,7 @@ class WalletRequestHandler {
|
|
|
2684
2690
|
}
|
|
2685
2691
|
|
|
2686
2692
|
// Build session response for connect details
|
|
2687
|
-
connectDetails.session = await this.walletSession();
|
|
2693
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2688
2694
|
return connectDetails;
|
|
2689
2695
|
}
|
|
2690
2696
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2730,8 +2736,8 @@ class WalletRequestHandler {
|
|
|
2730
2736
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2731
2737
|
}
|
|
2732
2738
|
async setDefaultChainId(chainId) {
|
|
2733
|
-
var _this$
|
|
2734
|
-
await ((_this$
|
|
2739
|
+
var _this$prompter4;
|
|
2740
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2735
2741
|
return this.defaultChainId();
|
|
2736
2742
|
}
|
|
2737
2743
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2751,9 +2757,11 @@ class WalletRequestHandler {
|
|
|
2751
2757
|
return this.account.networks;
|
|
2752
2758
|
}
|
|
2753
2759
|
}
|
|
2754
|
-
walletSession() {
|
|
2755
|
-
if (!this.account)
|
|
2756
|
-
|
|
2760
|
+
walletSession(networkId) {
|
|
2761
|
+
if (!this.account) {
|
|
2762
|
+
return undefined;
|
|
2763
|
+
}
|
|
2764
|
+
const session = {
|
|
2757
2765
|
walletContext: this.account.contexts,
|
|
2758
2766
|
accountAddress: this.account.address,
|
|
2759
2767
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2762,6 +2770,18 @@ class WalletRequestHandler {
|
|
|
2762
2770
|
relayer: undefined
|
|
2763
2771
|
}))
|
|
2764
2772
|
};
|
|
2773
|
+
if (networkId) {
|
|
2774
|
+
const network$1 = network.findNetworkConfig(session.networks, networkId);
|
|
2775
|
+
if (network$1) {
|
|
2776
|
+
var _session$networks;
|
|
2777
|
+
// Delete the isDefaultChain property from the session network
|
|
2778
|
+
(_session$networks = session.networks) == null ? void 0 : _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2779
|
+
|
|
2780
|
+
// Add the isDefaultChain property to the network with the given networkId
|
|
2781
|
+
network$1.isDefaultChain = true;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
return session;
|
|
2765
2785
|
}
|
|
2766
2786
|
notifyConnect(connectDetails, origin) {
|
|
2767
2787
|
var _connectDetails$sessi;
|
|
@@ -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, ChainId, findNetworkConfig, allNetworks, JsonRpcRouter, loggingProviderMiddleware, exceptionProviderMiddleware, CachedProvider, JsonRpcSender } from '@0xsequence/network';
|
|
5
5
|
import { commons } from '@0xsequence/core';
|
|
6
6
|
import { signAuthorization } from '@0xsequence/auth';
|
|
7
7
|
|
|
@@ -831,6 +831,11 @@ class BaseWalletTransport {
|
|
|
831
831
|
if (connectOptions.app) {
|
|
832
832
|
connectOptions.app = sanitizeAlphanumeric(connectOptions.app);
|
|
833
833
|
}
|
|
834
|
+
if (connectOptions.networkId) {
|
|
835
|
+
networkId = connectOptions.networkId;
|
|
836
|
+
} else if (networkId) {
|
|
837
|
+
connectOptions.networkId = networkId;
|
|
838
|
+
}
|
|
834
839
|
|
|
835
840
|
// Set connect options on the walletRequestHandler as our primary
|
|
836
841
|
// wallet controller, and fall back to networkId if necessary
|
|
@@ -897,7 +902,7 @@ class BaseWalletTransport {
|
|
|
897
902
|
_this.notifyOpen({
|
|
898
903
|
sessionId: _this._sessionId,
|
|
899
904
|
chainId: `${chainId}`,
|
|
900
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
905
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
901
906
|
});
|
|
902
907
|
}
|
|
903
908
|
}
|
|
@@ -2148,7 +2153,7 @@ class WalletRequestHandler {
|
|
|
2148
2153
|
});
|
|
2149
2154
|
const connectDetails = promptConnectDetails;
|
|
2150
2155
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2151
|
-
connectDetails.session = await _this.walletSession();
|
|
2156
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2152
2157
|
}
|
|
2153
2158
|
return promptConnectDetails;
|
|
2154
2159
|
};
|
|
@@ -2641,7 +2646,7 @@ class WalletRequestHandler {
|
|
|
2641
2646
|
});
|
|
2642
2647
|
}
|
|
2643
2648
|
async connect(options) {
|
|
2644
|
-
var
|
|
2649
|
+
var _ref, _options$networkId;
|
|
2645
2650
|
if (!this.account) {
|
|
2646
2651
|
return {
|
|
2647
2652
|
connected: false,
|
|
@@ -2649,7 +2654,8 @@ class WalletRequestHandler {
|
|
|
2649
2654
|
error: 'unable to connect without signed in account'
|
|
2650
2655
|
};
|
|
2651
2656
|
}
|
|
2652
|
-
const
|
|
2657
|
+
const networkId = (_ref = (_options$networkId = options == null ? void 0 : options.networkId) != null ? _options$networkId : this.defaultChainId()) != null ? _ref : ChainId.MAINNET;
|
|
2658
|
+
const chainId = findSupportedNetwork(networkId).chainId;
|
|
2653
2659
|
const connectDetails = {
|
|
2654
2660
|
connected: true,
|
|
2655
2661
|
chainId: ethers.utils.hexValue(chainId)
|
|
@@ -2680,7 +2686,7 @@ class WalletRequestHandler {
|
|
|
2680
2686
|
}
|
|
2681
2687
|
|
|
2682
2688
|
// Build session response for connect details
|
|
2683
|
-
connectDetails.session = await this.walletSession();
|
|
2689
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2684
2690
|
return connectDetails;
|
|
2685
2691
|
}
|
|
2686
2692
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2726,8 +2732,8 @@ class WalletRequestHandler {
|
|
|
2726
2732
|
(_this$onConnectOption = this.onConnectOptionsChange) == null ? void 0 : _this$onConnectOption.call(this, options);
|
|
2727
2733
|
}
|
|
2728
2734
|
async setDefaultChainId(chainId) {
|
|
2729
|
-
var _this$
|
|
2730
|
-
await ((_this$
|
|
2735
|
+
var _this$prompter4;
|
|
2736
|
+
await ((_this$prompter4 = this.prompter) == null ? void 0 : _this$prompter4.promptChangeNetwork(chainId));
|
|
2731
2737
|
return this.defaultChainId();
|
|
2732
2738
|
}
|
|
2733
2739
|
async getNetworks(jsonRpcResponse) {
|
|
@@ -2747,9 +2753,11 @@ class WalletRequestHandler {
|
|
|
2747
2753
|
return this.account.networks;
|
|
2748
2754
|
}
|
|
2749
2755
|
}
|
|
2750
|
-
walletSession() {
|
|
2751
|
-
if (!this.account)
|
|
2752
|
-
|
|
2756
|
+
walletSession(networkId) {
|
|
2757
|
+
if (!this.account) {
|
|
2758
|
+
return undefined;
|
|
2759
|
+
}
|
|
2760
|
+
const session = {
|
|
2753
2761
|
walletContext: this.account.contexts,
|
|
2754
2762
|
accountAddress: this.account.address,
|
|
2755
2763
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2758,6 +2766,18 @@ class WalletRequestHandler {
|
|
|
2758
2766
|
relayer: undefined
|
|
2759
2767
|
}))
|
|
2760
2768
|
};
|
|
2769
|
+
if (networkId) {
|
|
2770
|
+
const network = findNetworkConfig(session.networks, networkId);
|
|
2771
|
+
if (network) {
|
|
2772
|
+
var _session$networks;
|
|
2773
|
+
// Delete the isDefaultChain property from the session network
|
|
2774
|
+
(_session$networks = session.networks) == null ? void 0 : _session$networks.forEach(n => delete n.isDefaultChain);
|
|
2775
|
+
|
|
2776
|
+
// Add the isDefaultChain property to the network with the given networkId
|
|
2777
|
+
network.isDefaultChain = true;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
return session;
|
|
2761
2781
|
}
|
|
2762
2782
|
notifyConnect(connectDetails, origin) {
|
|
2763
2783
|
var _connectDetails$sessi;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Account } from '@0xsequence/account';
|
|
2
2
|
import { commons } from '@0xsequence/core';
|
|
3
|
-
import {
|
|
3
|
+
import { ChainIdLike, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, NetworkConfig } from '@0xsequence/network';
|
|
4
4
|
import { providers } from 'ethers';
|
|
5
|
-
import {
|
|
5
|
+
import { ConnectDetails, ConnectOptions, MessageToSign, NetworkedConnectOptions, OpenWalletIntent, PromptConnectDetails, ProviderEventTypes, ProviderMessageRequest, ProviderMessageRequestHandler, ProviderMessageResponse, ProviderRpcError, WalletSession } from "../types.js";
|
|
6
6
|
type ExternalProvider = providers.ExternalProvider;
|
|
7
7
|
export interface WalletSignInOptions {
|
|
8
8
|
connect?: boolean;
|
|
@@ -23,8 +23,8 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
23
23
|
signOut(): void;
|
|
24
24
|
signerReset(): void;
|
|
25
25
|
signerReady(timeout?: number): Promise<void>;
|
|
26
|
-
connect(options?:
|
|
27
|
-
promptConnect: (options?:
|
|
26
|
+
connect(options?: NetworkedConnectOptions): Promise<ConnectDetails>;
|
|
27
|
+
promptConnect: (options?: NetworkedConnectOptions) => Promise<ConnectDetails>;
|
|
28
28
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
29
29
|
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>;
|
|
30
30
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
@@ -36,7 +36,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
36
36
|
setConnectOptions(options: ConnectOptions | undefined): void;
|
|
37
37
|
setDefaultChainId(chainId: number): Promise<number>;
|
|
38
38
|
getNetworks(jsonRpcResponse?: boolean): Promise<NetworkConfig[]>;
|
|
39
|
-
walletSession(): WalletSession | undefined;
|
|
39
|
+
walletSession(networkId?: ChainIdLike): WalletSession | undefined;
|
|
40
40
|
notifyConnect(connectDetails: ConnectDetails, origin?: string): void;
|
|
41
41
|
notifyDisconnect(origin?: string): void;
|
|
42
42
|
notifyNetworks(networks?: NetworkConfig[]): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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": "1.1.
|
|
15
|
-
"@0xsequence/
|
|
16
|
-
"@0xsequence/
|
|
17
|
-
"@0xsequence/
|
|
18
|
-
"@0xsequence/
|
|
19
|
-
"@0xsequence/network": "1.1.
|
|
20
|
-
"@0xsequence/relayer": "1.1.
|
|
21
|
-
"@0xsequence/utils": "1.1.
|
|
22
|
-
"@0xsequence/wallet": "1.1.
|
|
14
|
+
"@0xsequence/abi": "1.1.4",
|
|
15
|
+
"@0xsequence/auth": "1.1.4",
|
|
16
|
+
"@0xsequence/account": "1.1.4",
|
|
17
|
+
"@0xsequence/core": "1.1.4",
|
|
18
|
+
"@0xsequence/migration": "1.1.4",
|
|
19
|
+
"@0xsequence/network": "1.1.4",
|
|
20
|
+
"@0xsequence/relayer": "1.1.4",
|
|
21
|
+
"@0xsequence/utils": "1.1.4",
|
|
22
|
+
"@0xsequence/wallet": "1.1.4"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"ethers": ">=5.5 < 6"
|
|
@@ -372,6 +372,12 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
372
372
|
connectOptions.app = sanitizeAlphanumeric(connectOptions.app)
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
if (connectOptions.networkId) {
|
|
376
|
+
networkId = connectOptions.networkId
|
|
377
|
+
} else if (networkId) {
|
|
378
|
+
connectOptions.networkId = networkId
|
|
379
|
+
}
|
|
380
|
+
|
|
375
381
|
// Set connect options on the walletRequestHandler as our primary
|
|
376
382
|
// wallet controller, and fall back to networkId if necessary
|
|
377
383
|
this.walletRequestHandler.setConnectOptions(connectOptions)
|
|
@@ -438,7 +444,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
438
444
|
this.notifyOpen({
|
|
439
445
|
sessionId: this._sessionId,
|
|
440
446
|
chainId: `${chainId}`,
|
|
441
|
-
session: await this.walletRequestHandler.walletSession()
|
|
447
|
+
session: await this.walletRequestHandler.walletSession(chainId)
|
|
442
448
|
})
|
|
443
449
|
}
|
|
444
450
|
}
|
|
@@ -2,12 +2,15 @@ import { Account, AccountStatus } from '@0xsequence/account'
|
|
|
2
2
|
import { signAuthorization, AuthorizationOptions } from '@0xsequence/auth'
|
|
3
3
|
import { commons } from '@0xsequence/core'
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
ChainId,
|
|
6
|
+
ChainIdLike,
|
|
7
|
+
findNetworkConfig,
|
|
8
|
+
findSupportedNetwork,
|
|
6
9
|
JsonRpcHandler,
|
|
7
10
|
JsonRpcRequest,
|
|
8
|
-
JsonRpcResponseCallback,
|
|
9
11
|
JsonRpcResponse,
|
|
10
|
-
|
|
12
|
+
JsonRpcResponseCallback,
|
|
13
|
+
NetworkConfig
|
|
11
14
|
} from '@0xsequence/network'
|
|
12
15
|
import { logger, TypedData } from '@0xsequence/utils'
|
|
13
16
|
import { BigNumber, ethers, providers } from 'ethers'
|
|
@@ -16,19 +19,20 @@ import { EventEmitter2 as EventEmitter } from 'eventemitter2'
|
|
|
16
19
|
import { fromExtended } from '../extended'
|
|
17
20
|
import { validateTransactionRequest } from '../transactions'
|
|
18
21
|
import {
|
|
19
|
-
ProviderMessageRequest,
|
|
20
|
-
ProviderMessageResponse,
|
|
21
|
-
ProviderMessageRequestHandler,
|
|
22
|
-
MessageToSign,
|
|
23
|
-
ProviderRpcError,
|
|
24
|
-
ConnectOptions,
|
|
25
22
|
ConnectDetails,
|
|
26
|
-
|
|
27
|
-
WalletSession,
|
|
28
|
-
OpenWalletIntent,
|
|
23
|
+
ConnectOptions,
|
|
29
24
|
ErrSignedInRequired,
|
|
25
|
+
MessageToSign,
|
|
26
|
+
NetworkedConnectOptions,
|
|
27
|
+
OpenWalletIntent,
|
|
28
|
+
PromptConnectDetails,
|
|
30
29
|
ProviderEventTypes,
|
|
31
|
-
|
|
30
|
+
ProviderMessageRequest,
|
|
31
|
+
ProviderMessageRequestHandler,
|
|
32
|
+
ProviderMessageResponse,
|
|
33
|
+
ProviderRpcError,
|
|
34
|
+
TypedEventEmitter,
|
|
35
|
+
WalletSession
|
|
32
36
|
} from '../types'
|
|
33
37
|
import { prefixEIP191Message } from '../utils'
|
|
34
38
|
|
|
@@ -132,7 +136,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
132
136
|
})
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
async connect(options?:
|
|
139
|
+
async connect(options?: NetworkedConnectOptions): Promise<ConnectDetails> {
|
|
136
140
|
if (!this.account) {
|
|
137
141
|
return {
|
|
138
142
|
connected: false,
|
|
@@ -141,7 +145,8 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
const
|
|
148
|
+
const networkId = options?.networkId ?? this.defaultChainId() ?? ChainId.MAINNET
|
|
149
|
+
const chainId = findSupportedNetwork(networkId)!.chainId
|
|
145
150
|
|
|
146
151
|
const connectDetails: ConnectDetails = {
|
|
147
152
|
connected: true,
|
|
@@ -174,12 +179,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
// Build session response for connect details
|
|
177
|
-
connectDetails.session = await this.walletSession()
|
|
182
|
+
connectDetails.session = await this.walletSession(chainId)
|
|
178
183
|
|
|
179
184
|
return connectDetails
|
|
180
185
|
}
|
|
181
186
|
|
|
182
|
-
promptConnect = async (options?:
|
|
187
|
+
promptConnect = async (options?: NetworkedConnectOptions): Promise<ConnectDetails> => {
|
|
183
188
|
if (!options && !this._connectOptions) {
|
|
184
189
|
// this is an unexpected state and should not happen
|
|
185
190
|
throw new Error('prompter connect options are empty')
|
|
@@ -196,7 +201,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
196
201
|
|
|
197
202
|
const connectDetails: ConnectDetails = promptConnectDetails
|
|
198
203
|
if (connectDetails.connected && !connectDetails.session) {
|
|
199
|
-
connectDetails.session = await this.walletSession()
|
|
204
|
+
connectDetails.session = await this.walletSession(options?.networkId)
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
return promptConnectDetails
|
|
@@ -725,14 +730,31 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
725
730
|
}
|
|
726
731
|
}
|
|
727
732
|
|
|
728
|
-
walletSession(): WalletSession | undefined {
|
|
729
|
-
if (!this.account)
|
|
730
|
-
|
|
733
|
+
walletSession(networkId?: ChainIdLike): WalletSession | undefined {
|
|
734
|
+
if (!this.account) {
|
|
735
|
+
return undefined
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const session = {
|
|
731
739
|
walletContext: this.account.contexts,
|
|
732
740
|
accountAddress: this.account.address,
|
|
733
741
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
734
742
|
networks: this.account.networks.map(n => ({ ...n, provider: undefined, relayer: undefined }))
|
|
735
743
|
}
|
|
744
|
+
|
|
745
|
+
if (networkId) {
|
|
746
|
+
const network = findNetworkConfig(session.networks, networkId)
|
|
747
|
+
|
|
748
|
+
if (network) {
|
|
749
|
+
// Delete the isDefaultChain property from the session network
|
|
750
|
+
session.networks?.forEach(n => delete n.isDefaultChain)
|
|
751
|
+
|
|
752
|
+
// Add the isDefaultChain property to the network with the given networkId
|
|
753
|
+
network.isDefaultChain = true
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
return session
|
|
736
758
|
}
|
|
737
759
|
|
|
738
760
|
notifyConnect(connectDetails: ConnectDetails, origin?: string) {
|