@wagmi/connectors 1.0.0-next.4 → 1.0.0-next.6
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/base-a11da01a.d.ts +132 -0
- package/dist/chunk-K4TVWOJP.js +370 -0
- package/dist/chunk-OQILYQDO.js +15 -0
- package/dist/chunk-QYMCVNHT.js +68 -0
- package/dist/chunk-ZCAPXGBX.js +26 -0
- package/dist/coinbaseWallet.d.ts +831 -1
- package/dist/coinbaseWallet.js +215 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +12 -0
- package/dist/injected.d.ts +833 -1
- package/dist/injected.js +9 -0
- package/dist/ledger.d.ts +810 -1
- package/dist/ledger.js +192 -0
- package/dist/metaMask.d.ts +37 -1
- package/dist/metaMask.js +139 -0
- package/dist/mock/index.d.ts +1578 -1
- package/dist/mock/index.js +202 -0
- package/dist/safe.d.ts +822 -1
- package/dist/safe.js +128 -0
- package/dist/walletConnect.d.ts +917 -1
- package/dist/walletConnect.js +311 -0
- package/dist/walletConnectLegacy.d.ts +811 -1
- package/dist/walletConnectLegacy.js +178 -0
- package/package.json +9 -9
package/dist/ledger.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeChainId
|
|
3
|
+
} from "./chunk-OQILYQDO.js";
|
|
4
|
+
import {
|
|
5
|
+
Connector,
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet,
|
|
10
|
+
__publicField
|
|
11
|
+
} from "./chunk-QYMCVNHT.js";
|
|
12
|
+
|
|
13
|
+
// src/ledger.ts
|
|
14
|
+
import {
|
|
15
|
+
SupportedProviders,
|
|
16
|
+
loadConnectKit
|
|
17
|
+
} from "@ledgerhq/connect-kit-loader";
|
|
18
|
+
import {
|
|
19
|
+
SwitchChainError,
|
|
20
|
+
UserRejectedRequestError,
|
|
21
|
+
createWalletClient,
|
|
22
|
+
custom,
|
|
23
|
+
getAddress,
|
|
24
|
+
numberToHex
|
|
25
|
+
} from "viem";
|
|
26
|
+
var _provider, _switchChain, switchChain_fn;
|
|
27
|
+
var LedgerConnector = class extends Connector {
|
|
28
|
+
constructor({
|
|
29
|
+
chains,
|
|
30
|
+
options = { enableDebugLogs: false }
|
|
31
|
+
} = {}) {
|
|
32
|
+
super({ chains, options });
|
|
33
|
+
__privateAdd(this, _switchChain);
|
|
34
|
+
__publicField(this, "id", "ledger");
|
|
35
|
+
__publicField(this, "name", "Ledger");
|
|
36
|
+
__publicField(this, "ready", true);
|
|
37
|
+
__privateAdd(this, _provider, void 0);
|
|
38
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
39
|
+
if (accounts.length === 0)
|
|
40
|
+
this.emit("disconnect");
|
|
41
|
+
else
|
|
42
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
43
|
+
});
|
|
44
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
45
|
+
const id = normalizeChainId(chainId);
|
|
46
|
+
const unsupported = this.isChainUnsupported(id);
|
|
47
|
+
this.emit("change", { chain: { id, unsupported } });
|
|
48
|
+
});
|
|
49
|
+
__publicField(this, "onDisconnect", () => {
|
|
50
|
+
this.emit("disconnect");
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async connect() {
|
|
54
|
+
try {
|
|
55
|
+
const provider = await this.getProvider({ create: true });
|
|
56
|
+
if (provider.on) {
|
|
57
|
+
provider.on("accountsChanged", this.onAccountsChanged);
|
|
58
|
+
provider.on("chainChanged", this.onChainChanged);
|
|
59
|
+
provider.on("disconnect", this.onDisconnect);
|
|
60
|
+
}
|
|
61
|
+
this.emit("message", { type: "connecting" });
|
|
62
|
+
const accounts = await provider.request({
|
|
63
|
+
method: "eth_requestAccounts"
|
|
64
|
+
});
|
|
65
|
+
const account = getAddress(accounts[0]);
|
|
66
|
+
const id = await this.getChainId();
|
|
67
|
+
const unsupported = this.isChainUnsupported(id);
|
|
68
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
69
|
+
return {
|
|
70
|
+
account,
|
|
71
|
+
chain: { id, unsupported }
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error.code === 4001) {
|
|
75
|
+
throw new UserRejectedRequestError(error);
|
|
76
|
+
}
|
|
77
|
+
if (error.code === -32002) {
|
|
78
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async disconnect() {
|
|
84
|
+
const provider = await this.getProvider();
|
|
85
|
+
if (provider?.disconnect) {
|
|
86
|
+
await provider.disconnect();
|
|
87
|
+
}
|
|
88
|
+
if (provider?.removeListener) {
|
|
89
|
+
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
90
|
+
provider.removeListener("chainChanged", this.onChainChanged);
|
|
91
|
+
provider.removeListener("disconnect", this.onDisconnect);
|
|
92
|
+
}
|
|
93
|
+
typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
|
|
94
|
+
}
|
|
95
|
+
async getAccount() {
|
|
96
|
+
const provider = await this.getProvider();
|
|
97
|
+
const accounts = await provider.request({
|
|
98
|
+
method: "eth_accounts"
|
|
99
|
+
});
|
|
100
|
+
const account = getAddress(accounts[0]);
|
|
101
|
+
return account;
|
|
102
|
+
}
|
|
103
|
+
async getChainId() {
|
|
104
|
+
const provider = await this.getProvider();
|
|
105
|
+
const chainId = await provider.request({
|
|
106
|
+
method: "eth_chainId"
|
|
107
|
+
});
|
|
108
|
+
return normalizeChainId(chainId);
|
|
109
|
+
}
|
|
110
|
+
async getProvider({ chainId, create } = {
|
|
111
|
+
create: false
|
|
112
|
+
}) {
|
|
113
|
+
if (!__privateGet(this, _provider) || chainId || create) {
|
|
114
|
+
const connectKit = await loadConnectKit();
|
|
115
|
+
if (this.options.enableDebugLogs) {
|
|
116
|
+
connectKit.enableDebugLogs();
|
|
117
|
+
}
|
|
118
|
+
const rpc = this.chains.reduce(
|
|
119
|
+
(rpc2, chain) => ({
|
|
120
|
+
...rpc2,
|
|
121
|
+
[chain.id]: chain.rpcUrls.default.http[0]
|
|
122
|
+
}),
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
connectKit.checkSupport({
|
|
126
|
+
bridge: this.options.bridge,
|
|
127
|
+
providerType: SupportedProviders.Ethereum,
|
|
128
|
+
chainId: chainId || this.options.chainId,
|
|
129
|
+
rpc: { ...rpc, ...this.options?.rpc }
|
|
130
|
+
});
|
|
131
|
+
__privateSet(this, _provider, await connectKit.getProvider());
|
|
132
|
+
}
|
|
133
|
+
return __privateGet(this, _provider);
|
|
134
|
+
}
|
|
135
|
+
async getWalletClient({ chainId } = {}) {
|
|
136
|
+
const [provider, account] = await Promise.all([
|
|
137
|
+
this.getProvider({ chainId }),
|
|
138
|
+
this.getAccount()
|
|
139
|
+
]);
|
|
140
|
+
const chain = this.chains.find((x) => x.id === chainId) || this.chains[0];
|
|
141
|
+
if (!provider)
|
|
142
|
+
throw new Error("provider is required.");
|
|
143
|
+
return createWalletClient({
|
|
144
|
+
account,
|
|
145
|
+
chain,
|
|
146
|
+
transport: custom(provider)
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async isAuthorized() {
|
|
150
|
+
try {
|
|
151
|
+
const account = await this.getAccount();
|
|
152
|
+
return !!account;
|
|
153
|
+
} catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
_provider = new WeakMap();
|
|
159
|
+
_switchChain = new WeakSet();
|
|
160
|
+
switchChain_fn = async function(chainId) {
|
|
161
|
+
const provider = await this.getProvider();
|
|
162
|
+
const id = numberToHex(chainId);
|
|
163
|
+
try {
|
|
164
|
+
await Promise.race([
|
|
165
|
+
provider.request({
|
|
166
|
+
method: "wallet_switchEthereumChain",
|
|
167
|
+
params: [{ chainId: id }]
|
|
168
|
+
}),
|
|
169
|
+
new Promise(
|
|
170
|
+
(res) => this.on("change", ({ chain }) => {
|
|
171
|
+
if (chain?.id === chainId)
|
|
172
|
+
res(chainId);
|
|
173
|
+
})
|
|
174
|
+
)
|
|
175
|
+
]);
|
|
176
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
177
|
+
id: chainId,
|
|
178
|
+
name: `Chain ${id}`,
|
|
179
|
+
network: `${id}`,
|
|
180
|
+
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
181
|
+
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
182
|
+
};
|
|
183
|
+
} catch (error) {
|
|
184
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
185
|
+
if (/user rejected request/i.test(message))
|
|
186
|
+
throw new UserRejectedRequestError(error);
|
|
187
|
+
throw new SwitchChainError(error);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
export {
|
|
191
|
+
LedgerConnector
|
|
192
|
+
};
|
package/dist/metaMask.d.ts
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { Chain } from '@wagmi/chains';
|
|
2
|
+
import { InjectedConnectorOptions, InjectedConnector } from './injected.js';
|
|
3
|
+
import { W as WindowProvider } from './base-a11da01a.js';
|
|
4
|
+
import 'abitype/dist/abi-7aa1f183';
|
|
5
|
+
import 'viem/dist/types/types/eip1193';
|
|
6
|
+
import 'viem/dist/types/types';
|
|
7
|
+
import 'viem';
|
|
8
|
+
import 'abitype';
|
|
9
|
+
import 'eventemitter3';
|
|
10
|
+
|
|
11
|
+
type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimDisconnect'> & {
|
|
12
|
+
/**
|
|
13
|
+
* While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
|
|
14
|
+
*/
|
|
15
|
+
UNSTABLE_shimOnConnectSelectAccount?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare class MetaMaskConnector extends InjectedConnector {
|
|
18
|
+
#private;
|
|
19
|
+
readonly id = "metaMask";
|
|
20
|
+
protected shimDisconnectKey: string;
|
|
21
|
+
constructor({ chains, options: options_, }?: {
|
|
22
|
+
chains?: Chain[];
|
|
23
|
+
options?: MetaMaskConnectorOptions;
|
|
24
|
+
});
|
|
25
|
+
connect({ chainId }?: {
|
|
26
|
+
chainId?: number;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
account: `0x${string}`;
|
|
29
|
+
chain: {
|
|
30
|
+
id: number;
|
|
31
|
+
unsupported: boolean;
|
|
32
|
+
};
|
|
33
|
+
provider: WindowProvider;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { MetaMaskConnector, MetaMaskConnectorOptions };
|
package/dist/metaMask.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-K4TVWOJP.js";
|
|
4
|
+
import {
|
|
5
|
+
ConnectorNotFoundError
|
|
6
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
7
|
+
import "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet,
|
|
12
|
+
__publicField
|
|
13
|
+
} from "./chunk-QYMCVNHT.js";
|
|
14
|
+
|
|
15
|
+
// src/metaMask.ts
|
|
16
|
+
import {
|
|
17
|
+
ResourceNotFoundRpcError,
|
|
18
|
+
UserRejectedRequestError,
|
|
19
|
+
getAddress
|
|
20
|
+
} from "viem";
|
|
21
|
+
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
22
|
+
var MetaMaskConnector = class extends InjectedConnector {
|
|
23
|
+
constructor({
|
|
24
|
+
chains,
|
|
25
|
+
options: options_
|
|
26
|
+
} = {}) {
|
|
27
|
+
const options = {
|
|
28
|
+
name: "MetaMask",
|
|
29
|
+
shimDisconnect: true,
|
|
30
|
+
getProvider() {
|
|
31
|
+
function getReady(ethereum2) {
|
|
32
|
+
const isMetaMask = !!ethereum2?.isMetaMask;
|
|
33
|
+
if (!isMetaMask)
|
|
34
|
+
return;
|
|
35
|
+
if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
|
|
36
|
+
return;
|
|
37
|
+
if (ethereum2.isApexWallet)
|
|
38
|
+
return;
|
|
39
|
+
if (ethereum2.isAvalanche)
|
|
40
|
+
return;
|
|
41
|
+
if (ethereum2.isBitKeep)
|
|
42
|
+
return;
|
|
43
|
+
if (ethereum2.isBlockWallet)
|
|
44
|
+
return;
|
|
45
|
+
if (ethereum2.isKuCoinWallet)
|
|
46
|
+
return;
|
|
47
|
+
if (ethereum2.isMathWallet)
|
|
48
|
+
return;
|
|
49
|
+
if (ethereum2.isOkxWallet || ethereum2.isOKExWallet)
|
|
50
|
+
return;
|
|
51
|
+
if (ethereum2.isOneInchIOSWallet || ethereum2.isOneInchAndroidWallet)
|
|
52
|
+
return;
|
|
53
|
+
if (ethereum2.isOpera)
|
|
54
|
+
return;
|
|
55
|
+
if (ethereum2.isPortal)
|
|
56
|
+
return;
|
|
57
|
+
if (ethereum2.isRabby)
|
|
58
|
+
return;
|
|
59
|
+
if (ethereum2.isTokenPocket)
|
|
60
|
+
return;
|
|
61
|
+
if (ethereum2.isTokenary)
|
|
62
|
+
return;
|
|
63
|
+
if (ethereum2.isZerion)
|
|
64
|
+
return;
|
|
65
|
+
return ethereum2;
|
|
66
|
+
}
|
|
67
|
+
if (typeof window === "undefined")
|
|
68
|
+
return;
|
|
69
|
+
const ethereum = window.ethereum;
|
|
70
|
+
if (ethereum?.providers)
|
|
71
|
+
return ethereum.providers.find(getReady);
|
|
72
|
+
return getReady(ethereum);
|
|
73
|
+
},
|
|
74
|
+
...options_
|
|
75
|
+
};
|
|
76
|
+
super({ chains, options });
|
|
77
|
+
__publicField(this, "id", "metaMask");
|
|
78
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
79
|
+
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
80
|
+
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
81
|
+
}
|
|
82
|
+
async connect({ chainId } = {}) {
|
|
83
|
+
try {
|
|
84
|
+
const provider = await this.getProvider();
|
|
85
|
+
if (!provider)
|
|
86
|
+
throw new ConnectorNotFoundError();
|
|
87
|
+
if (provider.on) {
|
|
88
|
+
provider.on("accountsChanged", this.onAccountsChanged);
|
|
89
|
+
provider.on("chainChanged", this.onChainChanged);
|
|
90
|
+
provider.on("disconnect", this.onDisconnect);
|
|
91
|
+
}
|
|
92
|
+
this.emit("message", { type: "connecting" });
|
|
93
|
+
let account = null;
|
|
94
|
+
if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
|
|
95
|
+
account = await this.getAccount().catch(() => null);
|
|
96
|
+
const isConnected = !!account;
|
|
97
|
+
if (isConnected)
|
|
98
|
+
try {
|
|
99
|
+
await provider.request({
|
|
100
|
+
method: "wallet_requestPermissions",
|
|
101
|
+
params: [{ eth_accounts: {} }]
|
|
102
|
+
});
|
|
103
|
+
account = await this.getAccount();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (this.isUserRejectedRequestError(error))
|
|
106
|
+
throw new UserRejectedRequestError(error);
|
|
107
|
+
if (error.code === new ResourceNotFoundRpcError(error).code)
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!account) {
|
|
112
|
+
const accounts = await provider.request({
|
|
113
|
+
method: "eth_requestAccounts"
|
|
114
|
+
});
|
|
115
|
+
account = getAddress(accounts[0]);
|
|
116
|
+
}
|
|
117
|
+
let id = await this.getChainId();
|
|
118
|
+
let unsupported = this.isChainUnsupported(id);
|
|
119
|
+
if (chainId && id !== chainId) {
|
|
120
|
+
const chain = await this.switchChain(chainId);
|
|
121
|
+
id = chain.id;
|
|
122
|
+
unsupported = this.isChainUnsupported(id);
|
|
123
|
+
}
|
|
124
|
+
if (this.options?.shimDisconnect)
|
|
125
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
126
|
+
return { account, chain: { id, unsupported }, provider };
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (this.isUserRejectedRequestError(error))
|
|
129
|
+
throw new UserRejectedRequestError(error);
|
|
130
|
+
if (error.code === -32002)
|
|
131
|
+
throw new ResourceNotFoundRpcError(error);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
137
|
+
export {
|
|
138
|
+
MetaMaskConnector
|
|
139
|
+
};
|