@0xsequence/provider 1.10.15 → 2.0.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 +656 -648
- package/dist/0xsequence-provider.cjs.prod.js +656 -648
- package/dist/0xsequence-provider.esm.js +660 -652
- package/dist/declarations/src/client.d.ts +7 -3
- package/dist/declarations/src/provider.d.ts +31 -22
- package/dist/declarations/src/signer.d.ts +15 -14
- package/dist/declarations/src/transports/base-provider-transport.d.ts +6 -2
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +6 -2
- package/dist/declarations/src/transports/mux-transport/mux-message-provider.d.ts +5 -2
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +7 -6
- package/dist/declarations/src/types.d.ts +6 -11
- package/dist/declarations/src/utils/index.d.ts +3 -3
- package/dist/declarations/src/utils.d.ts +7 -7
- package/package.json +12 -12
- package/src/client.ts +29 -51
- package/src/eip191exceptions.ts +2 -2
- package/src/extended.ts +5 -5
- package/src/init.ts +9 -10
- package/src/provider.ts +112 -66
- package/src/signer.ts +38 -43
- package/src/transactions.ts +4 -4
- package/src/transports/base-provider-transport.ts +19 -23
- package/src/transports/base-wallet-transport.ts +22 -13
- package/src/transports/mux-transport/mux-message-provider.ts +5 -6
- package/src/transports/proxy-transport/proxy-message-provider.ts +5 -2
- package/src/transports/wallet-request-handler.ts +91 -130
- package/src/transports/window-transport/window-message-handler.ts +15 -3
- package/src/transports/window-transport/window-message-provider.ts +1 -1
- package/src/types.ts +8 -11
- package/src/utils/index.ts +4 -4
- package/src/utils.ts +16 -18
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NetworkConfig } from '@0xsequence/network';
|
|
2
2
|
import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession } from "./index.js";
|
|
3
3
|
import { commons } from '@0xsequence/core';
|
|
4
4
|
import { TypedData } from '@0xsequence/utils';
|
|
@@ -75,14 +75,18 @@ export declare class SequenceClient {
|
|
|
75
75
|
getAddress(): string;
|
|
76
76
|
connect(options: ConnectOptions): Promise<ConnectDetails>;
|
|
77
77
|
disconnect(): Promise<void>;
|
|
78
|
-
|
|
78
|
+
request(request: {
|
|
79
|
+
method: string;
|
|
80
|
+
params?: any[];
|
|
81
|
+
chainId?: number;
|
|
82
|
+
}): Promise<any>;
|
|
79
83
|
getNetworks(pull?: boolean): Promise<NetworkConfig[]>;
|
|
80
84
|
private signMethod;
|
|
81
85
|
private signTypedDataMethod;
|
|
82
86
|
private mapSignMethod;
|
|
83
87
|
signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
84
88
|
signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
|
|
85
|
-
sendTransaction(tx: ethers.
|
|
89
|
+
sendTransaction(tx: ethers.TransactionRequest[] | ethers.TransactionRequest, options?: OptionalChainId): Promise<string>;
|
|
86
90
|
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
87
91
|
getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config>;
|
|
88
92
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { SequenceClient } from "./client.js";
|
|
3
|
-
import { ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
4
|
-
import { ConnectDetails, ConnectOptions,
|
|
3
|
+
import { EIP1193Provider, ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
4
|
+
import { ConnectDetails, ConnectOptions, 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,15 +29,21 @@ export interface ISequenceProvider {
|
|
|
29
29
|
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
30
30
|
utils: WalletUtils;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
declare const EIP1193EventTypes: readonly ["connect", "disconnect", "chainChanged", "accountsChanged"];
|
|
33
|
+
type EIP1193EventType = (typeof EIP1193EventTypes)[number];
|
|
34
|
+
export declare class SequenceProvider extends ethers.AbstractProvider implements ISequenceProvider, EIP1193Provider {
|
|
33
35
|
readonly client: SequenceClient;
|
|
34
36
|
private readonly providerFor;
|
|
35
37
|
readonly networks: NetworkConfig[];
|
|
38
|
+
readonly options?: ethers.AbstractProviderOptions | undefined;
|
|
36
39
|
private readonly singleNetworkProviders;
|
|
37
40
|
readonly _isSequenceProvider = true;
|
|
38
41
|
readonly utils: WalletUtils;
|
|
39
42
|
readonly signer: SequenceSigner;
|
|
40
|
-
|
|
43
|
+
readonly eip1193EventListeners: Map<"connect" | "disconnect" | "accountsChanged" | "chainChanged", Set<ethers.Listener>>;
|
|
44
|
+
constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.JsonRpcProvider, networks?: NetworkConfig[], options?: ethers.AbstractProviderOptions | undefined);
|
|
45
|
+
on(event: ethers.ProviderEvent | EIP1193EventType, listener: ethers.Listener): Promise<this>;
|
|
46
|
+
off(event: ethers.ProviderEvent | EIP1193EventType, listener?: ethers.Listener | undefined): Promise<this>;
|
|
41
47
|
getSigner(): SequenceSigner;
|
|
42
48
|
getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
|
|
43
49
|
getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
|
|
@@ -76,30 +82,32 @@ export declare class SequenceProvider extends ethers.providers.BaseProvider impl
|
|
|
76
82
|
* This returns a subprovider, this is a regular non-sequence provider that
|
|
77
83
|
* can be used to fulfill read only requests on a given network.
|
|
78
84
|
*/
|
|
79
|
-
_getSubprovider(chainId?: ChainIdLike): Promise<ethers.
|
|
85
|
+
_getSubprovider(chainId?: ChainIdLike): Promise<ethers.JsonRpcProvider>;
|
|
86
|
+
_perform(req: ethers.PerformActionRequest): Promise<any>;
|
|
80
87
|
perform(method: string, params: any): Promise<any>;
|
|
81
88
|
send(method: string, params: any): Promise<any>;
|
|
82
89
|
request(request: {
|
|
83
90
|
method: string;
|
|
84
91
|
params?: any[] | undefined;
|
|
85
92
|
}): Promise<any>;
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
_detectNetwork(): Promise<ethers.Network>;
|
|
94
|
+
detectNetwork(): Promise<ethers.Network>;
|
|
95
|
+
waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number, optionals?: OptionalChainIdLike): Promise<ethers.TransactionReceipt | null>;
|
|
88
96
|
getBlockNumber(optionals?: OptionalChainIdLike): Promise<number>;
|
|
89
|
-
|
|
90
|
-
getBalance(addressOrName: string | Promise<string>, blockTag?: ethers.
|
|
91
|
-
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: ethers.
|
|
92
|
-
getCode(addressOrName: string | Promise<string>, blockTag?: ethers.
|
|
93
|
-
|
|
94
|
-
call(transaction: ethers.
|
|
95
|
-
estimateGas(transaction: ethers.
|
|
96
|
-
getBlock(blockHashOrBlockTag: ethers.
|
|
97
|
-
getTransaction(transactionHash: string
|
|
98
|
-
getLogs(filter: ethers.
|
|
97
|
+
getFeeData(optionals?: OptionalChainIdLike): Promise<ethers.FeeData>;
|
|
98
|
+
getBalance(addressOrName: string | Promise<string>, blockTag?: ethers.BlockTag, optionals?: OptionalChainIdLike): Promise<bigint>;
|
|
99
|
+
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: ethers.BlockTag, optionals?: OptionalChainIdLike): Promise<number>;
|
|
100
|
+
getCode(addressOrName: string | Promise<string>, blockTag?: ethers.BlockTag, optionals?: OptionalChainIdLike): Promise<string>;
|
|
101
|
+
getStorage(addressOrName: string | Promise<string>, position: ethers.BigNumberish, blockTag?: ethers.BlockTag, optionals?: OptionalChainIdLike): Promise<string>;
|
|
102
|
+
call(transaction: ethers.TransactionRequest, optionals?: OptionalChainIdLike): Promise<string>;
|
|
103
|
+
estimateGas(transaction: ethers.TransactionRequest, optionals?: OptionalChainIdLike): Promise<bigint>;
|
|
104
|
+
getBlock(blockHashOrBlockTag: ethers.BlockTag | string, prefetchTxs?: boolean, optionals?: OptionalChainIdLike): Promise<ethers.Block | null>;
|
|
105
|
+
getTransaction(transactionHash: string, optionals?: OptionalChainIdLike): Promise<ethers.TransactionResponse | null>;
|
|
106
|
+
getLogs(filter: ethers.Filter, optionals?: OptionalChainIdLike): Promise<ethers.Log[]>;
|
|
99
107
|
supportsENS(): Promise<boolean>;
|
|
100
|
-
getResolver(name: string): Promise<ethers.
|
|
101
|
-
resolveName(name: string
|
|
102
|
-
lookupAddress(address: string
|
|
108
|
+
getResolver(name: string): Promise<ethers.EnsResolver | null>;
|
|
109
|
+
resolveName(name: string): Promise<string | null>;
|
|
110
|
+
lookupAddress(address: string): Promise<string | null>;
|
|
103
111
|
getAvatar(nameOrAddress: string): Promise<string | null>;
|
|
104
112
|
static is: (provider: any) => provider is SequenceProvider;
|
|
105
113
|
}
|
|
@@ -115,11 +123,11 @@ export declare class SequenceProvider extends ethers.providers.BaseProvider impl
|
|
|
115
123
|
export declare class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
116
124
|
readonly chainId: ChainIdLike;
|
|
117
125
|
readonly _isSingleNetworkSequenceProvider = true;
|
|
118
|
-
constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.
|
|
126
|
+
constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.JsonRpcProvider, chainId: ChainIdLike, options?: ethers.AbstractProviderOptions);
|
|
119
127
|
private _useChainId;
|
|
120
128
|
protected useChainId(chainId?: ChainIdLike): Promise<number>;
|
|
121
129
|
getChainId(): number;
|
|
122
|
-
getNetwork(): Promise<
|
|
130
|
+
getNetwork(): Promise<ethers.Network>;
|
|
123
131
|
/**
|
|
124
132
|
* Override getProvider and getSigner so they always use `useChainId`
|
|
125
133
|
* this way they can't return providers and signers that can switch networks,
|
|
@@ -130,3 +138,4 @@ export declare class SingleNetworkSequenceProvider extends SequenceProvider {
|
|
|
130
138
|
setDefaultChainId(_chainId: ChainIdLike): void;
|
|
131
139
|
static is(cand: any): cand is SingleNetworkSequenceProvider;
|
|
132
140
|
}
|
|
141
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import { commons } from '@0xsequence/core';
|
|
|
5
5
|
import { ChainIdLike, NetworkConfig } from '@0xsequence/network';
|
|
6
6
|
import { WalletUtils } from "./utils/index.js";
|
|
7
7
|
import { OptionalChainIdLike, OptionalEIP6492 } from "./types.js";
|
|
8
|
-
export interface ISequenceSigner extends ethers.Signer {
|
|
8
|
+
export interface ISequenceSigner extends Omit<ethers.Signer, 'connect'> {
|
|
9
9
|
getProvider(): SequenceProvider;
|
|
10
10
|
getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
|
|
11
11
|
getProvider(chainId?: ChainIdLike): SequenceProvider | SingleNetworkSequenceProvider;
|
|
@@ -14,21 +14,21 @@ export interface ISequenceSigner extends ethers.Signer {
|
|
|
14
14
|
getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
|
|
15
15
|
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
16
16
|
getNetworks(): Promise<NetworkConfig[]>;
|
|
17
|
+
connect: (provider: SequenceProvider) => SequenceSigner;
|
|
17
18
|
signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
|
|
18
19
|
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
|
|
19
|
-
sendTransaction(transaction: ethers.
|
|
20
|
+
sendTransaction(transaction: ethers.TransactionRequest[] | ethers.TransactionRequest, options?: OptionalChainIdLike): Promise<commons.transaction.TransactionResponse>;
|
|
20
21
|
utils: WalletUtils;
|
|
21
22
|
}
|
|
22
23
|
export declare class SequenceSigner implements ISequenceSigner {
|
|
23
24
|
client: SequenceClient;
|
|
24
25
|
provider: SequenceProvider;
|
|
25
26
|
private readonly singleNetworkSigners;
|
|
26
|
-
readonly _isSigner: boolean;
|
|
27
27
|
readonly _isSequenceSigner: boolean;
|
|
28
28
|
get utils(): WalletUtils;
|
|
29
29
|
constructor(client: SequenceClient, provider: SequenceProvider);
|
|
30
30
|
getAddress(): Promise<string>;
|
|
31
|
-
connect(provider: ethers.
|
|
31
|
+
connect(provider: ethers.Provider): SequenceSigner;
|
|
32
32
|
getSigner(): SequenceSigner;
|
|
33
33
|
getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
|
|
34
34
|
getSigner(chainId?: ChainIdLike): SingleNetworkSequenceSigner | SequenceSigner;
|
|
@@ -43,21 +43,22 @@ export declare class SequenceSigner implements ISequenceSigner {
|
|
|
43
43
|
getProvider(): SequenceProvider;
|
|
44
44
|
getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
|
|
45
45
|
getProvider(chainId?: ChainIdLike): SingleNetworkSequenceProvider | SequenceProvider;
|
|
46
|
-
sendTransaction(transaction: ethers.
|
|
46
|
+
sendTransaction(transaction: ethers.TransactionRequest[] | ethers.TransactionRequest, options?: OptionalChainIdLike): Promise<ethers.TransactionResponse>;
|
|
47
47
|
getWalletConfig(chainId?: ChainIdLike | undefined): Promise<commons.config.Config>;
|
|
48
48
|
getNetworks(): Promise<NetworkConfig[]>;
|
|
49
|
-
getBalance(blockTag?: ethers.
|
|
50
|
-
estimateGas(transaction: ethers.
|
|
51
|
-
call(transaction: ethers.
|
|
49
|
+
getBalance(blockTag?: ethers.BlockTag | undefined, optionals?: OptionalChainIdLike): Promise<bigint>;
|
|
50
|
+
estimateGas(transaction: ethers.TransactionRequest, optionals?: OptionalChainIdLike): Promise<bigint>;
|
|
51
|
+
call(transaction: ethers.TransactionRequest, optionals?: OptionalChainIdLike): Promise<string>;
|
|
52
52
|
getChainId(): Promise<number>;
|
|
53
|
-
|
|
54
|
-
getFeeData(optionals?: OptionalChainIdLike): Promise<ethers.providers.FeeData>;
|
|
53
|
+
getFeeData(optionals?: OptionalChainIdLike): Promise<ethers.FeeData>;
|
|
55
54
|
resolveName(name: string): Promise<string>;
|
|
56
55
|
_checkProvider(_operation?: string | undefined): void;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
getNonce(_blockTag?: ethers.BlockTag): Promise<number>;
|
|
57
|
+
populateCall(_transaction: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>>;
|
|
58
|
+
populateTransaction(_transaction: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>>;
|
|
59
|
+
checkTransaction(_transaction: ethers.TransactionRequest): ethers.TransactionRequest;
|
|
60
|
+
getTransactionCount(_blockTag?: ethers.BlockTag): Promise<number>;
|
|
61
|
+
signTransaction(_transaction: commons.transaction.Transactionish): Promise<string>;
|
|
61
62
|
static is(cand: any): cand is SequenceSigner;
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProviderTransport, ProviderMessage, ProviderMessageRequest, ProviderEventTypes, ProviderMessageResponse, ProviderMessageResponseCallback, OpenState, OpenWalletIntent, ConnectDetails, WalletSession, ProviderRpcError, InitState, TypedEventEmitter } from "../types.js";
|
|
2
|
-
import { NetworkConfig
|
|
2
|
+
import { NetworkConfig } from '@0xsequence/network';
|
|
3
3
|
import { commons } from '@0xsequence/core';
|
|
4
4
|
export declare const PROVIDER_OPEN_TIMEOUT = 30000;
|
|
5
5
|
export declare const nextMessageIdx: () => number;
|
|
@@ -31,7 +31,11 @@ export declare abstract class BaseProviderTransport implements ProviderTransport
|
|
|
31
31
|
closeWallet(): void;
|
|
32
32
|
isOpened(): boolean;
|
|
33
33
|
isConnected(): boolean;
|
|
34
|
-
|
|
34
|
+
request(request: {
|
|
35
|
+
method: string;
|
|
36
|
+
params?: any[];
|
|
37
|
+
chainId?: number;
|
|
38
|
+
}): Promise<any>;
|
|
35
39
|
handleMessage(message: ProviderMessage<any>): void;
|
|
36
40
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
37
41
|
sendMessage(message: ProviderMessage<any>): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletTransport, ProviderMessage, ProviderMessageRequest, ProviderMessageResponse, ProviderRpcError, InitState, ConnectDetails, WalletSession, TransportSession } from "../types.js";
|
|
2
2
|
import { WalletRequestHandler } from "./wallet-request-handler.js";
|
|
3
|
-
import { NetworkConfig
|
|
3
|
+
import { NetworkConfig } from '@0xsequence/network';
|
|
4
4
|
import { commons } from '@0xsequence/core';
|
|
5
5
|
export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
6
6
|
protected walletRequestHandler: WalletRequestHandler;
|
|
@@ -14,7 +14,11 @@ export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
|
14
14
|
get registered(): boolean;
|
|
15
15
|
register(): void;
|
|
16
16
|
unregister(): void;
|
|
17
|
-
|
|
17
|
+
request(request: {
|
|
18
|
+
method: string;
|
|
19
|
+
params?: any[];
|
|
20
|
+
chainId?: number;
|
|
21
|
+
}): Promise<any>;
|
|
18
22
|
handleMessage: (message: ProviderMessage<any>) => Promise<void>;
|
|
19
23
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
20
24
|
sendMessage(message: ProviderMessage<any>): void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ProviderMessage, ProviderTransport, ProviderEventTypes, ProviderMessageRequest, ProviderMessageResponse, WalletSession, OpenWalletIntent, ConnectDetails } from "../../types.js";
|
|
2
|
-
import { JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
3
2
|
import { ProxyMessageChannelPort } from "../proxy-transport/index.js";
|
|
4
3
|
import { Runtime } from 'webextension-polyfill';
|
|
5
4
|
export type MuxTransportTemplate = {
|
|
@@ -35,7 +34,11 @@ export declare class MuxMessageProvider implements ProviderTransport {
|
|
|
35
34
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
36
35
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
37
36
|
emit<K extends keyof ProviderEventTypes>(event: K, ...args: Parameters<ProviderEventTypes[K]>): boolean;
|
|
38
|
-
|
|
37
|
+
request(request: {
|
|
38
|
+
method: string;
|
|
39
|
+
params?: any[];
|
|
40
|
+
chainId?: number;
|
|
41
|
+
}): Promise<any>;
|
|
39
42
|
sendMessage(message: ProviderMessage<any>): void;
|
|
40
43
|
sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
41
44
|
handleMessage(message: ProviderMessage<any>): void;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Account } from '@0xsequence/account';
|
|
2
2
|
import { commons } from '@0xsequence/core';
|
|
3
|
-
import { ChainIdLike,
|
|
4
|
-
import { providers } from 'ethers';
|
|
3
|
+
import { ChainIdLike, NetworkConfig, EIP1193Provider } from '@0xsequence/network';
|
|
5
4
|
import { ConnectDetails, ConnectOptions, MessageToSign, NetworkedConnectOptions, OpenWalletIntent, PromptConnectDetails, ProviderEventTypes, ProviderMessageRequest, ProviderMessageRequestHandler, ProviderMessageResponse, ProviderRpcError, WalletSession } from "../types.js";
|
|
6
|
-
type ExternalProvider = providers.ExternalProvider;
|
|
7
5
|
export interface WalletSignInOptions {
|
|
8
6
|
connect?: boolean;
|
|
9
7
|
defaultNetworkId?: number;
|
|
10
8
|
}
|
|
11
|
-
export declare class WalletRequestHandler implements
|
|
9
|
+
export declare class WalletRequestHandler implements EIP1193Provider, ProviderMessageRequestHandler {
|
|
12
10
|
private account;
|
|
13
11
|
private signerReadyCallbacks;
|
|
14
12
|
private prompter;
|
|
@@ -26,7 +24,11 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
26
24
|
connect(options?: NetworkedConnectOptions): Promise<ConnectDetails>;
|
|
27
25
|
promptConnect: (options?: NetworkedConnectOptions) => Promise<ConnectDetails>;
|
|
28
26
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
29
|
-
|
|
27
|
+
request(request: {
|
|
28
|
+
method: string;
|
|
29
|
+
params?: any[];
|
|
30
|
+
chainId?: number;
|
|
31
|
+
}): Promise<any>;
|
|
30
32
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
31
33
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
32
34
|
getAddress(): Promise<string>;
|
|
@@ -58,4 +60,3 @@ export interface WalletUserPrompter {
|
|
|
58
60
|
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>;
|
|
59
61
|
promptChangeNetwork(chainId: number): Promise<boolean>;
|
|
60
62
|
}
|
|
61
|
-
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth';
|
|
2
2
|
import { commons } from '@0xsequence/core';
|
|
3
|
-
import { ChainIdLike,
|
|
3
|
+
import { ChainIdLike, EIP1193Provider, JsonRpcRequest, JsonRpcResponse, NetworkConfig, JsonRpcErrorPayload } from '@0xsequence/network';
|
|
4
4
|
import { TypedData } from '@0xsequence/utils';
|
|
5
|
-
export interface ProviderTransport extends
|
|
5
|
+
export interface ProviderTransport extends EIP1193Provider, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
6
6
|
register(): void;
|
|
7
7
|
unregister(): void;
|
|
8
8
|
openWallet(path?: string, intent?: OpenWalletIntent, networkId?: string | number): void;
|
|
@@ -16,7 +16,7 @@ export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransp
|
|
|
16
16
|
waitUntilConnected(): Promise<ConnectDetails>;
|
|
17
17
|
}
|
|
18
18
|
export declare function isProviderTransport(transport: any): transport is ProviderTransport;
|
|
19
|
-
export interface WalletTransport extends
|
|
19
|
+
export interface WalletTransport extends EIP1193Provider, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
20
20
|
register(): void;
|
|
21
21
|
unregister(): void;
|
|
22
22
|
notifyOpen(openInfo: {
|
|
@@ -37,11 +37,12 @@ export interface ProviderMessage<T> {
|
|
|
37
37
|
data: T;
|
|
38
38
|
chainId?: number;
|
|
39
39
|
origin?: string;
|
|
40
|
+
clientVersion: string;
|
|
40
41
|
}
|
|
41
42
|
export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>;
|
|
42
|
-
export type ProviderMessageResponse = ProviderMessage<JsonRpcResponse>;
|
|
43
|
+
export type ProviderMessageResponse = ProviderMessage<JsonRpcResponse | any>;
|
|
43
44
|
export type ProviderMessageResponseCallback = (error?: ProviderRpcError, response?: ProviderMessageResponse) => void;
|
|
44
|
-
export type ProviderRpcError =
|
|
45
|
+
export type ProviderRpcError = JsonRpcErrorPayload;
|
|
45
46
|
export interface ProviderMessageRequestHandler {
|
|
46
47
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
47
48
|
}
|
|
@@ -257,10 +258,4 @@ export type OptionalChainId = {
|
|
|
257
258
|
export type OptionalEIP6492 = {
|
|
258
259
|
eip6492?: boolean;
|
|
259
260
|
} | undefined;
|
|
260
|
-
export interface EIP1193Provider {
|
|
261
|
-
request: (request: {
|
|
262
|
-
method: string;
|
|
263
|
-
params?: Array<any>;
|
|
264
|
-
}) => Promise<any>;
|
|
265
|
-
}
|
|
266
261
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
2
|
import { ChainIdLike } from '@0xsequence/network';
|
|
3
3
|
import { TypedData } from '@0xsequence/utils';
|
|
4
4
|
import { SequenceSigner } from "../signer.js";
|
|
@@ -10,8 +10,8 @@ import { SequenceSigner } from "../signer.js";
|
|
|
10
10
|
export declare class WalletUtils {
|
|
11
11
|
signer: SequenceSigner;
|
|
12
12
|
constructor(signer: SequenceSigner);
|
|
13
|
-
signMessage(message: BytesLike, chainId?: ChainIdLike, eip6492?: boolean): Promise<string>;
|
|
14
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, eip6492?: boolean): Promise<string>;
|
|
13
|
+
signMessage(message: ethers.BytesLike, chainId?: ChainIdLike, eip6492?: boolean): Promise<string>;
|
|
14
|
+
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, eip6492?: boolean): Promise<string>;
|
|
15
15
|
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number): Promise<boolean>;
|
|
16
16
|
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number): Promise<boolean>;
|
|
17
17
|
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number): Promise<boolean>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ethers
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
2
|
import { AccountStatus } from '@0xsequence/account';
|
|
3
3
|
import { TypedData } from '@0xsequence/utils';
|
|
4
|
-
export declare const messageToBytes: (message: BytesLike) => Uint8Array;
|
|
5
|
-
export declare const prefixEIP191Message: (message: BytesLike) => Uint8Array;
|
|
4
|
+
export declare const messageToBytes: (message: ethers.BytesLike) => Uint8Array;
|
|
5
|
+
export declare const prefixEIP191Message: (message: ethers.BytesLike) => Uint8Array;
|
|
6
6
|
export declare const trimEIP191Prefix: (prefixedMessage: Uint8Array) => Uint8Array;
|
|
7
|
-
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: ethers.
|
|
8
|
-
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: ethers.
|
|
9
|
-
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: ethers.
|
|
7
|
+
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: ethers.Provider) => Promise<boolean>;
|
|
8
|
+
export declare const isValidMessageSignature: (address: string, message: string | Uint8Array, signature: string, provider: ethers.Provider) => Promise<boolean>;
|
|
9
|
+
export declare const isValidTypedDataSignature: (address: string, typedData: TypedData, signature: string, provider: ethers.Provider) => Promise<boolean>;
|
|
10
10
|
export declare const isBrowserExtension: () => boolean;
|
|
11
11
|
export declare const isUnityPlugin: () => boolean;
|
|
12
12
|
export declare const isWalletUpToDate: (status: AccountStatus) => boolean;
|
|
@@ -34,4 +34,4 @@ export declare class LocalStorage implements ItemStore {
|
|
|
34
34
|
onItemChange(key: string, cb: (value: string | null) => void): () => void;
|
|
35
35
|
}
|
|
36
36
|
export declare function useBestStore(): ItemStore;
|
|
37
|
-
export declare function resolveArrayProperties<T>(object: Readonly<
|
|
37
|
+
export declare function resolveArrayProperties<T>(object: Readonly<T> | Readonly<T>[]): Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -12,22 +12,22 @@
|
|
|
12
12
|
"@databeat/tracker": "^0.9.1",
|
|
13
13
|
"eventemitter2": "^6.4.5",
|
|
14
14
|
"webextension-polyfill": "^0.10.0",
|
|
15
|
-
"@0xsequence/abi": "
|
|
16
|
-
"@0xsequence/account": "
|
|
17
|
-
"@0xsequence/auth": "
|
|
18
|
-
"@0xsequence/core": "
|
|
19
|
-
"@0xsequence/migration": "
|
|
20
|
-
"@0xsequence/network": "
|
|
21
|
-
"@0xsequence/relayer": "
|
|
22
|
-
"@0xsequence/utils": "
|
|
23
|
-
"@0xsequence/wallet": "
|
|
15
|
+
"@0xsequence/abi": "2.0.0",
|
|
16
|
+
"@0xsequence/account": "2.0.0",
|
|
17
|
+
"@0xsequence/auth": "2.0.0",
|
|
18
|
+
"@0xsequence/core": "2.0.0",
|
|
19
|
+
"@0xsequence/migration": "2.0.0",
|
|
20
|
+
"@0xsequence/network": "2.0.0",
|
|
21
|
+
"@0xsequence/relayer": "2.0.0",
|
|
22
|
+
"@0xsequence/utils": "2.0.0",
|
|
23
|
+
"@0xsequence/wallet": "2.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"ethers": ">=
|
|
26
|
+
"ethers": ">=6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/webextension-polyfill": "^0.10.0",
|
|
30
|
-
"ethers": "^
|
|
30
|
+
"ethers": "^6.13.0",
|
|
31
31
|
"hardhat": "^2.20.1"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NetworkConfig } from '@0xsequence/network'
|
|
2
2
|
import {
|
|
3
3
|
ConnectDetails,
|
|
4
4
|
ConnectOptions,
|
|
@@ -15,14 +15,12 @@ import {
|
|
|
15
15
|
isProviderTransport,
|
|
16
16
|
messageToBytes
|
|
17
17
|
} from '.'
|
|
18
|
-
import { commons } from '@0xsequence/core'
|
|
18
|
+
import { commons, VERSION } from '@0xsequence/core'
|
|
19
19
|
import { TypedData } from '@0xsequence/utils'
|
|
20
20
|
import { toExtended } from './extended'
|
|
21
21
|
import { Analytics, setupAnalytics } from './analytics'
|
|
22
22
|
import { ethers } from 'ethers'
|
|
23
23
|
|
|
24
|
-
import packageJson from '../package.json'
|
|
25
|
-
|
|
26
24
|
/**
|
|
27
25
|
* This session class is meant to persist the state of the wallet connection
|
|
28
26
|
* whitin the dapp. This enables the client to retain the wallet address (and some more)
|
|
@@ -166,7 +164,7 @@ export class SequenceClient {
|
|
|
166
164
|
})
|
|
167
165
|
|
|
168
166
|
this.transport.on('connect', (response: ConnectDetails) => {
|
|
169
|
-
const chainIdHex = ethers.
|
|
167
|
+
const chainIdHex = ethers.toQuantity(this.getChainId())
|
|
170
168
|
this.callbacks.connect?.forEach(cb =>
|
|
171
169
|
cb({
|
|
172
170
|
...response,
|
|
@@ -204,7 +202,7 @@ export class SequenceClient {
|
|
|
204
202
|
// We don't listen for the transport chainChanged event
|
|
205
203
|
// instead we handle it locally, so we listen for changes in the store
|
|
206
204
|
this.defaultChainId.onDefaultChainIdChanged((chainId: number) => {
|
|
207
|
-
const chainIdHex = ethers.
|
|
205
|
+
const chainIdHex = ethers.toQuantity(chainId)
|
|
208
206
|
this.callbacks.chainChanged?.forEach(cb => cb(chainIdHex))
|
|
209
207
|
})
|
|
210
208
|
|
|
@@ -337,7 +335,7 @@ export class SequenceClient {
|
|
|
337
335
|
|
|
338
336
|
await this.openWallet(undefined, {
|
|
339
337
|
type: 'connect',
|
|
340
|
-
options: { ...options, networkId: this.getChainId(), clientVersion:
|
|
338
|
+
options: { ...options, networkId: this.getChainId(), clientVersion: VERSION }
|
|
341
339
|
})
|
|
342
340
|
|
|
343
341
|
const connectDetails = await this.transport.waitUntilConnected().catch((error): ConnectDetails => {
|
|
@@ -351,7 +349,7 @@ export class SequenceClient {
|
|
|
351
349
|
// Normalize chainId into a decimal string
|
|
352
350
|
// TODO: Remove this once wallet-webapp returns chainId as a string
|
|
353
351
|
if (connectDetails.chainId) {
|
|
354
|
-
connectDetails.chainId =
|
|
352
|
+
connectDetails.chainId = BigInt(connectDetails.chainId).toString()
|
|
355
353
|
}
|
|
356
354
|
|
|
357
355
|
if (connectDetails.connected) {
|
|
@@ -381,40 +379,20 @@ export class SequenceClient {
|
|
|
381
379
|
|
|
382
380
|
// Higher level API
|
|
383
381
|
|
|
384
|
-
|
|
385
|
-
// but transport uses it instead of send, so we wrap it
|
|
386
|
-
send(request: JsonRpcRequest, chainId?: number): Promise<any> {
|
|
382
|
+
async request(request: { method: string; params?: any[]; chainId?: number }): Promise<any> {
|
|
387
383
|
// Internally when sending requests we use `legacy_sign`
|
|
388
384
|
// to avoid the default EIP6492 behavior overriding an explicit
|
|
389
385
|
// "legacy sign" request, so we map the method here.
|
|
390
386
|
request.method = this.mapSignMethod(request.method)
|
|
391
387
|
|
|
392
|
-
return
|
|
393
|
-
this.transport.sendAsync(
|
|
394
|
-
request,
|
|
395
|
-
(error, response) => {
|
|
396
|
-
if (error) {
|
|
397
|
-
reject(error)
|
|
398
|
-
} else if (response === undefined) {
|
|
399
|
-
reject(new Error(`Got undefined response for request: ${request}`))
|
|
400
|
-
} else if (typeof response === 'object' && response.error) {
|
|
401
|
-
reject(response.error)
|
|
402
|
-
} else if (typeof response === 'object' && response.result) {
|
|
403
|
-
resolve(response.result)
|
|
404
|
-
} else {
|
|
405
|
-
reject(new Error(`Got invalid response for request: ${request}`))
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
chainId || this.getChainId()
|
|
409
|
-
)
|
|
410
|
-
})
|
|
388
|
+
return this.transport.request(request)
|
|
411
389
|
}
|
|
412
390
|
|
|
413
391
|
async getNetworks(pull?: boolean): Promise<NetworkConfig[]> {
|
|
414
392
|
const connectedSession = this.session.connectedSession()
|
|
415
393
|
|
|
416
394
|
if (pull) {
|
|
417
|
-
connectedSession.networks = await this.
|
|
395
|
+
connectedSession.networks = await this.request({ method: 'sequence_getNetworks' })
|
|
418
396
|
this.session.setSession(connectedSession)
|
|
419
397
|
}
|
|
420
398
|
|
|
@@ -474,11 +452,14 @@ export class SequenceClient {
|
|
|
474
452
|
|
|
475
453
|
this.analytics?.track({ event: 'SIGN_MESSAGE_REQUEST', props: { chainId: `${options?.chainId || this.getChainId()}` } })
|
|
476
454
|
|
|
477
|
-
|
|
478
|
-
message = ethers.utils.hexlify(messageToBytes(message))
|
|
455
|
+
message = ethers.hexlify(messageToBytes(message))
|
|
479
456
|
|
|
480
457
|
// Address is ignored by the wallet webapp
|
|
481
|
-
return this.
|
|
458
|
+
return this.request({
|
|
459
|
+
method,
|
|
460
|
+
params: [message, this.getAddress()],
|
|
461
|
+
chainId: options?.chainId
|
|
462
|
+
})
|
|
482
463
|
}
|
|
483
464
|
|
|
484
465
|
async signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string> {
|
|
@@ -486,7 +467,7 @@ export class SequenceClient {
|
|
|
486
467
|
|
|
487
468
|
// TODO: Stop using ethers for this, this is the only place where we use it
|
|
488
469
|
// and it makes the client depend on ethers.
|
|
489
|
-
const encoded = ethers.
|
|
470
|
+
const encoded = ethers.TypedDataEncoder.getPayload(typedData.domain, typedData.types, typedData.message)
|
|
490
471
|
|
|
491
472
|
// The sign typed data will use one of the following chainIds, in order:
|
|
492
473
|
// - The one provided in the options
|
|
@@ -495,36 +476,33 @@ export class SequenceClient {
|
|
|
495
476
|
|
|
496
477
|
this.analytics?.track({ event: 'SIGN_TYPED_DATA_REQUEST', props: { chainId: `${options?.chainId || this.getChainId()}` } })
|
|
497
478
|
|
|
498
|
-
return this.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
)
|
|
479
|
+
return this.request({
|
|
480
|
+
method,
|
|
481
|
+
params: [this.getAddress(), encoded],
|
|
482
|
+
chainId: options?.chainId || (typedData.domain.chainId && Number(typedData.domain.chainId)) || this.getChainId()
|
|
483
|
+
})
|
|
504
484
|
}
|
|
505
485
|
|
|
506
|
-
async sendTransaction(
|
|
507
|
-
tx: ethers.providers.TransactionRequest[] | ethers.providers.TransactionRequest,
|
|
508
|
-
options?: OptionalChainId
|
|
509
|
-
): Promise<string> {
|
|
486
|
+
async sendTransaction(tx: ethers.TransactionRequest[] | ethers.TransactionRequest, options?: OptionalChainId): Promise<string> {
|
|
510
487
|
const sequenceTxs = Array.isArray(tx) ? tx : [tx]
|
|
511
488
|
const extendedTxs = toExtended(sequenceTxs)
|
|
512
489
|
|
|
513
490
|
this.analytics?.track({ event: 'SEND_TRANSACTION_REQUEST', props: { chainId: `${options?.chainId || this.getChainId()}` } })
|
|
514
491
|
|
|
515
|
-
return this.
|
|
492
|
+
return this.request({ method: 'eth_sendTransaction', params: [extendedTxs], chainId: options?.chainId })
|
|
516
493
|
}
|
|
517
494
|
|
|
518
495
|
async getWalletContext(): Promise<commons.context.VersionedContext> {
|
|
519
|
-
return this.
|
|
496
|
+
return this.request({ method: 'sequence_getWalletContext' })
|
|
520
497
|
}
|
|
521
498
|
|
|
522
499
|
async getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config> {
|
|
523
500
|
// NOTICE: sequence_getWalletConfig sends the chainId as a param
|
|
524
|
-
const res = await this.
|
|
525
|
-
|
|
526
|
-
options?.chainId
|
|
527
|
-
|
|
501
|
+
const res = await this.request({
|
|
502
|
+
method: 'sequence_getWalletConfig',
|
|
503
|
+
params: [options?.chainId || this.getChainId()],
|
|
504
|
+
chainId: options?.chainId
|
|
505
|
+
})
|
|
528
506
|
return Array.isArray(res) ? res[0] : res
|
|
529
507
|
}
|
|
530
508
|
|
package/src/eip191exceptions.ts
CHANGED
|
@@ -23,7 +23,7 @@ const DCL_REGEX =
|
|
|
23
23
|
/^Decentraland Login\nEphemeral address: 0x[a-fA-F0-9]{40}\nExpiration: (\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/
|
|
24
24
|
export function isDecentralandLoginMessage(bytes: Uint8Array): boolean {
|
|
25
25
|
try {
|
|
26
|
-
const stringified = ethers.
|
|
26
|
+
const stringified = ethers.toUtf8String(bytes)
|
|
27
27
|
return DCL_REGEX.test(stringified)
|
|
28
28
|
} catch {
|
|
29
29
|
return false
|
|
@@ -33,7 +33,7 @@ export function isDecentralandLoginMessage(bytes: Uint8Array): boolean {
|
|
|
33
33
|
// try to interpret bytes as abi-encoded 0x v3 OrderWithHash -
|
|
34
34
|
// see https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md
|
|
35
35
|
export function isZeroExV3Order(bytes: Uint8Array): boolean {
|
|
36
|
-
const abi = new ethers.
|
|
36
|
+
const abi = new ethers.Interface(ZeroXV3EIP1271OrderWithHashAbi)
|
|
37
37
|
try {
|
|
38
38
|
abi.decodeFunctionData('OrderWithHash', bytes)
|
|
39
39
|
return true
|