@0xsequence/provider 1.1.3 → 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 +20 -6
- package/dist/0xsequence-provider.cjs.prod.js +20 -6
- package/dist/0xsequence-provider.esm.js +21 -7
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +3 -3
- package/package.json +10 -10
- package/src/transports/base-wallet-transport.ts +1 -1
- package/src/transports/wallet-request-handler.ts +25 -6
|
@@ -906,7 +906,7 @@ class BaseWalletTransport {
|
|
|
906
906
|
_this.notifyOpen({
|
|
907
907
|
sessionId: _this._sessionId,
|
|
908
908
|
chainId: `${chainId}`,
|
|
909
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
909
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
910
910
|
});
|
|
911
911
|
}
|
|
912
912
|
}
|
|
@@ -2157,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2157
2157
|
});
|
|
2158
2158
|
const connectDetails = promptConnectDetails;
|
|
2159
2159
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2160
|
-
connectDetails.session = await _this.walletSession();
|
|
2160
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2161
2161
|
}
|
|
2162
2162
|
return promptConnectDetails;
|
|
2163
2163
|
};
|
|
@@ -2690,7 +2690,7 @@ class WalletRequestHandler {
|
|
|
2690
2690
|
}
|
|
2691
2691
|
|
|
2692
2692
|
// Build session response for connect details
|
|
2693
|
-
connectDetails.session = await this.walletSession();
|
|
2693
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2694
2694
|
return connectDetails;
|
|
2695
2695
|
}
|
|
2696
2696
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2757,9 +2757,11 @@ class WalletRequestHandler {
|
|
|
2757
2757
|
return this.account.networks;
|
|
2758
2758
|
}
|
|
2759
2759
|
}
|
|
2760
|
-
walletSession() {
|
|
2761
|
-
if (!this.account)
|
|
2762
|
-
|
|
2760
|
+
walletSession(networkId) {
|
|
2761
|
+
if (!this.account) {
|
|
2762
|
+
return undefined;
|
|
2763
|
+
}
|
|
2764
|
+
const session = {
|
|
2763
2765
|
walletContext: this.account.contexts,
|
|
2764
2766
|
accountAddress: this.account.address,
|
|
2765
2767
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2768,6 +2770,18 @@ class WalletRequestHandler {
|
|
|
2768
2770
|
relayer: undefined
|
|
2769
2771
|
}))
|
|
2770
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;
|
|
2771
2785
|
}
|
|
2772
2786
|
notifyConnect(connectDetails, origin) {
|
|
2773
2787
|
var _connectDetails$sessi;
|
|
@@ -906,7 +906,7 @@ class BaseWalletTransport {
|
|
|
906
906
|
_this.notifyOpen({
|
|
907
907
|
sessionId: _this._sessionId,
|
|
908
908
|
chainId: `${chainId}`,
|
|
909
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
909
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
910
910
|
});
|
|
911
911
|
}
|
|
912
912
|
}
|
|
@@ -2157,7 +2157,7 @@ class WalletRequestHandler {
|
|
|
2157
2157
|
});
|
|
2158
2158
|
const connectDetails = promptConnectDetails;
|
|
2159
2159
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2160
|
-
connectDetails.session = await _this.walletSession();
|
|
2160
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2161
2161
|
}
|
|
2162
2162
|
return promptConnectDetails;
|
|
2163
2163
|
};
|
|
@@ -2690,7 +2690,7 @@ class WalletRequestHandler {
|
|
|
2690
2690
|
}
|
|
2691
2691
|
|
|
2692
2692
|
// Build session response for connect details
|
|
2693
|
-
connectDetails.session = await this.walletSession();
|
|
2693
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2694
2694
|
return connectDetails;
|
|
2695
2695
|
}
|
|
2696
2696
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2757,9 +2757,11 @@ class WalletRequestHandler {
|
|
|
2757
2757
|
return this.account.networks;
|
|
2758
2758
|
}
|
|
2759
2759
|
}
|
|
2760
|
-
walletSession() {
|
|
2761
|
-
if (!this.account)
|
|
2762
|
-
|
|
2760
|
+
walletSession(networkId) {
|
|
2761
|
+
if (!this.account) {
|
|
2762
|
+
return undefined;
|
|
2763
|
+
}
|
|
2764
|
+
const session = {
|
|
2763
2765
|
walletContext: this.account.contexts,
|
|
2764
2766
|
accountAddress: this.account.address,
|
|
2765
2767
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2768,6 +2770,18 @@ class WalletRequestHandler {
|
|
|
2768
2770
|
relayer: undefined
|
|
2769
2771
|
}))
|
|
2770
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;
|
|
2771
2785
|
}
|
|
2772
2786
|
notifyConnect(connectDetails, origin) {
|
|
2773
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, ChainId,
|
|
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
|
|
|
@@ -902,7 +902,7 @@ class BaseWalletTransport {
|
|
|
902
902
|
_this.notifyOpen({
|
|
903
903
|
sessionId: _this._sessionId,
|
|
904
904
|
chainId: `${chainId}`,
|
|
905
|
-
session: await _this.walletRequestHandler.walletSession()
|
|
905
|
+
session: await _this.walletRequestHandler.walletSession(chainId)
|
|
906
906
|
});
|
|
907
907
|
}
|
|
908
908
|
}
|
|
@@ -2153,7 +2153,7 @@ class WalletRequestHandler {
|
|
|
2153
2153
|
});
|
|
2154
2154
|
const connectDetails = promptConnectDetails;
|
|
2155
2155
|
if (connectDetails.connected && !connectDetails.session) {
|
|
2156
|
-
connectDetails.session = await _this.walletSession();
|
|
2156
|
+
connectDetails.session = await _this.walletSession(options == null ? void 0 : options.networkId);
|
|
2157
2157
|
}
|
|
2158
2158
|
return promptConnectDetails;
|
|
2159
2159
|
};
|
|
@@ -2686,7 +2686,7 @@ class WalletRequestHandler {
|
|
|
2686
2686
|
}
|
|
2687
2687
|
|
|
2688
2688
|
// Build session response for connect details
|
|
2689
|
-
connectDetails.session = await this.walletSession();
|
|
2689
|
+
connectDetails.session = await this.walletSession(chainId);
|
|
2690
2690
|
return connectDetails;
|
|
2691
2691
|
}
|
|
2692
2692
|
// sendMessageRequest will unwrap the ProviderMessageRequest and send it to the JsonRpcHandler
|
|
@@ -2753,9 +2753,11 @@ class WalletRequestHandler {
|
|
|
2753
2753
|
return this.account.networks;
|
|
2754
2754
|
}
|
|
2755
2755
|
}
|
|
2756
|
-
walletSession() {
|
|
2757
|
-
if (!this.account)
|
|
2758
|
-
|
|
2756
|
+
walletSession(networkId) {
|
|
2757
|
+
if (!this.account) {
|
|
2758
|
+
return undefined;
|
|
2759
|
+
}
|
|
2760
|
+
const session = {
|
|
2759
2761
|
walletContext: this.account.contexts,
|
|
2760
2762
|
accountAddress: this.account.address,
|
|
2761
2763
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
@@ -2764,6 +2766,18 @@ class WalletRequestHandler {
|
|
|
2764
2766
|
relayer: undefined
|
|
2765
2767
|
}))
|
|
2766
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;
|
|
2767
2781
|
}
|
|
2768
2782
|
notifyConnect(connectDetails, origin) {
|
|
2769
2783
|
var _connectDetails$sessi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Account } from '@0xsequence/account';
|
|
2
2
|
import { commons } from '@0xsequence/core';
|
|
3
|
-
import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, NetworkConfig } from '@0xsequence/network';
|
|
3
|
+
import { ChainIdLike, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, NetworkConfig } from '@0xsequence/network';
|
|
4
4
|
import { providers } from 'ethers';
|
|
5
5
|
import { ConnectDetails, ConnectOptions, MessageToSign, NetworkedConnectOptions, OpenWalletIntent, PromptConnectDetails, ProviderEventTypes, ProviderMessageRequest, ProviderMessageRequestHandler, ProviderMessageResponse, ProviderRpcError, WalletSession } from "../types.js";
|
|
6
6
|
type ExternalProvider = providers.ExternalProvider;
|
|
@@ -24,7 +24,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
24
24
|
signerReset(): void;
|
|
25
25
|
signerReady(timeout?: number): Promise<void>;
|
|
26
26
|
connect(options?: NetworkedConnectOptions): Promise<ConnectDetails>;
|
|
27
|
-
promptConnect: (options?:
|
|
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/core": "1.1.
|
|
18
|
-
"@0xsequence/migration": "1.1.
|
|
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"
|
|
@@ -444,7 +444,7 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
444
444
|
this.notifyOpen({
|
|
445
445
|
sessionId: this._sessionId,
|
|
446
446
|
chainId: `${chainId}`,
|
|
447
|
-
session: await this.walletRequestHandler.walletSession()
|
|
447
|
+
session: await this.walletRequestHandler.walletSession(chainId)
|
|
448
448
|
})
|
|
449
449
|
}
|
|
450
450
|
}
|
|
@@ -3,6 +3,8 @@ import { signAuthorization, AuthorizationOptions } from '@0xsequence/auth'
|
|
|
3
3
|
import { commons } from '@0xsequence/core'
|
|
4
4
|
import {
|
|
5
5
|
ChainId,
|
|
6
|
+
ChainIdLike,
|
|
7
|
+
findNetworkConfig,
|
|
6
8
|
findSupportedNetwork,
|
|
7
9
|
JsonRpcHandler,
|
|
8
10
|
JsonRpcRequest,
|
|
@@ -177,12 +179,12 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
// Build session response for connect details
|
|
180
|
-
connectDetails.session = await this.walletSession()
|
|
182
|
+
connectDetails.session = await this.walletSession(chainId)
|
|
181
183
|
|
|
182
184
|
return connectDetails
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
promptConnect = async (options?:
|
|
187
|
+
promptConnect = async (options?: NetworkedConnectOptions): Promise<ConnectDetails> => {
|
|
186
188
|
if (!options && !this._connectOptions) {
|
|
187
189
|
// this is an unexpected state and should not happen
|
|
188
190
|
throw new Error('prompter connect options are empty')
|
|
@@ -199,7 +201,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
199
201
|
|
|
200
202
|
const connectDetails: ConnectDetails = promptConnectDetails
|
|
201
203
|
if (connectDetails.connected && !connectDetails.session) {
|
|
202
|
-
connectDetails.session = await this.walletSession()
|
|
204
|
+
connectDetails.session = await this.walletSession(options?.networkId)
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
return promptConnectDetails
|
|
@@ -728,14 +730,31 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
728
730
|
}
|
|
729
731
|
}
|
|
730
732
|
|
|
731
|
-
walletSession(): WalletSession | undefined {
|
|
732
|
-
if (!this.account)
|
|
733
|
-
|
|
733
|
+
walletSession(networkId?: ChainIdLike): WalletSession | undefined {
|
|
734
|
+
if (!this.account) {
|
|
735
|
+
return undefined
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const session = {
|
|
734
739
|
walletContext: this.account.contexts,
|
|
735
740
|
accountAddress: this.account.address,
|
|
736
741
|
// The dapp shouldn't access the relayer directly, and the provider (as an object) is not serializable.
|
|
737
742
|
networks: this.account.networks.map(n => ({ ...n, provider: undefined, relayer: undefined }))
|
|
738
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
|
|
739
758
|
}
|
|
740
759
|
|
|
741
760
|
notifyConnect(connectDetails: ConnectDetails, origin?: string) {
|