@metamask/connect-evm 0.1.1 → 0.1.2
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/CHANGELOG.md +22 -3
- package/README.md +1 -1
- package/dist/browser/es/connect-evm.mjs +67 -47
- package/dist/browser/es/connect-evm.mjs.map +1 -1
- package/dist/src/connect.d.ts +166 -0
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/src/connect.js +593 -0
- package/dist/src/connect.js.map +1 -0
- package/dist/src/constants.d.ts +5 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +23 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +3 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +11 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/provider.d.ts +23 -0
- package/dist/src/provider.d.ts.map +1 -0
- package/dist/src/provider.js +105 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/caip.d.ts +18 -0
- package/dist/src/utils/caip.d.ts.map +1 -0
- package/dist/src/utils/caip.js +33 -0
- package/dist/src/utils/caip.js.map +1 -0
- package/dist/src/utils/type-guards.d.ts +50 -0
- package/dist/src/utils/type-guards.d.ts.map +1 -0
- package/dist/src/utils/type-guards.js +64 -0
- package/dist/src/utils/type-guards.js.map +1 -0
- package/dist/types/index.d.ts +21 -11
- package/package.json +6 -6
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { MultichainOptions } from '@metamask/connect-multichain';
|
|
2
|
+
import { EIP1193Provider } from './provider';
|
|
3
|
+
import type { AddEthereumChainParameter, Address, EventHandlers, Hex, MetamaskConnectEVMOptions } from './types';
|
|
4
|
+
/** The options for the connect method */
|
|
5
|
+
type ConnectOptions = {
|
|
6
|
+
/** The account to connect to */
|
|
7
|
+
account?: string | undefined;
|
|
8
|
+
/** Whether to force a request regardless of an existing session */
|
|
9
|
+
forceRequest?: boolean;
|
|
10
|
+
/** All available chain IDs in the dapp */
|
|
11
|
+
chainIds: number[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The MetamaskConnectEVM class provides an EIP-1193 compatible interface for connecting
|
|
15
|
+
* to MetaMask and interacting with Ethereum Virtual Machine (EVM) networks.
|
|
16
|
+
*
|
|
17
|
+
* This class serves as a modern replacement for MetaMask SDK V1, offering enhanced
|
|
18
|
+
* functionality and cross-platform compatibility. It wraps the Multichain SDK to provide
|
|
19
|
+
* a simplified, EIP-1193 compliant API for dapp developers.
|
|
20
|
+
*
|
|
21
|
+
* Key features:
|
|
22
|
+
* - EIP-1193 provider interface for seamless integration with existing dapp code
|
|
23
|
+
* - Automatic session recovery when reloading or opening in new tabs
|
|
24
|
+
* - Chain switching with automatic chain addition if not configured
|
|
25
|
+
* - Event-driven architecture with support for connect, disconnect, accountsChanged, and chainChanged events
|
|
26
|
+
* - Cross-platform support for browser extensions and mobile applications
|
|
27
|
+
* - Built-in handling of common Ethereum methods (eth_accounts, wallet_switchEthereumChain, etc.)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const sdk = await createMetamaskConnectEVM({
|
|
32
|
+
* dapp: { name: 'My DApp', url: 'https://mydapp.com' }
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* await sdk.connect({ chainId: 1 });
|
|
36
|
+
* const provider = await sdk.getProvider();
|
|
37
|
+
* const accounts = await provider.request({ method: 'eth_accounts' });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class MetamaskConnectEVM {
|
|
41
|
+
#private;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new MetamaskConnectEVM instance.
|
|
44
|
+
*
|
|
45
|
+
* @param options - The options for the MetamaskConnectEVM instance
|
|
46
|
+
* @param options.core - The core instance of the Multichain SDK
|
|
47
|
+
* @param options.eventHandlers - Optional event handlers for EIP-1193 provider events
|
|
48
|
+
*/
|
|
49
|
+
constructor({ core, eventHandlers }: MetamaskConnectEVMOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Connects to the wallet with the specified chain ID and optional account.
|
|
52
|
+
*
|
|
53
|
+
* @param options - The connection options
|
|
54
|
+
* @param options.account - Optional specific account to connect to
|
|
55
|
+
* @param options.forceRequest - Wwhether to force a request regardless of an existing session
|
|
56
|
+
* @param options.chainIds - Array of chain IDs to connect to
|
|
57
|
+
* @returns A promise that resolves with the connected accounts and chain ID
|
|
58
|
+
*/
|
|
59
|
+
connect({ account, forceRequest, chainIds }?: ConnectOptions): Promise<{
|
|
60
|
+
accounts: Address[];
|
|
61
|
+
chainId: number;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Connects to the wallet and signs a message using personal_sign.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The connection options
|
|
67
|
+
* @param options.message - The message to sign after connecting
|
|
68
|
+
* @param options.chainIds - Optional chain IDs to connect to (defaults to ethereum mainnet if not provided)
|
|
69
|
+
* @returns A promise that resolves with the signature
|
|
70
|
+
* @throws Error if the selected account is not available after timeout
|
|
71
|
+
*/
|
|
72
|
+
connectAndSign({ message, chainIds, }: {
|
|
73
|
+
message: string;
|
|
74
|
+
chainIds?: number[];
|
|
75
|
+
}): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Connects to the wallet and invokes a method with specified parameters.
|
|
78
|
+
*
|
|
79
|
+
* @param options - The options for connecting and invoking the method
|
|
80
|
+
* @param options.method - The method name to invoke
|
|
81
|
+
* @param options.params - The parameters to pass to the method, or a function that receives the account and returns params
|
|
82
|
+
* @param options.chainIds - Optional chain IDs to connect to (defaults to ethereum mainnet if not provided)
|
|
83
|
+
* @param options.account - Optional specific account to connect to
|
|
84
|
+
* @param options.forceRequest - Whether to force a request regardless of an existing session
|
|
85
|
+
* @returns A promise that resolves with the result of the method invocation
|
|
86
|
+
* @throws Error if the selected account is not available after timeout (for methods that require an account)
|
|
87
|
+
*/
|
|
88
|
+
connectWith({ method, params, chainIds, account, forceRequest, }: {
|
|
89
|
+
method: string;
|
|
90
|
+
params: unknown[] | ((account: Address) => unknown[]);
|
|
91
|
+
chainIds?: number[];
|
|
92
|
+
account?: string | undefined;
|
|
93
|
+
forceRequest?: boolean;
|
|
94
|
+
}): Promise<unknown>;
|
|
95
|
+
/**
|
|
96
|
+
* Disconnects from the wallet by revoking the session and cleaning up event listeners.
|
|
97
|
+
*
|
|
98
|
+
* @returns A promise that resolves when disconnection is complete
|
|
99
|
+
*/
|
|
100
|
+
disconnect(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Switches the Ethereum chain. Will track state internally whenever possible.
|
|
103
|
+
*
|
|
104
|
+
* @param options - The options for the switch chain request
|
|
105
|
+
* @param options.chainId - The chain ID to switch to
|
|
106
|
+
* @param options.chainConfiguration - The chain configuration to use in case the chain is not present by the wallet
|
|
107
|
+
* @returns The result of the switch chain request
|
|
108
|
+
*/
|
|
109
|
+
switchChain({ chainId, chainConfiguration, }: {
|
|
110
|
+
chainId: number | Hex;
|
|
111
|
+
chainConfiguration?: AddEthereumChainParameter;
|
|
112
|
+
}): Promise<unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the EIP-1193 provider instance
|
|
115
|
+
*
|
|
116
|
+
* @returns The EIP-1193 provider instance
|
|
117
|
+
*/
|
|
118
|
+
getProvider(): EIP1193Provider;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the currently selected chain ID on the wallet
|
|
121
|
+
*
|
|
122
|
+
* @returns The currently selected chain ID or undefined if no chain is selected
|
|
123
|
+
*/
|
|
124
|
+
getChainId(): Hex | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the currently selected account on the wallet
|
|
127
|
+
*
|
|
128
|
+
* @returns The currently selected account or undefined if no account is selected
|
|
129
|
+
*/
|
|
130
|
+
getAccount(): Address | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the currently permitted accounts
|
|
133
|
+
*
|
|
134
|
+
* @returns The currently permitted accounts
|
|
135
|
+
*/
|
|
136
|
+
get accounts(): Address[];
|
|
137
|
+
/**
|
|
138
|
+
* Gets the currently selected account on the wallet
|
|
139
|
+
*
|
|
140
|
+
* @returns The currently selected account or undefined if no account is selected
|
|
141
|
+
*/
|
|
142
|
+
get selectedAccount(): Address | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the currently selected chain ID on the wallet
|
|
145
|
+
*
|
|
146
|
+
* @returns The currently selected chain ID or undefined if no chain is selected
|
|
147
|
+
*/
|
|
148
|
+
get selectedChainId(): Hex | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new Metamask Connect/EVM instance
|
|
152
|
+
*
|
|
153
|
+
* @param options - The options for the Metamask Connect/EVM layer
|
|
154
|
+
* @param options.dapp - Dapp identification and branding settings
|
|
155
|
+
* @param options.api - API configuration including read-only RPC map
|
|
156
|
+
* @param options.api.supportedNetworks - A map of CAIP chain IDs to RPC URLs for read-only requests
|
|
157
|
+
* @param options.eventEmitter - The event emitter to use for the Metamask Connect/EVM layer
|
|
158
|
+
* @param options.eventHandlers - The event handlers to use for the Metamask Connect/EVM layer
|
|
159
|
+
* @returns The Metamask Connect/EVM layer instance
|
|
160
|
+
*/
|
|
161
|
+
export declare function createMetamaskConnectEVM(options: Pick<MultichainOptions, 'dapp' | 'api'> & {
|
|
162
|
+
eventHandlers?: Partial<EventHandlers>;
|
|
163
|
+
debug?: boolean;
|
|
164
|
+
}): Promise<MetamaskConnectEVM>;
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/connect.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