@0xsequence/provider 0.43.34 → 1.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 +2265 -2219
- package/dist/0xsequence-provider.cjs.prod.js +2265 -2219
- package/dist/0xsequence-provider.esm.js +2521 -2477
- package/dist/declarations/src/extended.d.ts +6 -0
- package/dist/declarations/src/provider.d.ts +23 -21
- package/dist/declarations/src/transports/base-provider-transport.d.ts +3 -2
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +3 -2
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +19 -22
- package/dist/declarations/src/types.d.ts +10 -14
- package/dist/declarations/src/utils/index.d.ts +5 -9
- package/dist/declarations/src/utils.d.ts +9 -17
- package/dist/declarations/src/wallet.d.ts +12 -15
- package/package.json +11 -10
- package/src/extended.ts +23 -0
- package/src/provider.ts +74 -75
- package/src/transports/base-provider-transport.ts +3 -2
- package/src/transports/base-wallet-transport.ts +11 -10
- package/src/transports/wallet-request-handler.ts +251 -180
- package/src/types.ts +12 -15
- package/src/utils/index.ts +46 -51
- package/src/utils.ts +97 -96
- package/src/wallet.ts +42 -52
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
export type ExtendedTransactionRequest = ethers.providers.TransactionRequest & {
|
|
3
|
+
auxiliary?: ethers.providers.TransactionRequest[];
|
|
4
|
+
};
|
|
5
|
+
export declare function toExtended(transactions: ethers.providers.TransactionRequest[]): ExtendedTransactionRequest;
|
|
6
|
+
export declare function fromExtended(transaction: ExtendedTransactionRequest): ethers.providers.TransactionRequest[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ethers, BytesLike, Bytes, providers, TypedDataDomain, TypedDataField } from 'ethers';
|
|
2
|
-
import { NetworkConfig,
|
|
2
|
+
import { NetworkConfig, ChainIdLike, JsonRpcHandler, JsonRpcFetchFunc, JsonRpcRequest, JsonRpcResponseCallback, JsonRpcSender } from '@0xsequence/network';
|
|
3
3
|
import { Signer } from '@0xsequence/wallet';
|
|
4
|
-
import { WalletConfig, WalletState } from '@0xsequence/config';
|
|
5
4
|
import { Relayer } from '@0xsequence/relayer';
|
|
6
|
-
import { Deferrable
|
|
7
|
-
import {
|
|
5
|
+
import { Deferrable } from '@0xsequence/utils';
|
|
6
|
+
import { commons } from '@0xsequence/core';
|
|
7
|
+
import { Account, AccountStatus } from '@0xsequence/account';
|
|
8
|
+
import { ExtendedTransactionRequest } from './extended';
|
|
8
9
|
export declare class Web3Provider extends providers.Web3Provider implements JsonRpcHandler {
|
|
9
10
|
static isSequenceProvider(cand: any): cand is Web3Provider;
|
|
10
11
|
readonly _sender: JsonRpcSender;
|
|
@@ -20,10 +21,11 @@ export declare class Web3Provider extends providers.Web3Provider implements Json
|
|
|
20
21
|
}): Promise<any>;
|
|
21
22
|
getSigner(): Web3Signer;
|
|
22
23
|
getChainId(): Promise<number>;
|
|
24
|
+
getNetworks(): Promise<NetworkConfig[]>;
|
|
23
25
|
}
|
|
24
26
|
export declare function isSequenceProvider(provider: any): provider is Web3Provider;
|
|
25
27
|
export declare class LocalWeb3Provider extends Web3Provider {
|
|
26
|
-
constructor(
|
|
28
|
+
constructor(account: Account, networks?: NetworkConfig[]);
|
|
27
29
|
}
|
|
28
30
|
interface TypedDataSigner {
|
|
29
31
|
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
@@ -34,32 +36,32 @@ export declare class Web3Signer extends Signer implements TypedDataSigner {
|
|
|
34
36
|
constructor(provider: Web3Provider, defaultChainId?: number);
|
|
35
37
|
_address: string;
|
|
36
38
|
_index: number;
|
|
37
|
-
_context:
|
|
39
|
+
_context: commons.context.VersionedContext;
|
|
38
40
|
_networks: NetworkConfig[];
|
|
39
41
|
private _providers;
|
|
40
42
|
getAddress(): Promise<string>;
|
|
41
|
-
signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
43
|
+
signTransaction(transaction: Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
|
|
42
44
|
connect(provider: ethers.providers.Provider): ethers.providers.JsonRpcSigner;
|
|
43
45
|
getProvider(chainId?: number): Promise<Web3Provider | undefined>;
|
|
44
46
|
getSender(chainId?: number): Promise<Web3Provider | undefined>;
|
|
45
47
|
getRelayer(chainId?: number): Promise<Relayer | undefined>;
|
|
46
|
-
getWalletContext(): Promise<
|
|
47
|
-
getWalletConfig(chainId?: ChainIdLike): Promise<
|
|
48
|
-
getWalletState(chainId?: ChainIdLike): Promise<
|
|
48
|
+
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
49
|
+
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
50
|
+
getWalletState(chainId?: ChainIdLike): Promise<AccountStatus>;
|
|
49
51
|
getNetworks(): Promise<NetworkConfig[]>;
|
|
50
52
|
getSigners(): Promise<string[]>;
|
|
51
|
-
signMessage(message: BytesLike, chainId?: ChainIdLike,
|
|
52
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike,
|
|
53
|
-
sendTransaction(transaction: Deferrable<
|
|
54
|
-
sendTransactionBatch(transactions: Deferrable<
|
|
55
|
-
signTransactions(transaction: Deferrable<TransactionRequest>, chainId?: ChainIdLike
|
|
56
|
-
sendSignedTransactions(signedTxs:
|
|
57
|
-
updateConfig(newConfig?:
|
|
58
|
-
publishConfig(): Promise<TransactionResponse | undefined>;
|
|
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>;
|
|
59
61
|
isDeployed(chainId?: ChainIdLike): Promise<boolean>;
|
|
60
|
-
_legacySignMessage(message: Bytes | string, chainId?: ChainIdLike
|
|
61
|
-
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike
|
|
62
|
-
sendUncheckedTransaction(transaction: Deferrable<
|
|
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>;
|
|
63
65
|
connectUnchecked(): ethers.providers.JsonRpcSigner;
|
|
64
66
|
unlock(password: string): Promise<boolean>;
|
|
65
67
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderTransport, ProviderMessage, ProviderMessageRequest, ProviderEventTypes, ProviderMessageResponse, ProviderMessageResponseCallback, OpenState, OpenWalletIntent, ConnectDetails, WalletSession, ProviderRpcError, InitState, TypedEventEmitter } from '../types';
|
|
2
|
-
import { NetworkConfig,
|
|
2
|
+
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
3
|
+
import { commons } from '@0xsequence/core';
|
|
3
4
|
export declare const PROVIDER_OPEN_TIMEOUT = 30000;
|
|
4
5
|
export declare const nextMessageIdx: () => number;
|
|
5
6
|
export declare abstract class BaseProviderTransport implements ProviderTransport {
|
|
@@ -18,7 +19,7 @@ export declare abstract class BaseProviderTransport implements ProviderTransport
|
|
|
18
19
|
origin?: string;
|
|
19
20
|
} | undefined;
|
|
20
21
|
protected networksPayload: NetworkConfig[] | undefined;
|
|
21
|
-
protected walletContextPayload:
|
|
22
|
+
protected walletContextPayload: commons.context.VersionedContext | undefined;
|
|
22
23
|
protected _sessionId?: string;
|
|
23
24
|
protected _init: InitState;
|
|
24
25
|
protected _registered: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WalletTransport, ProviderMessage, ProviderMessageRequest, ProviderMessageResponse, ProviderRpcError, InitState, ConnectDetails, WalletSession, TransportSession } from '../types';
|
|
2
2
|
import { WalletRequestHandler } from './wallet-request-handler';
|
|
3
|
-
import { NetworkConfig,
|
|
3
|
+
import { NetworkConfig, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
4
|
+
import { commons } from '@0xsequence/core';
|
|
4
5
|
export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
5
6
|
protected walletRequestHandler: WalletRequestHandler;
|
|
6
7
|
protected _sessionId: string;
|
|
@@ -29,7 +30,7 @@ export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
|
29
30
|
notifyAccountsChanged(accounts: string[], origin?: string): void;
|
|
30
31
|
notifyChainChanged(chainIdHex: string): void;
|
|
31
32
|
notifyNetworks(networks: NetworkConfig[]): void;
|
|
32
|
-
notifyWalletContext(walletContext:
|
|
33
|
+
notifyWalletContext(walletContext: commons.context.VersionedContext): void;
|
|
33
34
|
protected isValidInitAck(message: ProviderMessage<any>): boolean;
|
|
34
35
|
private init;
|
|
35
36
|
protected open: ({ sessionId, intent, networkId }: TransportSession) => Promise<boolean>;
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Account } from '@0xsequence/account';
|
|
2
|
+
import { commons } from '@0xsequence/core';
|
|
3
3
|
import { NetworkConfig, JsonRpcHandler, JsonRpcRequest, JsonRpcResponseCallback } from '@0xsequence/network';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { providers } from 'ethers';
|
|
5
|
+
import { ProviderMessageRequest, ProviderMessageResponse, ProviderMessageRequestHandler, MessageToSign, ProviderRpcError, ConnectOptions, ConnectDetails, PromptConnectDetails, WalletSession, OpenWalletIntent, ProviderEventTypes } from '../types';
|
|
6
6
|
type ExternalProvider = providers.ExternalProvider;
|
|
7
7
|
export interface WalletSignInOptions {
|
|
8
8
|
connect?: boolean;
|
|
9
|
-
|
|
10
|
-
testnetNetworks?: NetworkConfig[];
|
|
11
|
-
defaultNetworkId?: string | number;
|
|
9
|
+
defaultNetworkId?: number;
|
|
12
10
|
}
|
|
13
11
|
export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, ProviderMessageRequestHandler {
|
|
14
|
-
private
|
|
12
|
+
private account;
|
|
15
13
|
private signerReadyCallbacks;
|
|
16
14
|
private prompter;
|
|
17
|
-
private
|
|
18
|
-
private testnetNetworks;
|
|
15
|
+
private networks;
|
|
19
16
|
private _openIntent?;
|
|
20
17
|
private _connectOptions?;
|
|
21
|
-
private _defaultNetworkId?;
|
|
22
|
-
private _chainId?;
|
|
23
18
|
private events;
|
|
24
19
|
onConnectOptionsChange: ((connectOptions: ConnectOptions | undefined) => void) | undefined;
|
|
25
|
-
constructor(
|
|
26
|
-
|
|
20
|
+
constructor(account: Account | null | undefined, prompter: WalletUserPrompter | null, networks: NetworkConfig[]);
|
|
21
|
+
defaultChainId(): number;
|
|
22
|
+
private findNetworkID;
|
|
23
|
+
signIn(account: Account | null, options?: WalletSignInOptions): Promise<void>;
|
|
27
24
|
signOut(): void;
|
|
28
25
|
signerReset(): void;
|
|
29
26
|
signerReady(timeout?: number): Promise<void>;
|
|
@@ -34,31 +31,31 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
34
31
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
35
32
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
36
33
|
getAddress(): Promise<string>;
|
|
37
|
-
getChainId(): Promise<number>;
|
|
38
34
|
get openIntent(): OpenWalletIntent | undefined;
|
|
39
35
|
setOpenIntent(intent: OpenWalletIntent | undefined): void;
|
|
40
36
|
get connectOptions(): ConnectOptions | undefined;
|
|
41
37
|
setConnectOptions(options: ConnectOptions | undefined): void;
|
|
42
|
-
|
|
43
|
-
setDefaultNetwork(chainId: string | number, notifyNetworks?: boolean): Promise<number | undefined>;
|
|
38
|
+
setDefaultChainId(chainId: number): Promise<number>;
|
|
44
39
|
getNetworks(jsonRpcResponse?: boolean): Promise<NetworkConfig[]>;
|
|
45
|
-
walletSession():
|
|
40
|
+
walletSession(): WalletSession | undefined;
|
|
46
41
|
notifyConnect(connectDetails: ConnectDetails, origin?: string): void;
|
|
47
42
|
notifyDisconnect(origin?: string): void;
|
|
48
43
|
notifyNetworks(networks?: NetworkConfig[]): Promise<void>;
|
|
49
44
|
notifyWalletContext(): Promise<void>;
|
|
50
45
|
notifyClose(error?: ProviderRpcError): void;
|
|
51
46
|
isSignedIn: () => Promise<boolean>;
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
getAccount: () => Promise<Account | null>;
|
|
48
|
+
setAccount(account: Account | null | undefined): void;
|
|
54
49
|
private handleConfirmWalletDeployPrompt;
|
|
55
50
|
}
|
|
56
51
|
export interface WalletUserPrompter {
|
|
52
|
+
getDefaultChainId(): number;
|
|
57
53
|
promptConnect(options?: ConnectOptions): Promise<PromptConnectDetails>;
|
|
58
54
|
promptSignInConnect(options?: ConnectOptions): Promise<PromptConnectDetails>;
|
|
59
55
|
promptSignMessage(message: MessageToSign, options?: ConnectOptions): Promise<string>;
|
|
60
|
-
promptSignTransaction(txn:
|
|
61
|
-
promptSendTransaction(txn:
|
|
56
|
+
promptSignTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise<string>;
|
|
57
|
+
promptSendTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise<string>;
|
|
62
58
|
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>;
|
|
59
|
+
promptChangeNetwork(chainId: number): Promise<boolean>;
|
|
63
60
|
}
|
|
64
61
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ETHAuthProof as AuthETHAuthProof } from '@0xsequence/auth';
|
|
2
|
+
import { commons } from '@0xsequence/core';
|
|
3
|
+
import { JsonRpcHandler, JsonRpcRequest, JsonRpcResponse, NetworkConfig, ProviderRpcError as NetworkProviderRpcError } from '@0xsequence/network';
|
|
2
4
|
import { TypedData } from '@0xsequence/utils';
|
|
3
5
|
export interface ProviderTransport extends JsonRpcHandler, ProviderMessageTransport, ProviderMessageRequestHandler {
|
|
4
6
|
register(): void;
|
|
@@ -38,13 +40,7 @@ export interface ProviderMessage<T> {
|
|
|
38
40
|
export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>;
|
|
39
41
|
export type ProviderMessageResponse = ProviderMessage<JsonRpcResponse>;
|
|
40
42
|
export type ProviderMessageResponseCallback = (error?: ProviderRpcError, response?: ProviderMessageResponse) => void;
|
|
41
|
-
export
|
|
42
|
-
message: string;
|
|
43
|
-
code?: number;
|
|
44
|
-
data?: {
|
|
45
|
-
[key: string]: any;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
43
|
+
export type ProviderRpcError = NetworkProviderRpcError;
|
|
48
44
|
export interface ProviderMessageRequestHandler {
|
|
49
45
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
50
46
|
}
|
|
@@ -91,7 +87,7 @@ export interface WalletEventTypes {
|
|
|
91
87
|
accountsChanged: (accounts: string[], origin?: string) => void;
|
|
92
88
|
chainChanged: (chainIdHex: string) => void;
|
|
93
89
|
networks: (networks: NetworkConfig[]) => void;
|
|
94
|
-
walletContext: (walletContext:
|
|
90
|
+
walletContext: (walletContext: commons.context.VersionedContext) => void;
|
|
95
91
|
}
|
|
96
92
|
export interface ProviderEventTypes extends WalletEventTypes {
|
|
97
93
|
message: (message: ProviderMessageResponse) => void;
|
|
@@ -121,6 +117,8 @@ export interface ConnectOptions {
|
|
|
121
117
|
expiry?: number;
|
|
122
118
|
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
|
|
123
119
|
authorize?: boolean;
|
|
120
|
+
/** authorizeVersion is the version of the SDK that will validate the ETHAuth proof. */
|
|
121
|
+
authorizeVersion?: number;
|
|
124
122
|
/** askForEmail will prompt to give permission to the dapp to access email address */
|
|
125
123
|
askForEmail?: boolean;
|
|
126
124
|
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */
|
|
@@ -206,13 +204,11 @@ export interface MessageToSign {
|
|
|
206
204
|
message?: Uint8Array;
|
|
207
205
|
typedData?: TypedData;
|
|
208
206
|
chainId?: number;
|
|
207
|
+
eip6492?: boolean;
|
|
209
208
|
}
|
|
210
|
-
export
|
|
211
|
-
typedData: TypedData;
|
|
212
|
-
proofString: string;
|
|
213
|
-
}
|
|
209
|
+
export type ETHAuthProof = AuthETHAuthProof;
|
|
214
210
|
export interface WalletSession {
|
|
215
|
-
walletContext?:
|
|
211
|
+
walletContext?: commons.context.VersionedContext;
|
|
216
212
|
accountAddress?: string;
|
|
217
213
|
networks?: NetworkConfig[];
|
|
218
214
|
providerCache?: {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BytesLike, TypedDataDomain, TypedDataField } from 'ethers';
|
|
2
|
+
import { ChainIdLike } from '@0xsequence/network';
|
|
3
3
|
import { TypedData } from '@0xsequence/utils';
|
|
4
|
-
import { DecodedSignature, WalletConfig } from '@0xsequence/config';
|
|
5
4
|
import { Wallet } from '../wallet';
|
|
6
5
|
export declare class WalletUtils {
|
|
7
6
|
private wallet;
|
|
@@ -10,10 +9,7 @@ export declare class WalletUtils {
|
|
|
10
9
|
signAuthMessage(message: BytesLike, allSigners?: boolean): Promise<string>;
|
|
11
10
|
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, chainId?: ChainIdLike, allSigners?: boolean): Promise<string>;
|
|
12
11
|
signAuthTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>, allSigners?: boolean): Promise<string>;
|
|
13
|
-
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number
|
|
14
|
-
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number
|
|
15
|
-
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number
|
|
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>;
|
|
12
|
+
isValidSignature(address: string, digest: Uint8Array, signature: string, chainId: number): Promise<boolean>;
|
|
13
|
+
isValidMessageSignature(address: string, message: string | Uint8Array, signature: string, chainId: number): Promise<boolean>;
|
|
14
|
+
isValidTypedDataSignature(address: string, typedData: TypedData, signature: string, chainId: number): Promise<boolean>;
|
|
19
15
|
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { WalletConfig, DecodedSignature } from '@0xsequence/config';
|
|
4
|
-
import { TypedData } from '@0xsequence/utils';
|
|
1
|
+
|
|
2
|
+
import { ethers, BytesLike } from 'ethers';
|
|
5
3
|
import { Web3Provider } from './provider';
|
|
6
|
-
import {
|
|
4
|
+
import { AccountStatus } from '@0xsequence/account';
|
|
5
|
+
import { commons } from '@0xsequence/core';
|
|
7
6
|
export declare const messageToBytes: (message: BytesLike) => Uint8Array;
|
|
8
7
|
export declare const prefixEIP191Message: (message: BytesLike) => Uint8Array;
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export declare const trimEIP191Prefix: (prefixedMessage: Uint8Array) => Uint8Array;
|
|
9
|
+
export declare const isValidSignature: (address: string, digest: Uint8Array, sig: string, provider: Web3Provider | ethers.providers.Web3Provider, contexts: {
|
|
10
|
+
[key: number]: commons.context.WalletContext;
|
|
11
|
+
}) => Promise<boolean>;
|
|
13
12
|
export declare const isBrowserExtension: () => boolean;
|
|
14
13
|
export declare const isUnityPlugin: () => boolean;
|
|
15
|
-
|
|
16
|
-
* Returns the status of a signer's wallet on given chain by checking wallet deployment and config status
|
|
17
|
-
*
|
|
18
|
-
* @param {Signer} signer
|
|
19
|
-
* @param {number} chainId
|
|
20
|
-
* @return {Promise<boolean>} Promise that returns true if the wallet is up to date, false otherwise
|
|
21
|
-
*/
|
|
22
|
-
export declare const isWalletUpToDate: (signer: Signer, chainId: number) => Promise<boolean>;
|
|
14
|
+
export declare const isWalletUpToDate: (status: AccountStatus) => boolean;
|
|
23
15
|
export interface ItemStore {
|
|
24
16
|
getItem(key: string): Promise<string | null>;
|
|
25
17
|
setItem(key: string, value: string): Promise<void>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { NetworkConfig,
|
|
2
|
-
import { WalletConfig, WalletState } from '@0xsequence/config';
|
|
1
|
+
import { NetworkConfig, ChainIdLike } from '@0xsequence/network';
|
|
3
2
|
import { Web3Provider, Web3Signer } from './provider';
|
|
4
3
|
import { ProxyMessageChannelPort } from './transports';
|
|
5
4
|
import { WalletSession, ProviderEventTypes, ConnectOptions, OpenWalletIntent, ConnectDetails } from './types';
|
|
6
5
|
import { ItemStore } from './utils';
|
|
7
6
|
import { WalletUtils } from './utils/index';
|
|
8
7
|
import { Runtime } from 'webextension-polyfill';
|
|
8
|
+
import { commons } from '@0xsequence/core';
|
|
9
|
+
import { AccountStatus } from '@0xsequence/account';
|
|
10
|
+
export declare const SESSION_LOCALSTORE_KEY = "@sequence.session";
|
|
9
11
|
export interface WalletProvider {
|
|
10
12
|
connect(options?: ConnectOptions): Promise<ConnectDetails>;
|
|
11
13
|
disconnect(): void;
|
|
@@ -14,15 +16,14 @@ export interface WalletProvider {
|
|
|
14
16
|
getAddress(): Promise<string>;
|
|
15
17
|
getNetworks(chainId?: ChainIdLike): Promise<NetworkConfig[]>;
|
|
16
18
|
getChainId(): Promise<number>;
|
|
17
|
-
getAuthChainId(): Promise<number>;
|
|
18
19
|
isOpened(): boolean;
|
|
19
20
|
openWallet(path?: string, intent?: OpenWalletIntent, networkId?: string | number): Promise<boolean>;
|
|
20
21
|
closeWallet(): void;
|
|
21
22
|
getProvider(chainId?: ChainIdLike): Web3Provider | undefined;
|
|
22
23
|
getSigner(chainId?: ChainIdLike): Web3Signer;
|
|
23
|
-
getWalletContext(): Promise<
|
|
24
|
-
getWalletConfig(chainId?: ChainIdLike): Promise<
|
|
25
|
-
getWalletState(chainId?: ChainIdLike): Promise<
|
|
24
|
+
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
25
|
+
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
26
|
+
getWalletState(chainId?: ChainIdLike): Promise<AccountStatus>;
|
|
26
27
|
isDeployed(chainId?: ChainIdLike): Promise<boolean>;
|
|
27
28
|
getProviderConfig(): ProviderConfig;
|
|
28
29
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
@@ -46,7 +47,7 @@ export declare class Wallet implements WalletProvider {
|
|
|
46
47
|
getConnectedSites(): Promise<string[] | undefined>;
|
|
47
48
|
isSiteConnected(origin: string | undefined): Promise<boolean>;
|
|
48
49
|
authorize: (options?: ConnectOptions) => Promise<ConnectDetails>;
|
|
49
|
-
disconnect(): void
|
|
50
|
+
disconnect(): Promise<void>;
|
|
50
51
|
getProviderConfig(): ProviderConfig;
|
|
51
52
|
isOpened(): boolean;
|
|
52
53
|
isConnected(): boolean;
|
|
@@ -54,20 +55,16 @@ export declare class Wallet implements WalletProvider {
|
|
|
54
55
|
getAddress: () => Promise<string>;
|
|
55
56
|
getNetworks: (chainId?: ChainIdLike) => Promise<NetworkConfig[]>;
|
|
56
57
|
getChainId: () => Promise<number>;
|
|
57
|
-
getAuthChainId: () => Promise<number>;
|
|
58
58
|
openWallet: (path?: string, intent?: OpenWalletIntent, networkId?: string | number) => Promise<boolean>;
|
|
59
59
|
closeWallet: () => void;
|
|
60
60
|
getProvider(chainId?: ChainIdLike): Web3Provider | undefined;
|
|
61
|
-
getAuthProvider(): Promise<Web3Provider>;
|
|
62
|
-
getAuthNetwork(): Promise<NetworkConfig>;
|
|
63
61
|
getAllProviders(): {
|
|
64
62
|
[chainId: number]: Web3Provider;
|
|
65
63
|
};
|
|
66
64
|
getSigner(chainId?: ChainIdLike): Web3Signer;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
getWalletContext(): Promise<WalletContext>;
|
|
65
|
+
getWalletConfig(chainId?: ChainIdLike): Promise<commons.config.Config>;
|
|
66
|
+
getWalletState(chainId?: ChainIdLike): Promise<AccountStatus>;
|
|
67
|
+
getWalletContext(): Promise<commons.context.VersionedContext>;
|
|
71
68
|
isDeployed(chainId?: ChainIdLike): Promise<boolean>;
|
|
72
69
|
on<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
73
70
|
once<K extends keyof ProviderEventTypes>(event: K, fn: ProviderEventTypes[K]): void;
|
|
@@ -100,7 +97,7 @@ export interface ProviderConfig {
|
|
|
100
97
|
enabled: boolean;
|
|
101
98
|
};
|
|
102
99
|
};
|
|
103
|
-
walletContext?:
|
|
100
|
+
walletContext?: commons.context.VersionedContext;
|
|
104
101
|
}
|
|
105
102
|
export declare const DefaultProviderConfig: ProviderConfig;
|
|
106
103
|
export declare const initWallet: (network?: string | number, config?: Partial<ProviderConfig>) => Promise<Wallet>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.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",
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
"author": "Horizon Blockchain Games",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@0xsequence/abi": "^0.43.34",
|
|
13
|
-
"@0xsequence/auth": "^0.43.34",
|
|
14
|
-
"@0xsequence/config": "^0.43.34",
|
|
15
|
-
"@0xsequence/network": "^0.43.34",
|
|
16
|
-
"@0xsequence/relayer": "^0.43.34",
|
|
17
|
-
"@0xsequence/transactions": "^0.43.34",
|
|
18
|
-
"@0xsequence/utils": "^0.43.34",
|
|
19
|
-
"@0xsequence/wallet": "^0.43.34",
|
|
20
12
|
"eventemitter2": "^6.4.5",
|
|
21
|
-
"webextension-polyfill": "^0.10.0"
|
|
13
|
+
"webextension-polyfill": "^0.10.0",
|
|
14
|
+
"@0xsequence/abi": "1.0.0",
|
|
15
|
+
"@0xsequence/account": "1.0.0",
|
|
16
|
+
"@0xsequence/core": "1.0.0",
|
|
17
|
+
"@0xsequence/auth": "1.0.0",
|
|
18
|
+
"@0xsequence/migration": "1.0.0",
|
|
19
|
+
"@0xsequence/network": "1.0.0",
|
|
20
|
+
"@0xsequence/relayer": "1.0.0",
|
|
21
|
+
"@0xsequence/utils": "1.0.0",
|
|
22
|
+
"@0xsequence/wallet": "1.0.0"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"ethers": ">=5.5 < 6"
|
package/src/extended.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { ethers } from "ethers"
|
|
3
|
+
|
|
4
|
+
export type ExtendedTransactionRequest = ethers.providers.TransactionRequest & {
|
|
5
|
+
auxiliary?: ethers.providers.TransactionRequest[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function toExtended(transactions: ethers.providers.TransactionRequest[]): ExtendedTransactionRequest {
|
|
9
|
+
if (transactions.length === 0) {
|
|
10
|
+
throw new Error("No transaction provided")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const [first, ...rest] = transactions
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...first,
|
|
17
|
+
auxiliary: rest,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fromExtended(transaction: ExtendedTransactionRequest): ethers.providers.TransactionRequest[] {
|
|
22
|
+
return [transaction, ...(transaction.auxiliary || [])]
|
|
23
|
+
}
|