@0xsequence/provider 1.0.5 → 1.1.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.
Files changed (31) hide show
  1. package/dist/0xsequence-provider.cjs.dev.js +1742 -1678
  2. package/dist/0xsequence-provider.cjs.prod.js +1742 -1678
  3. package/dist/0xsequence-provider.esm.js +1735 -1676
  4. package/dist/declarations/src/client.d.ts +74 -0
  5. package/dist/declarations/src/index.d.ts +3 -1
  6. package/dist/declarations/src/init.d.ts +25 -0
  7. package/dist/declarations/src/provider.d.ts +127 -63
  8. package/dist/declarations/src/signer.d.ts +87 -0
  9. package/dist/declarations/src/transports/mux-transport/mux-message-provider.d.ts +21 -0
  10. package/dist/declarations/src/transports/wallet-request-handler.d.ts +0 -1
  11. package/dist/declarations/src/types.d.ts +25 -9
  12. package/dist/declarations/src/utils/index.d.ts +10 -7
  13. package/dist/declarations/src/utils.d.ts +21 -15
  14. package/package.json +19 -12
  15. package/src/client.ts +423 -0
  16. package/src/extended.ts +4 -0
  17. package/src/index.ts +3 -1
  18. package/src/init.ts +134 -0
  19. package/src/provider.ts +447 -424
  20. package/src/signer.ts +316 -0
  21. package/src/transports/base-wallet-transport.ts +3 -8
  22. package/src/transports/mux-transport/mux-message-provider.ts +86 -2
  23. package/src/transports/proxy-transport/proxy-message-provider.ts +1 -1
  24. package/src/transports/wallet-request-handler.ts +3 -33
  25. package/src/transports/window-transport/window-message-provider.ts +4 -2
  26. package/src/types.ts +41 -10
  27. package/src/utils/index.ts +16 -76
  28. package/src/utils.ts +81 -51
  29. package/dist/declarations/src/extended.d.ts +0 -6
  30. package/dist/declarations/src/wallet.d.ts +0 -105
  31. package/src/wallet.ts +0 -770
@@ -0,0 +1,74 @@
1
+ import { JsonRpcRequest, NetworkConfig } from "@0xsequence/network";
2
+ import { ConnectDetails, ConnectOptions, ItemStore, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession } from "./index.js";
3
+ import { commons } from "@0xsequence/core";
4
+ import { TypedData } from "@0xsequence/utils";
5
+ import { ethers } from "ethers";
6
+ /**
7
+ * This session class is meant to persist the state of the wallet connection
8
+ * whitin the dapp. This enables the client to retain the wallet address (and some more)
9
+ * even if the user refreshes the page. Otherwise we would have to open the popup again.
10
+ */
11
+ export declare class SequenceClientSession {
12
+ private store;
13
+ static readonly SESSION_LOCALSTORE_KEY = "@sequence.session";
14
+ constructor(store: ItemStore);
15
+ connectedSession(): Required<WalletSession>;
16
+ hasSession(): boolean;
17
+ setSession(session: WalletSession): void;
18
+ getSession(): WalletSession | undefined;
19
+ clearSession(): Promise<void>;
20
+ }
21
+ /**
22
+ * The wallet webapp doesn't really care what's the "default chain" for the user.
23
+ * so we don't even bother to send this information to the wallet. Instead, we
24
+ * track it locally using storage, that way the data stays always in sync.
25
+ */
26
+ export declare class DefaultChainIdTracker {
27
+ private store;
28
+ private startingChainId;
29
+ static readonly SESSION_CHAIN_ID_KEY = "@sequence.session.defaultChainId";
30
+ callbacks: ((chainId: number) => void)[];
31
+ constructor(store: ItemStore, startingChainId?: number);
32
+ onDefaultChainIdChanged(callback: (chainId: number) => void): () => void;
33
+ setDefaultChainId(chainId: number): void;
34
+ getDefaultChainId(): number;
35
+ }
36
+ /**
37
+ * This is a wallet client for sequence wallet-webapp. It connects using *some* transport
38
+ * and it allows to perform all sequence specific (or write) operations related to the wallet.
39
+ *
40
+ * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
41
+ */
42
+ export declare class SequenceClient {
43
+ private readonly session;
44
+ private readonly defaultChainId;
45
+ private readonly callbacks;
46
+ readonly transport: ProviderTransport;
47
+ constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, defaultChainId?: number);
48
+ registerCallback<K extends keyof WalletEventTypes>(eventName: K, callback: WalletEventTypes[K]): () => void;
49
+ onOpen(callback: WalletEventTypes['open']): () => void;
50
+ onClose(callback: WalletEventTypes['close']): () => void;
51
+ onConnect(callback: WalletEventTypes['connect']): () => void;
52
+ onDisconnect(callback: WalletEventTypes['disconnect']): () => void;
53
+ onNetworks(callback: WalletEventTypes['networks']): () => void;
54
+ onAccountsChanged(callback: WalletEventTypes['accountsChanged']): () => void;
55
+ onWalletContext(callback: WalletEventTypes['walletContext']): () => void;
56
+ onDefaultChainIdChanged(callback: WalletEventTypes['chainChanged']): () => void;
57
+ getChainId(): number;
58
+ setDefaultChainId(chainId: number): void;
59
+ openWallet(path?: string, intent?: OpenWalletIntent): Promise<boolean>;
60
+ closeWallet(): void;
61
+ isOpened(): boolean;
62
+ isConnected(): boolean;
63
+ getSession(): WalletSession | undefined;
64
+ getAddress(): string;
65
+ connect(options: ConnectOptions): Promise<ConnectDetails>;
66
+ disconnect(): Promise<void>;
67
+ send(request: JsonRpcRequest, chainId?: number): Promise<any>;
68
+ getNetworks(pull?: boolean): Promise<NetworkConfig[]>;
69
+ signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
70
+ signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string>;
71
+ sendTransaction(tx: (ethers.providers.TransactionRequest[] | ethers.providers.TransactionRequest), options?: OptionalChainId): Promise<string>;
72
+ getWalletContext(): Promise<commons.context.VersionedContext>;
73
+ getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config>;
74
+ }
@@ -1,5 +1,7 @@
1
1
  export * from "./transports/index.js";
