@0xsequence/provider 0.42.9 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/0xsequence-provider.cjs.dev.js +422 -869
- package/dist/0xsequence-provider.cjs.prod.js +422 -869
- package/dist/0xsequence-provider.esm.js +423 -870
- package/dist/declarations/src/provider.d.ts +7 -6
- package/dist/declarations/src/transports/base-provider-transport.d.ts +1 -1
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +1 -1
- package/dist/declarations/src/transports/mux-transport/mux-message-provider.d.ts +2 -2
- package/dist/declarations/src/transports/proxy-transport/proxy-message-provider.d.ts +1 -1
- package/dist/declarations/src/transports/unreal-transport/unreal-message-provider.d.ts +1 -1
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +10 -4
- package/dist/declarations/src/transports/window-transport/window-message-provider.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +1 -1
- package/dist/declarations/src/utils/index.d.ts +4 -5
- package/dist/declarations/src/utils.d.ts +4 -4
- package/dist/declarations/src/wallet.d.ts +5 -5
- package/package.json +14 -15
- package/src/provider.ts +10 -14
- package/src/transports/wallet-request-handler.ts +17 -2
- package/src/types.ts +1 -2
- package/src/utils/index.ts +2 -9
- package/src/wallet.ts +2 -3
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { BytesLike, Bytes } from '@ethersproject/bytes';
|
|
3
|
-
import { Web3Provider as EthersWeb3Provider, JsonRpcProvider } from '@ethersproject/providers';
|
|
4
|
-
import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer';
|
|
1
|
+
import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField } from 'ethers';
|
|
5
2
|
import { NetworkConfig, WalletContext, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
|
|
6
3
|
import { Signer } from '@0xsequence/wallet';
|
|
7
4
|
import { WalletConfig, WalletState } from '@0xsequence/config';
|
|
8
5
|
import { Relayer } from '@0xsequence/relayer';
|
|
9
6
|
import { Deferrable, Forbid } from '@0xsequence/utils';
|
|
10
7
|
import { TransactionRequest, TransactionResponse, SignedTransactions } from '@0xsequence/transactions';
|
|
11
|
-
export declare class Web3Provider extends
|
|
8
|
+
export declare class Web3Provider extends providers.Web3Provider implements JsonRpcHandler {
|
|
12
9
|
static isSequenceProvider(cand: any): cand is Web3Provider;
|
|
13
10
|
readonly _sender: JsonRpcSender;
|
|
14
11
|
readonly _isSequenceProvider: boolean;
|
|
15
12
|
readonly _defaultChainId?: number;
|
|
16
|
-
constructor(provider: JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike);
|
|
13
|
+
constructor(provider: providers.JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike);
|
|
17
14
|
sendAsync(request: JsonRpcRequest, callback: JsonRpcResponseCallback | ((error: any, response: any) => void), chainId?: number): void;
|
|
18
15
|
send(method: string, params: Array<any>, chainId?: number): Promise<any>;
|
|
19
16
|
request(request: {
|
|
@@ -28,6 +25,9 @@ export declare function isSequenceProvider(provider: any): provider is Web3Provi
|
|
|
28
25
|
export declare class LocalWeb3Provider extends Web3Provider {
|
|
29
26
|
constructor(signer: Signer, networks?: NetworkConfig[]);
|
|
30
27
|
}
|
|
28
|
+
interface TypedDataSigner {
|
|
29
|
+
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
30
|
+
}
|
|
31
31
|
export declare class Web3Signer extends Signer implements TypedDataSigner {
|
|
32
32
|
readonly provider: Web3Provider;
|
|
33
33
|
readonly defaultChainId?: number;
|
|
@@ -63,3 +63,4 @@ export declare class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
63
63
|
connectUnchecked(): ethers.providers.JsonRpcSigner;
|
|
64
64
|
unlock(password: string): Promise<boolean>;
|
|
65
65
|
}
|
|
66
|
+
export {};
|
|
@@ -30,7 +30,7 @@ export declare abstract class BaseProviderTransport implements ProviderTransport
|
|
|
30
30
|
closeWallet(): void;
|
|
31
31
|
isOpened(): boolean;
|
|
32
32
|
isConnected(): boolean;
|
|
33
|
-
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number
|
|
33
|
+
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>;
|
|
34
34
|
handleMessage(message: ProviderMessage<any>): void;
|
|
35
35
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
36
36
|
sendMessage(message: ProviderMessage<any>): void;
|
|
@@ -13,7 +13,7 @@ export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
|
13
13
|
get registered(): boolean;
|
|
14
14
|
register(): void;
|
|
15
15
|
unregister(): void;
|
|
16
|
-
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number
|
|
16
|
+
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<never>;
|
|
17
17
|
handleMessage: (message: ProviderMessage<any>) => Promise<void>;
|
|
18
18
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
19
19
|
sendMessage(message: ProviderMessage<any>): void;
|
|
@@ -7,14 +7,14 @@ export declare class MuxMessageProvider implements ProviderTransport {
|
|
|
7
7
|
add(...messageProviders: ProviderTransport[]): void;
|
|
8
8
|
register: () => void;
|
|
9
9
|
unregister: () => void;
|
|
10
|
-
openWallet: (path?: string
|
|
10
|
+
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => void;
|
|
11
11
|
closeWallet(): void;
|
|
12
12
|
isOpened(): boolean;
|
|
13
13
|
isConnected(): boolean;
|
|
14
14
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
15
15
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
16
16
|
emit<K extends keyof ProviderEventTypes>(event: K, ...args: Parameters<ProviderEventTypes[K]>): boolean;
|
|
17
|
-
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number
|
|
17
|
+
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>;
|
|
18
18
|
sendMessage(message: ProviderMessage<any>): void;
|
|
19
19
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
20
20
|
handleMessage(message: ProviderMessage<any>): void;
|
|
@@ -6,7 +6,7 @@ export declare class ProxyMessageProvider extends BaseProviderTransport {
|
|
|
6
6
|
constructor(port: ProxyMessageChannelPort);
|
|
7
7
|
register: () => void;
|
|
8
8
|
unregister: () => void;
|
|
9
|
-
openWallet: (path?: string
|
|
9
|
+
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => void;
|
|
10
10
|
closeWallet(): void;
|
|
11
11
|
sendMessage(message: ProviderMessage<any>): void;
|
|
12
12
|
}
|
|
@@ -8,7 +8,7 @@ export declare class UnrealMessageProvider extends BaseProviderTransport {
|
|
|
8
8
|
constructor(walletAppURL: string);
|
|
9
9
|
register: () => void;
|
|
10
10
|
unregister: () => void;
|
|
11
|
-
openWallet: (path?: string
|
|
11
|
+
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => void;
|
|
12
12
|
closeWallet(): void;
|
|
13
13
|
private onUnrealCallback;
|
|
14
14
|
sendMessage(message: ProviderMessage<unknown>): void;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ProviderMessageRequest, ProviderMessageResponse, ProviderMessageRequestHandler, MessageToSign, ProviderRpcError, ConnectOptions, ConnectDetails, PromptConnectDetails, WalletSession, OpenWalletIntent, ProviderEventTypes } from '../types';
|
|
2
|
-
import {
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
3
|
import { NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
4
4
|
import { Signer } from '@0xsequence/wallet';
|
|
5
5
|
import { TransactionRequest } from '@0xsequence/transactions';
|
|
6
|
+
declare type ExternalProvider = providers.ExternalProvider;
|
|
6
7
|
export interface WalletSignInOptions {
|
|
7
8
|
connect?: boolean;
|
|
8
9
|
mainnetNetworks?: NetworkConfig[];
|
|
@@ -13,6 +14,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
13
14
|
private signer;
|
|
14
15
|
private signerReadyCallbacks;
|
|
15
16
|
private prompter;
|
|
17
|
+
private auxDataProvider;
|
|
16
18
|
private mainnetNetworks;
|
|
17
19
|
private testnetNetworks;
|
|
18
20
|
private _openIntent?;
|
|
@@ -20,15 +22,15 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
20
22
|
private _defaultNetworkId?;
|
|
21
23
|
private _chainId?;
|
|
22
24
|
private events;
|
|
23
|
-
constructor(signer: Signer | null | undefined, prompter: WalletUserPrompter | null, mainnetNetworks: NetworkConfig[], testnetNetworks?: NetworkConfig[]);
|
|
25
|
+
constructor(signer: Signer | null | undefined, prompter: WalletUserPrompter | null, auxDataProvider: AuxDataProvider | null, mainnetNetworks: NetworkConfig[], testnetNetworks?: NetworkConfig[]);
|
|
24
26
|
signIn(signer: Signer | null, options?: WalletSignInOptions): Promise<void>;
|
|
25
27
|
signOut(): void;
|
|
26
28
|
signerReset(): void;
|
|
27
29
|
signerReady(timeout?: number): Promise<void>;
|
|
28
30
|
connect(options?: ConnectOptions): Promise<ConnectDetails>;
|
|
29
|
-
promptConnect: (options?: ConnectOptions
|
|
31
|
+
promptConnect: (options?: ConnectOptions) => Promise<ConnectDetails>;
|
|
30
32
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
31
|
-
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number
|
|
33
|
+
sendAsync: (request: JsonRpcRequest, callback: JsonRpcResponseCallback, chainId?: number) => Promise<void>;
|
|
32
34
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
33
35
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
34
36
|
getAddress(): Promise<string>;
|
|
@@ -58,3 +60,7 @@ export interface WalletUserPrompter {
|
|
|
58
60
|
promptSendTransaction(txn: TransactionRequest, chaindId?: number, options?: ConnectOptions): Promise<string>;
|
|
59
61
|
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>;
|
|
60
62
|
}
|
|
63
|
+
export interface AuxDataProvider {
|
|
64
|
+
get(key: string): Promise<any>;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -6,7 +6,7 @@ export declare class WindowMessageProvider extends BaseProviderTransport {
|
|
|
6
6
|
constructor(walletAppURL: string);
|
|
7
7
|
register: () => void;
|
|
8
8
|
unregister: () => void;
|
|
9
|
-
openWallet: (path?: string
|
|
9
|
+
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => void;
|
|
10
10
|
closeWallet(): void;
|
|
11
11
|
private onWindowEvent;
|
|
12
12
|
sendMessage(message: ProviderMessage<any>): void;
|
|
@@ -121,7 +121,7 @@ export interface ConnectOptions {
|
|
|
121
121
|
expiry?: number;
|
|
122
122
|
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
|
|
123
123
|
authorize?: boolean;
|
|
124
|
-
/**
|
|
124
|
+
/** askForEmail will prompt to give permission to the dapp to access email address */
|
|
125
125
|
askForEmail?: boolean;
|
|
126
126
|
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */
|
|
127
127
|
refresh?: boolean;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { BigNumberish, BytesLike } from 'ethers';
|
|
2
|
-
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
|
|
1
|
+
import { BigNumberish, BytesLike, TypedDataDomain, TypedDataField } from 'ethers';
|
|
3
2
|
import { WalletContext, ChainIdLike } from '@0xsequence/network';
|
|
4
3
|
import { TypedData } from '@0xsequence/utils';
|
|
5
4
|
import { DecodedSignature, WalletConfig } from '@0xsequence/config';
|
|
@@ -14,7 +13,7 @@ export declare class WalletUtils {
|
|
|
14
13
|
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>;
|
|
15
14
|
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>;
|
|
16
15
|
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number, walletContext?: WalletContext): Promise<boolean | undefined>;
|
|
17
|
-
recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext
|
|
18
|
-
recoverWalletConfigFromMessage: (address: string, message: string | Uint8Array, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext
|
|
19
|
-
recoverWalletConfigFromTypedData: (address: string, typedData: TypedData, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext
|
|
16
|
+
recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>;
|
|
17
|
+
recoverWalletConfigFromMessage: (address: string, message: string | Uint8Array, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>;
|
|
18
|
+
recoverWalletConfigFromTypedData: (address: string, typedData: TypedData, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>;
|
|
20
19
|
}
|
|
@@ -6,10 +6,10 @@ import { Web3Provider } from './provider';
|
|
|
6
6
|
import { Signer } from '@0xsequence/wallet';
|
|
7
7
|
export declare const messageToBytes: (message: BytesLike) => Uint8Array;
|
|
8
8
|
export declare const prefixEIP191Message: (message: BytesLike) => Uint8Array;
|
|
9
|
-
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number
|
|
10
|
-
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number
|
|
11
|
-
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number
|
|
12
|
-
export declare const recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext
|
|
9
|
+
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number, walletContext?: WalletContext) => Promise<boolean | undefined>;
|
|
10
|
+
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number, walletContext?: WalletContext) => Promise<boolean | undefined>;
|
|
11
|
+
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: Web3Provider | ethers.providers.Web3Provider, chainId?: number, walletContext?: WalletContext) => Promise<boolean | undefined>;
|
|
12
|
+
export declare const recoverWalletConfig: (address: string, digest: BytesLike, signature: string | DecodedSignature, chainId: BigNumberish, walletContext?: WalletContext) => Promise<WalletConfig>;
|
|
13
13
|
export declare const isBrowserExtension: () => boolean;
|
|
14
14
|
export declare const isUnityPlugin: () => boolean;
|
|
15
15
|
/**
|
|
@@ -40,22 +40,22 @@ export declare class Wallet implements WalletProvider {
|
|
|
40
40
|
constructor(network?: string | number, config?: Partial<ProviderConfig>);
|
|
41
41
|
private init;
|
|
42
42
|
loadSession: () => Promise<WalletSession | undefined>;
|
|
43
|
-
connect: (options?: ConnectOptions
|
|
43
|
+
connect: (options?: ConnectOptions) => Promise<ConnectDetails>;
|
|
44
44
|
addConnectedSite(origin: string | undefined): Promise<void>;
|
|
45
45
|
removeConnectedSite(origin: string): Promise<void>;
|
|
46
46
|
getConnectedSites(): Promise<string[] | undefined>;
|
|
47
47
|
isSiteConnected(origin: string | undefined): Promise<boolean>;
|
|
48
|
-
authorize: (options?: ConnectOptions
|
|
48
|
+
authorize: (options?: ConnectOptions) => Promise<ConnectDetails>;
|
|
49
49
|
disconnect(): void;
|
|
50
50
|
getProviderConfig(): ProviderConfig;
|
|
51
51
|
isOpened(): boolean;
|
|
52
52
|
isConnected(): boolean;
|
|
53
53
|
getSession: () => WalletSession | undefined;
|
|
54
54
|
getAddress: () => Promise<string>;
|
|
55
|
-
getNetworks: (chainId?: ChainIdLike
|
|
55
|
+
getNetworks: (chainId?: ChainIdLike) => Promise<NetworkConfig[]>;
|
|
56
56
|
getChainId: () => Promise<number>;
|
|
57
57
|
getAuthChainId: () => Promise<number>;
|
|
58
|
-
openWallet: (path?: string
|
|
58
|
+
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => Promise<boolean>;
|
|
59
59
|
closeWallet: () => void;
|
|
60
60
|
getProvider(chainId?: ChainIdLike): Web3Provider | undefined;
|
|
61
61
|
getAuthProvider(): Promise<Web3Provider>;
|
|
@@ -102,5 +102,5 @@ export interface ProviderConfig {
|
|
|
102
102
|
walletContext?: WalletContext;
|
|
103
103
|
}
|
|
104
104
|
export declare const DefaultProviderConfig: ProviderConfig;
|
|
105
|
-
export declare const initWallet: (network?: string | number
|
|
105
|
+
export declare const initWallet: (network?: string | number, config?: Partial<ProviderConfig>) => Promise<Wallet>;
|
|
106
106
|
export declare const getWallet: () => Wallet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "provider sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -14,23 +14,22 @@
|
|
|
14
14
|
"typecheck": "tsc --noEmit"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@0xsequence/abi": "^0.
|
|
18
|
-
"@0xsequence/auth": "^0.
|
|
19
|
-
"@0xsequence/config": "^0.
|
|
20
|
-
"@0xsequence/network": "^0.
|
|
21
|
-
"@0xsequence/transactions": "^0.
|
|
22
|
-
"@0xsequence/utils": "^0.
|
|
23
|
-
"@0xsequence/wallet": "^0.
|
|
24
|
-
"@ethersproject/abstract-signer": "^5.5.0",
|
|
25
|
-
"@ethersproject/hash": "^5.5.0",
|
|
26
|
-
"@ethersproject/providers": "^5.5.1",
|
|
27
|
-
"@ethersproject/web": "^5.5.1",
|
|
28
|
-
"ethers": "^5.5.2",
|
|
17
|
+
"@0xsequence/abi": "^0.43.0",
|
|
18
|
+
"@0xsequence/auth": "^0.43.0",
|
|
19
|
+
"@0xsequence/config": "^0.43.0",
|
|
20
|
+
"@0xsequence/network": "^0.43.0",
|
|
21
|
+
"@0xsequence/transactions": "^0.43.0",
|
|
22
|
+
"@0xsequence/utils": "^0.43.0",
|
|
23
|
+
"@0xsequence/wallet": "^0.43.0",
|
|
29
24
|
"eventemitter2": "^6.4.5",
|
|
30
25
|
"webextension-polyfill-ts": "^0.26.0"
|
|
31
26
|
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"ethers": ">=5.5"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"ethers": "^5.7.2"
|
|
32
|
+
},
|
|
34
33
|
"files": [
|
|
35
34
|
"src",
|
|
36
35
|
"dist"
|
package/src/provider.ts
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
import { ethers } from 'ethers'
|
|
2
|
-
import { BytesLike, Bytes } from '@ethersproject/bytes'
|
|
3
|
-
import { Web3Provider as EthersWeb3Provider, ExternalProvider, JsonRpcProvider, Networkish } from '@ethersproject/providers'
|
|
4
|
-
import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer'
|
|
1
|
+
import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField } from 'ethers'
|
|
5
2
|
import {
|
|
6
3
|
NetworkConfig,
|
|
7
4
|
WalletContext,
|
|
8
5
|
ChainIdLike,
|
|
9
6
|
JsonRpcHandler,
|
|
10
|
-
JsonRpcHandlerFunc,
|
|
11
7
|
JsonRpcFetchFunc,
|
|
12
8
|
JsonRpcRequest,
|
|
13
9
|
JsonRpcResponseCallback,
|
|
14
|
-
JsonRpcResponse,
|
|
15
10
|
maybeChainId,
|
|
16
|
-
|
|
17
|
-
JsonRpcSender,
|
|
18
|
-
isJsonRpcProvider
|
|
11
|
+
JsonRpcSender
|
|
19
12
|
} from '@0xsequence/network'
|
|
20
13
|
import { resolveArrayProperties, Signer } from '@0xsequence/wallet'
|
|
21
14
|
import { WalletConfig, WalletState } from '@0xsequence/config'
|
|
22
15
|
import { Relayer } from '@0xsequence/relayer'
|
|
23
16
|
import { Deferrable, shallowCopy, resolveProperties, Forbid } from '@0xsequence/utils'
|
|
24
17
|
import {
|
|
25
|
-
Transaction,
|
|
26
18
|
TransactionRequest,
|
|
27
19
|
TransactionResponse,
|
|
28
|
-
Transactionish,
|
|
29
20
|
SignedTransactions
|
|
30
21
|
} from '@0xsequence/transactions'
|
|
31
22
|
import { WalletRequestHandler } from './transports/wallet-request-handler'
|
|
32
23
|
|
|
33
|
-
export class Web3Provider extends
|
|
24
|
+
export class Web3Provider extends providers.Web3Provider implements JsonRpcHandler {
|
|
34
25
|
static isSequenceProvider(cand: any): cand is Web3Provider {
|
|
35
26
|
return isSequenceProvider(cand)
|
|
36
27
|
}
|
|
@@ -43,7 +34,7 @@ export class Web3Provider extends EthersWeb3Provider implements JsonRpcHandler {
|
|
|
43
34
|
// overridden by passing chainId argument to a specific request
|
|
44
35
|
readonly _defaultChainId?: number
|
|
45
36
|
|
|
46
|
-
constructor(provider: JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike) {
|
|
37
|
+
constructor(provider: providers.JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike) {
|
|
47
38
|
const sender = new JsonRpcSender(provider, maybeChainId(defaultChainId))
|
|
48
39
|
provider = sender
|
|
49
40
|
|
|
@@ -94,11 +85,16 @@ export function isSequenceProvider(provider: any): provider is Web3Provider {
|
|
|
94
85
|
|
|
95
86
|
export class LocalWeb3Provider extends Web3Provider {
|
|
96
87
|
constructor(signer: Signer, networks?: NetworkConfig[]) {
|
|
97
|
-
const walletRequestHandler = new WalletRequestHandler(signer, null, networks || [])
|
|
88
|
+
const walletRequestHandler = new WalletRequestHandler(signer, null, null, networks || [])
|
|
98
89
|
super(walletRequestHandler)
|
|
99
90
|
}
|
|
100
91
|
}
|
|
101
92
|
|
|
93
|
+
// TODO: in the future with ethers v6 we can remove/change this type name
|
|
94
|
+
interface TypedDataSigner {
|
|
95
|
+
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
96
|
+
}
|
|
97
|
+
|
|
102
98
|
export class Web3Signer extends Signer implements TypedDataSigner {
|
|
103
99
|
readonly provider: Web3Provider
|
|
104
100
|
readonly defaultChainId?: number
|
|
@@ -16,8 +16,7 @@ import {
|
|
|
16
16
|
TypedEventEmitter
|
|
17
17
|
} from '../types'
|
|
18
18
|
|
|
19
|
-
import { BigNumber, ethers } from 'ethers'
|
|
20
|
-
import { ExternalProvider } from '@ethersproject/providers'
|
|
19
|
+
import { BigNumber, ethers, providers } from 'ethers'
|
|
21
20
|
|
|
22
21
|
import { NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcResponse } from '@0xsequence/network'
|
|
23
22
|
import { Signer } from '@0xsequence/wallet'
|
|
@@ -27,6 +26,8 @@ import { logger, TypedData } from '@0xsequence/utils'
|
|
|
27
26
|
|
|
28
27
|
import { isWalletUpToDate, prefixEIP191Message } from '../utils'
|
|
29
28
|
|
|
29
|
+
type ExternalProvider = providers.ExternalProvider
|
|
30
|
+
|
|
30
31
|
const SIGNER_READY_TIMEOUT = 10000
|
|
31
32
|
|
|
32
33
|
export interface WalletSignInOptions {
|
|
@@ -44,6 +45,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
44
45
|
private signerReadyCallbacks: Array<() => void> = []
|
|
45
46
|
|
|
46
47
|
private prompter: WalletUserPrompter | null
|
|
48
|
+
private auxDataProvider: AuxDataProvider | null
|
|
47
49
|
private mainnetNetworks: NetworkConfig[]
|
|
48
50
|
private testnetNetworks: NetworkConfig[]
|
|
49
51
|
|
|
@@ -57,11 +59,13 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
57
59
|
constructor(
|
|
58
60
|
signer: Signer | null | undefined,
|
|
59
61
|
prompter: WalletUserPrompter | null,
|
|
62
|
+
auxDataProvider: AuxDataProvider | null,
|
|
60
63
|
mainnetNetworks: NetworkConfig[],
|
|
61
64
|
testnetNetworks: NetworkConfig[] = []
|
|
62
65
|
) {
|
|
63
66
|
this.signer = signer
|
|
64
67
|
this.prompter = prompter
|
|
68
|
+
this.auxDataProvider = auxDataProvider
|
|
65
69
|
this.mainnetNetworks = mainnetNetworks
|
|
66
70
|
this.testnetNetworks = testnetNetworks
|
|
67
71
|
}
|
|
@@ -152,6 +156,13 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
152
156
|
chainId: ethers.utils.hexlify(await this.getChainId())
|
|
153
157
|
}
|
|
154
158
|
|
|
159
|
+
if (options && options.askForEmail) {
|
|
160
|
+
const email = await this.auxDataProvider?.get('email')
|
|
161
|
+
if (email) {
|
|
162
|
+
connectDetails.email = email
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
if (options && options.authorize) {
|
|
156
167
|
// Perform ethauth eip712 request and construct the ConnectDetails response
|
|
157
168
|
// including the auth proof
|
|
@@ -802,6 +813,10 @@ export interface WalletUserPrompter {
|
|
|
802
813
|
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>
|
|
803
814
|
}
|
|
804
815
|
|
|
816
|
+
export interface AuxDataProvider {
|
|
817
|
+
get(key: string): Promise<any>
|
|
818
|
+
}
|
|
819
|
+
|
|
805
820
|
const permittedJsonRpcMethods = [
|
|
806
821
|
'net_version',
|
|
807
822
|
'eth_chainId',
|
package/src/types.ts
CHANGED
|
@@ -156,8 +156,7 @@ export interface ConnectOptions {
|
|
|
156
156
|
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
|
|
157
157
|
authorize?: boolean
|
|
158
158
|
|
|
159
|
-
/**
|
|
160
|
-
// TODO: this feature is currently not used as the wallet does not report emails yet
|
|
159
|
+
/** askForEmail will prompt to give permission to the dapp to access email address */
|
|
161
160
|
askForEmail?: boolean
|
|
162
161
|
|
|
163
162
|
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TypedDataDomain, TypedDataField, TypedDataSigner } from '@ethersproject/abstract-signer'
|
|
1
|
+
import { BigNumberish, BytesLike, TypedDataDomain, TypedDataField } from 'ethers'
|
|
3
2
|
import { WalletContext, ChainIdLike } from '@0xsequence/network'
|
|
4
3
|
import { encodeMessageDigest, TypedData, encodeTypedDataDigest } from '@0xsequence/utils'
|
|
5
4
|
import { DecodedSignature, WalletConfig } from '@0xsequence/config'
|
|
@@ -113,13 +112,7 @@ export class WalletUtils {
|
|
|
113
112
|
walletContext?: WalletContext
|
|
114
113
|
): Promise<WalletConfig> => {
|
|
115
114
|
walletContext = walletContext || (await this.wallet.getWalletContext())
|
|
116
|
-
return recoverWalletConfig(
|
|
117
|
-
address,
|
|
118
|
-
encodeMessageDigest(prefixEIP191Message(message)),
|
|
119
|
-
signature,
|
|
120
|
-
chainId,
|
|
121
|
-
walletContext
|
|
122
|
-
)
|
|
115
|
+
return recoverWalletConfig(address, encodeMessageDigest(prefixEIP191Message(message)), signature, chainId, walletContext)
|
|
123
116
|
}
|
|
124
117
|
|
|
125
118
|
// Recover the WalletConfig from a signature of a typedData object
|
package/src/wallet.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
} from '@0xsequence/network'
|
|
20
20
|
import { WalletConfig, WalletState } from '@0xsequence/config'
|
|
21
21
|
import { logger } from '@0xsequence/utils'
|
|
22
|
-
import { JsonRpcProvider } from '@ethersproject/providers'
|
|
23
22
|
import { Web3Provider, Web3Signer } from './provider'
|
|
24
23
|
import {
|
|
25
24
|
MuxMessageProvider,
|
|
@@ -29,7 +28,7 @@ import {
|
|
|
29
28
|
UnrealMessageProvider
|
|
30
29
|
} from './transports'
|
|
31
30
|
import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, ConnectDetails } from './types'
|
|
32
|
-
import { ethers } from 'ethers'
|
|
31
|
+
import { ethers, providers } from 'ethers'
|
|
33
32
|
import { ExtensionMessageProvider } from './transports/extension-transport/extension-message-provider'
|
|
34
33
|
import { LocalStore, ItemStore, LocalStorage } from './utils'
|
|
35
34
|
import { WalletUtils } from './utils/index'
|
|
@@ -483,7 +482,7 @@ export class Wallet implements WalletProvider {
|
|
|
483
482
|
let provider: Web3Provider
|
|
484
483
|
|
|
485
484
|
// network.provider may be set by the ProviderConfig override
|
|
486
|
-
const rpcProvider = network.provider ? network.provider : new JsonRpcProvider(network.rpcUrl, network.chainId)
|
|
485
|
+
const rpcProvider = network.provider ? network.provider : new providers.JsonRpcProvider(network.rpcUrl, network.chainId)
|
|
487
486
|
|
|
488
487
|
if (network.isDefaultChain) {
|
|
489
488
|
// communicating with defaultChain will prioritize the wallet message transport
|