2
2
  export * from "./types.js";
3
- export * from "./wallet.js";
4
3
  export * from "./provider.js";
5
4
  export * from "./utils.js";
5
+ export * from "./client.js";
6
+ export * from "./signer.js";
7
+ export * from "./init.js";
@@ -0,0 +1,25 @@
1
+ import { ChainIdLike, NetworkConfig } from "@0xsequence/network";
2
+ import { MuxTransportTemplate } from "./transports/index.js";
3
+ import { ItemStore } from "./utils.js";
4
+ import { SequenceProvider } from "./provider.js";
5
+ export interface ProviderConfig {
6
+ localStorage?: ItemStore;
7
+ defaultNetwork?: ChainIdLike;
8
+ networks?: Partial<NetworkConfig>[];
9
+ transports?: MuxTransportTemplate;
10
+ }
11
+ export declare const DefaultProviderConfig: {
12
+ transports: {
13
+ walletAppURL: string;
14
+ windowTransport: {
15
+ enabled: boolean;
16
+ };
17
+ proxyTransport: {
18
+ enabled: boolean;
19
+ };
20
+ };
21
+ defaultNetwork: number;
22
+ };
23
+ export declare const initWallet: (partialConfig?: Partial<ProviderConfig>) => SequenceProvider;
24
+ export declare const unregisterWallet: () => void;
25
+ export declare const getWallet: () => SequenceProvider;
@@ -1,68 +1,132 @@
1
- import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField } from 'ethers';
2
- import { NetworkConfig, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
3
- import { Signer } from '@0xsequence/wallet';
4
- import { Relayer } from '@0xsequence/relayer';
5
- import { Deferrable } from '@0xsequence/utils';
6
- import { commons } from '@0xsequence/core';
7
- import { Account, AccountStatus } from '@0xsequence/account';
8
- import { ExtendedTransactionRequest } from "./extended.js";
9
- export declare class Web3Provider extends providers.Web3Provider implements JsonRpcHandler {
10
- static isSequenceProvider(cand: any): cand is Web3Provider;
11
- readonly _sender: JsonRpcSender;
12
- readonly _isSequenceProvider: boolean;
13
- readonly _defaultChainId?: number;
14
- constructor(provider: providers.JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike);
15
- sendAsync(request: JsonRpcRequest, callback: JsonRpcResponseCallback | ((error: any, response: any) => void), chainId?: number): void;
16
- send(method: string, params: Array<any>, chainId?: number): Promise<any>;
17
- request(request: {
18
- method: string;
19
- params?: Array<any>;
20
- chainId?: number;
21
- }): Promise<any>;
22
- getSigner(): Web3Signer;
23
- getChainId(): Promise<number>;
1
+ import { ethers } from "ethers";
2
+ import { SequenceClient } from "./client.js";
3
+ import { ChainIdLike, NetworkConfig } from "@0xsequence/network";
4
+ import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types.js";
5
+ import { commons } from "@0xsequence/core";
6
+ import { WalletUtils } from "./utils/index.js";
7
+ import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer.js";
8
+ export interface ISequenceProvider {
9
+ readonly _isSequenceProvider: true;
10
+ connect(options?: ConnectOptions): Promise<ConnectDetails>;
11
+ disconnect(): void;
12
+ isConnected(): boolean;
13
+ getSession(): WalletSession | undefined;
14
+ listAccounts(): string[];
15
+ getAddress(): string;
24
16
  getNetworks(): Promise<NetworkConfig[]>;
25
- }
26
- export declare function isSequenceProvider(provider: any): provider is Web3Provider;
27
- export declare class LocalWeb3Provider extends Web3Provider {
28
- constructor(account: Account, networks?: NetworkConfig[]);
29
- }
30
- interface TypedDataSigner {
31
- _signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
32
- }
33
- export declare class Web3Signer extends Signer implements TypedDataSigner {
34
- readonly provider: Web3Provider;
35
- readonly defaultChainId?: number;
36
- constructor(provider: Web3Provider, defaultChainId?: number);
37
- _address: string;
38
- _index: number;
39
- _context: commons.context.VersionedContext;
40
- _networks: NetworkConfig[];
41
- private _providers;
42
- getAddress(): Promise<string>;
43
- signTransaction(transaction: Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
44
- connect(provider: ethers.providers.Provider): ethers.providers.JsonRpcSigner;
45
- getProvider(chainId?: number): Promise<Web3Provider | undefined>;
46
- getSender(chainId?: number): Promise<Web3Provider | undefined>;
47
- getRelayer(chainId?: number): Promise<Relayer | undefined>;
17
+ getChainId(): number;
18
+ setDefaultChainId(chainId: ChainIdLike): void;
19
+ isOpened(): boolean;
20
+ openWallet(path?: string, intent?: OpenWalletIntent): Promise<boolean>;
21
+ closeWallet(): void;
22
+ getProvider(): SequenceProvider;
23
+ getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
24
+ getProvider(chainId?: ChainIdLike): SequenceProvider | SingleNetworkSequenceProvider;
25
+ getSigner(): SequenceSigner;
26
+ getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
27
+ getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
48
28
  getWalletContext(): Promise<commons.context.VersionedContext>;
49
29
  getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
50
- getWalletState(chainId?: ChainIdLike): Promise<AccountStatus>;
30
+ utils: WalletUtils;
31
+ }
32
+ export declare class SequenceProvider extends ethers.providers.BaseProvider implements ISequenceProvider, EIP1193Provider {
33
+ readonly client: SequenceClient;
34
+ private readonly providerFor;
35
+ readonly networks: NetworkConfig[];
36
+ private readonly singleNetworkProviders;
37
+ readonly _isSequenceProvider = true;
38
+ readonly utils: WalletUtils;
39
+ readonly signer: SequenceSigner;
40
+ constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.providers.JsonRpcProvider, networks?: NetworkConfig[]);
41
+ getSigner(): SequenceSigner;
42
+ getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
43
+ getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
44
+ connect(options: ConnectOptions): Promise<ConnectDetails>;
45
+ disconnect(): Promise<void>;
46
+ isConnected(): boolean;
47
+ getSession(): WalletSession | undefined;
48
+ listAccounts(): string[];
49
+ getAddress(): string;
51
50
  getNetworks(): Promise<NetworkConfig[]>;
52
- getSigners(): Promise<string[]>;
53
- signMessage(message: BytesLike, chainId?: ChainIdLike, sequenceVerified?: boolean): Promise<string>;
54
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, sequenceVerified?: boolean): Promise<string>;
55
- sendTransaction(transaction: Deferrable<ExtendedTransactionRequest>, chainId?: ChainIdLike): Promise<commons.transaction.TransactionResponse>;
56
- sendTransactionBatch(transactions: Deferrable<ethers.providers.TransactionRequest[]>, chainId?: ChainIdLike): Promise<ethers.providers.TransactionResponse>;
57
- signTransactions(transaction: Deferrable<ethers.providers.TransactionRequest>, chainId?: ChainIdLike): Promise<commons.transaction.SignedTransactionBundle>;
58
- sendSignedTransactions(signedTxs: commons.transaction.SignedTransactionBundle, chainId?: ChainIdLike): Promise<ethers.providers.TransactionResponse>;
59
- updateConfig(newConfig?: commons.config.Config): Promise<[commons.config.Config, ethers.providers.TransactionResponse | undefined]>;
60
- publishConfig(): Promise<ethers.providers.TransactionResponse | undefined>;
61
- isDeployed(chainId?: ChainIdLike): Promise<boolean>;
62
- _legacySignMessage(message: Bytes | string, chainId?: ChainIdLike): Promise<string>;
63
- _signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike): Promise<string>;
64
- sendUncheckedTransaction(transaction: Deferrable<ExtendedTransactionRequest>, chainId?: ChainIdLike): Promise<string>;
65
- connectUnchecked(): ethers.providers.JsonRpcSigner;
66
- unlock(password: string): Promise<boolean>;
51
+ getChainId(): number;
52
+ setDefaultChainId(chainId: ChainIdLike): void;
53
+ isOpened(): boolean;
54
+ closeWallet(): void;
55
+ getWalletContext(): Promise<commons.context.VersionedContext>;
56
+ getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
57
+ authorize(options: ConnectOptions): Promise<ConnectDetails>;
58
+ openWallet(path?: string, intent?: OpenWalletIntent): Promise<boolean>;
59
+ toChainId(chainId: ChainIdLike): number;
60
+ toChainId(chainId?: ChainIdLike): number | undefined;
61
+ /**
62
+ * Resolves the chainId to use for the given request. If no chainId is provided,
63
+ * it uses the chainId defined by the client (default chainId). This can be
64
+ * overriden to build a single-network SequenceProvider.
65
+ */
66
+ protected useChainId(chainId?: ChainIdLike): Promise<number>;
67
+ /**
68
+ * This generates a provider that ONLY works for the given chainId.
69
+ * the generated provider can't switch networks, and can't handle requests
70
+ * for other networks.
71
+ */
72
+ getProvider(): SequenceProvider;
73
+ getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
74
+ getProvider(chainId?: ChainIdLike): SequenceProvider | SingleNetworkSequenceProvider;
75
+ /**
76
+ * This returns a subprovider, this is a regular non-sequence provider that
77
+ * can be used to fulfill read only requests on a given network.
78
+ */
79
+ _getSubprovider(chainId?: ChainIdLike): Promise<ethers.providers.JsonRpcProvider>;
80
+ perform(method: string, params: any): Promise<any>;
81
+ send(method: string, params: any): Promise<any>;
82
+ request(request: {
83
+ method: string;
84
+ params?: any[] | undefined;
85
+ }): Promise<any>;
86
+ detectNetwork(): Promise<ethers.providers.Network>;
87
+ waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number, optionals?: OptionalChainIdLike): Promise<ethers.providers.TransactionReceipt>;
88
+ getBlockNumber(optionals?: OptionalChainIdLike): Promise<number>;
89
+ getGasPrice(optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
90
+ getBalance(addressOrName: string | Promise<string>, blockTag?: ethers.providers.BlockTag | Promise<ethers.providers.BlockTag>, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
91
+ getTransactionCount(addressOrName: string | Promise<string>, blockTag?: ethers.providers.BlockTag | Promise<ethers.providers.BlockTag>, optionals?: OptionalChainIdLike): Promise<number>;
92
+ getCode(addressOrName: string | Promise<string>, blockTag?: ethers.providers.BlockTag | Promise<ethers.providers.BlockTag>, optionals?: OptionalChainIdLike): Promise<string>;
93
+ getStorageAt(addressOrName: string | Promise<string>, position: ethers.BigNumberish | Promise<ethers.BigNumberish>, blockTag?: ethers.providers.BlockTag | Promise<ethers.providers.BlockTag>, optionals?: OptionalChainIdLike): Promise<string>;
94
+ call(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, blockTag?: ethers.providers.BlockTag | Promise<ethers.providers.BlockTag>, optionals?: OptionalChainIdLike): Promise<string>;
95
+ estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
96
+ getBlock(blockHashOrBlockTag: ethers.providers.BlockTag | string | Promise<ethers.providers.BlockTag | string>, optionals?: OptionalChainIdLike): Promise<ethers.providers.Block>;
97
+ getTransaction(transactionHash: string | Promise<string>, optionals?: OptionalChainIdLike): Promise<ethers.providers.TransactionResponse>;
98
+ getLogs(filter: ethers.providers.Filter | Promise<ethers.providers.Filter>, optionals?: OptionalChainIdLike): Promise<ethers.providers.Log[]>;
99
+ supportsENS(): Promise<boolean>;
100
+ getResolver(name: string): Promise<ethers.providers.Resolver | null>;
101
+ resolveName(name: string | Promise<string>): Promise<string | null>;
102
+ lookupAddress(address: string | Promise<string>): Promise<string | null>;
103
+ getAvatar(nameOrAddress: string): Promise<string | null>;
104
+ static is: (provider: any) => provider is SequenceProvider;
105
+ }
106
+ /**
107
+ * This is the same provider, but it only allows a single network at a time.
108
+ * the network defined by the constructor is the only one that can be used.
109
+ *
110
+ * Attempting to call any method with a different network will throw an error.
111
+ * Attempting to change the network of this provider will throw an error.
112
+ *
113
+ * NOTICE: These networks won't support ENS unless they are the mainnet.
114
+ */
115
+ export declare class SingleNetworkSequenceProvider extends SequenceProvider {
116
+ readonly chainId: ChainIdLike;
117
+ readonly _isSingleNetworkSequenceProvider = true;
118
+ constructor(client: SequenceClient, providerFor: (networkId: number) => ethers.providers.JsonRpcProvider, chainId: ChainIdLike);
119
+ private _useChainId;
120
+ protected useChainId(chainId?: ChainIdLike): Promise<number>;
121
+ getChainId(): number;
122
+ getNetwork(): Promise<NetworkConfig>;
123
+ /**
124
+ * Override getProvider and getSigner so they always use `useChainId`
125
+ * this way they can't return providers and signers that can switch networks,
126
+ * or that don't match the chainId of this signer.
127
+ */
128
+ getProvider(chainId?: ChainIdLike): SingleNetworkSequenceProvider;
129
+ getSigner(chainId?: ChainIdLike): SingleNetworkSequenceSigner;
130
+ setDefaultChainId(_chainId: ChainIdLike): void;
131
+ static is(cand: any): cand is SingleNetworkSequenceProvider;
67
132
  }
68
- export {};
@@ -0,0 +1,87 @@
1
+ import { ethers } from "ethers";
2
+ import { SequenceProvider, SingleNetworkSequenceProvider } from "./provider.js";
3
+ import { SequenceClient } from "./client.js";
4
+ import { commons } from "@0xsequence/core";
5
+ import { ChainIdLike, NetworkConfig } from "@0xsequence/network";
6
+ import { WalletUtils } from "./utils/index.js";
7
+ import { OptionalChainIdLike, OptionalEIP6492 } from "./types.js";
8
+ export interface ISequenceSigner extends ethers.Signer {
9
+ getProvider(): SequenceProvider;
10
+ getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
11
+ getProvider(chainId?: ChainIdLike): SequenceProvider | SingleNetworkSequenceProvider;
12
+ getSigner(): SequenceSigner;
13
+ getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
14
+ getSigner(chainId?: ChainIdLike): SequenceSigner | SingleNetworkSequenceSigner;
15
+ getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
16
+ getNetworks(): Promise<NetworkConfig[]>;
17
+ signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
18
+ signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
19
+ sendTransaction(transaction: (ethers.utils.Deferrable<ethers.providers.TransactionRequest>[] | ethers.utils.Deferrable<ethers.providers.TransactionRequest>), options?: OptionalChainIdLike): Promise<commons.transaction.TransactionResponse>;
20
+ utils: WalletUtils;
21
+ }
22
+ export declare class SequenceSigner implements ISequenceSigner {
23
+ client: SequenceClient;
24
+ provider: SequenceProvider;
25
+ private readonly singleNetworkSigners;
26
+ readonly _isSigner: boolean;
27
+ readonly _isSequenceSigner: boolean;
28
+ get utils(): WalletUtils;
29
+ constructor(client: SequenceClient, provider: SequenceProvider);
30
+ getAddress(): Promise<string>;
31
+ connect(provider: ethers.providers.Provider): SequenceSigner;
32
+ getSigner(): SequenceSigner;
33
+ getSigner(chainId: ChainIdLike): SingleNetworkSequenceSigner;
34
+ getSigner(chainId?: ChainIdLike): SingleNetworkSequenceSigner | SequenceSigner;
35
+ /**
36
+ * Resolves the chainId to use for the given request. If no chainId is provided,
37
+ * it uses the chainId defined by the client (default chainId). This can be
38
+ * overriden to build a single-network SequenceProvider.
39
+ */
40
+ protected useChainId(chainId?: ChainIdLike): number;
41
+ signMessage(message: ethers.BytesLike, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
42
+ signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, message: Record<string, any>, options?: OptionalChainIdLike & OptionalEIP6492): Promise<string>;
43
+ getProvider(): SequenceProvider;
44
+ getProvider(chainId: ChainIdLike): SingleNetworkSequenceProvider;
45
+ getProvider(chainId?: ChainIdLike): SingleNetworkSequenceProvider | SequenceProvider;
46
+ sendTransaction(transaction: (ethers.utils.Deferrable<ethers.providers.TransactionRequest>[] | ethers.utils.Deferrable<ethers.providers.TransactionRequest>), options?: OptionalChainIdLike): Promise<ethers.providers.TransactionResponse>;
47
+ getWalletConfig(chainId?: ChainIdLike | undefined): Promise<commons.config.Config>;
48
+ getNetworks(): Promise<NetworkConfig[]>;
49
+ getBalance(blockTag?: ethers.providers.BlockTag | undefined, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
50
+ estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
51
+ call(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, blockTag?: ethers.providers.BlockTag | undefined, optionals?: OptionalChainIdLike): Promise<string>;
52
+ getChainId(): Promise<number>;
53
+ getGasPrice(optionals?: OptionalChainIdLike): Promise<ethers.BigNumber>;
54
+ getFeeData(optionals?: OptionalChainIdLike): Promise<ethers.providers.FeeData>;
55
+ resolveName(name: string): Promise<string>;
56
+ _checkProvider(_operation?: string | undefined): void;
57
+ populateTransaction(_transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.providers.TransactionRequest>;
58
+ checkTransaction(_transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
59
+ getTransactionCount(_blockTag?: ethers.providers.BlockTag | undefined): Promise<number>;
60
+ signTransaction(_transaction: ethers.utils.Deferrable<commons.transaction.Transactionish>): Promise<string>;
61
+ static is(cand: any): cand is SequenceSigner;
62
+ }
63
+ /**
64
+ * This is the same provider, but it only allows a single network at a time.
65
+ * the network defined by the constructor is the only one that can be used.
66
+ *
67
+ * Attempting to call any method with a different network will throw an error.
68
+ * Attempting to change the network of this provider will throw an error.
69
+ *
70
+ * NOTICE: These networks won't support ENS unless they are the mainnet.
71
+ */
72
+ export declare class SingleNetworkSequenceSigner extends SequenceSigner {
73
+ readonly chainId: ChainIdLike;
74
+ readonly _isSingleNetworkSequenceSigner = true;
75
+ constructor(client: SequenceClient, provider: SequenceProvider, chainId: ChainIdLike);
76
+ private _useChainId;
77
+ protected useChainId(chainId?: ChainIdLike): number;
78
+ getChainId(): Promise<number>;
79
+ /**
80
+ * Override getProvider and getSigner so they always use `useChainId`
81
+ * this way they can't return providers and signers that can switch networks,
82
+ * or that don't match the chainId of this signer.
83
+ */
84
+ getProvider(chainId?: ChainIdLike): SingleNetworkSequenceProvider;
85
+ getSigner(chainId?: ChainIdLike | undefined): SingleNetworkSequenceSigner;
86
+ static is(cand: any): cand is SingleNetworkSequenceSigner;
87
+ }
@@ -1,9 +1,30 @@
1
1
  import { ProviderMessage, ProviderTransport, ProviderEventTypes, ProviderMessageRequest, ProviderMessageResponse, WalletSession, OpenWalletIntent, ConnectDetails } from "../../types.js";
2
2
  import { JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
3
+ import { ProxyMessageChannelPort } from "../proxy-transport/index.js";
4
+ import { Runtime } from 'webextension-polyfill';
5
+ export type MuxTransportTemplate = {
6
+ walletAppURL?: string;
7
+ windowTransport?: {
8
+ enabled: boolean;
9
+ };
10
+ proxyTransport?: {
11
+ enabled: boolean;
12
+ appPort?: ProxyMessageChannelPort;
13
+ };
14
+ extensionTransport?: {
15
+ enabled: boolean;
16
+ runtime: Runtime.Static;
17
+ };
18
+ unrealTransport?: {
19
+ enabled: boolean;
20
+ };
21
+ };
22
+ export declare function isMuxTransportTemplate(obj: any): obj is MuxTransportTemplate;
3
23
  export declare class MuxMessageProvider implements ProviderTransport {
4
24
  private messageProviders;
5
25
  private provider;
6
26
  constructor(...messageProviders: ProviderTransport[]);
27
+ static new(template: MuxTransportTemplate): MuxMessageProvider;
7
28
  add(...messageProviders: ProviderTransport[]): void;
8
29
  register: () => void;
9
30
  unregister: () => void;
@@ -19,7 +19,6 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
19
19
  onConnectOptionsChange: ((connectOptions: ConnectOptions | undefined) => void) | undefined;
20
20
  constructor(account: Account | null | undefined, prompter: WalletUserPrompter | null, networks: NetworkConfig[]);
21
21
  defaultChainId(): number;
22
- private findNetworkID;
23
22
  signIn(account: Account | null, options?: WalletSignInOptions): Promise<void>;
24
23
  signOut(): void;
25
24
  signerReset(): void;
@@ -1,6 +1,6 @@
1
1
  import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth';
2
2
  import { commons } from '@0xsequence/core';
3
- import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponse, NetworkConfig, ProviderRpcError as NetworkProviderRpcError } from '@0xsequence/network';
3
+ import { ChainIdLike, JsonRpcHandler, JsonRpcRequest, JsonRpcResponse, NetworkConfig, ProviderRpcError as NetworkProviderRpcError } from '@0xsequence/network';
4
4
  import { TypedData } from '@0xsequence/utils';
5
5
  export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
6
6
  register(): void;
@@ -15,6 +15,7 @@ export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransp
15
15
  waitUntilOpened(): Promise<WalletSession | undefined>;
16
16
  waitUntilConnected(): Promise<ConnectDetails>;
17
17
  }
18
+ export declare function isProviderTransport(transport: any): transport is ProviderTransport;
18
19
  export interface WalletTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
19
20
  register(): void;
20
21
  unregister(): void;
@@ -103,11 +104,8 @@ export declare enum InitState {
103
104
  OK = 2
104
105
  }
105
106
  export interface ConnectOptions {
106
- /** Specifies the default network a dapp would like to connect to. This field
107
- * is optional as it can be provided a number of different ways. */
108
- networkId?: string | number;
109
107
  /** app name of the dapp which will be announced to user on connect screen */
110
- app?: string;
108
+ app: string;
111
109
  /** custom protocol for auth redirect (unity/unreal) */
112
110
  appProtocol?: string;
113
111
  /** origin hint of the dapp's host opening the wallet. This value will automatically
@@ -129,6 +127,12 @@ export interface ConnectOptions {
129
127
  /** Options to further customize the wallet experience. */
130
128
  settings?: Settings;
131
129
  }
130
+ export interface NetworkedConnectOptions extends ConnectOptions {
131
+ /** chainId is the chainId to connect to. If not specified, the default chainId
132
+ * will be used. This does not define a default chain id, it is only used for the connect
133
+ * authorization signature. */
134
+ networkId?: string | number;
135
+ }
132
136
  /** Options to further customize the wallet experience. */
133
137
  export interface Settings {
134
138
  /** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
@@ -192,7 +196,7 @@ export interface ConnectDetails {
192
196
  export type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'error' | 'connected' | 'proof' | 'email'>;
193
197
  export type OpenWalletIntent = {
194
198
  type: 'connect';
195
- options?: ConnectOptions;
199
+ options?: NetworkedConnectOptions;
196
200
  } | {
197
201
  type: 'openWithOptions';
198
202
  options?: ConnectOptions;
@@ -211,9 +215,6 @@ export interface WalletSession {
211
215
  walletContext?: commons.context.VersionedContext;
212
216
  accountAddress?: string;
213
217
  networks?: NetworkConfig[];
214
- providerCache?: {
215
- [key: string]: any;
216
- };
217
218
  }
218
219
  export declare class ProviderError extends Error {
219
220
  constructor(message?: string);
@@ -234,4 +235,19 @@ export interface TypedEventEmitter<Events> {
234
235
  listenerCount<E extends keyof Events>(event: E): number;
235
236
  }
236
237
  type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T];
238
+ export type OptionalChainIdLike = {
239
+ chainId?: ChainIdLike;
240
+ } | undefined;
241
+ export type OptionalChainId = {
242
+ chainId?: number;
243
+ } | undefined;
244
+ export type OptionalEIP6492 = {
245
+ eip6492?: boolean;
246
+ } | undefined;
247
+ export interface EIP1193Provider {
248
+ request: (request: {
249
+ method: string;
250
+ params?: Array<any>;
251
+ }) => Promise<any>;
252
+ }
237
253
  export {};
@@ -1,14 +1,17 @@
1
1
  import { BytesLike, TypedDataDomain, TypedDataField } from 'ethers';
2
2
  import { ChainIdLike } from '@0xsequence/network';
3
3
  import { TypedData } from '@0xsequence/utils';
4
- import { Wallet } from "../wallet.js";
4
+ import { SequenceSigner } from "../signer.js";
5
+ /**
6
+ * This class is redundant with the SequenceSigner class, but it is here for now to
7
+ * maintain compatibility with the old wallet API. Eventually we should move these
8
+ * methods to the SequenceSigner class and deprecate this class.
9
+ */
5
10
  export declare class WalletUtils {
6
- private wallet;
7
- constructor(walletProvider: Wallet);
8
- signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
9
- signAuthMessage(message: BytesLike, allSigners?: boolean): Promise<string>;
10
- signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
11
- signAuthTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, allSigners?: boolean): Promise<string>;
11
+ signer: SequenceSigner;
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>;
12
15
  isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number): Promise<boolean>;
13
16
  isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number): Promise<boolean>;
14
17
  isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number): Promise<boolean>;
@@ -11,21 +11,27 @@ export declare const isBrowserExtension: () => boolean;
11
11
  export declare const isUnityPlugin: () => boolean;
12
12
  export declare const isWalletUpToDate: (status: AccountStatus) => boolean;
13
13
  export interface ItemStore {
14
- getItem(key: string): Promise<string | null>;
15
- setItem(key: string, value: string): Promise<void>;
16
- removeItem(key: string): Promise<void>;
14
+ getItem(key: string): string | null;
15
+ setItem(key: string, value: string): void;
16
+ removeItem(key: string): void;
17
+ onItemChange(key: string, cb: (value: string | null) => void): () => void;
17
18
  }
18
- export declare class LocalStorage {
19
- private static _instance;
20
- private constructor();
21
- static getInstance(): ItemStore;
22
- static use(instance: ItemStore): void;
19
+ export declare class MemoryItemStore implements ItemStore {
20
+ private callbacks;
21
+ private store;
22
+ getItem(key: string): string | null;
23
+ setItem(key: string, value: string): void;
24
+ removeItem(key: string): void;
25
+ onItemChange(key: string, cb: (value: string | null) => void): () => void;
23
26
  }
24
- export declare class LocalStore<T extends Object = string> {
25
- def?: T | undefined;
26
- readonly key: string;
27
- constructor(key: string, def?: T | undefined);
28
- get(): Promise<T | undefined>;
29
- set(val: T | undefined): void;
30
- del(): void;
27
+ export declare class LocalStorage implements ItemStore {
28
+ private callbacks;
29
+ static isAvailable(): boolean;
30
+ constructor();
31
+ getItem(key: string): string | null;
32
+ setItem(key: string, value: string): void;
33
+ removeItem(key: string): void;
34
+ onItemChange(key: string, cb: (value: string | null) => void): () => void;
31
35
  }
36
+ export declare function useBestStore(): ItemStore;
37
+ export declare function resolveArrayProperties<T>(object: Readonly<ethers.utils.Deferrable<T>> | Readonly<ethers.utils.Deferrable<T>>[]): Promise<T>;