@walletconnect/ethereum-provider 2.12.1 → 2.12.2-req-q.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/index.cjs.js +500 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +473 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +39488 -139
- package/dist/index.umd.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,501 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var events = require('events');
|
|
6
|
+
var utils = require('@walletconnect/utils');
|
|
7
|
+
var universalProvider = require('@walletconnect/universal-provider');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n["default"] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const PROTOCOL = "wc";
|
|
28
|
+
const WC_VERSION = 2;
|
|
29
|
+
const CONTEXT = "ethereum_provider";
|
|
30
|
+
const STORAGE_KEY = `${PROTOCOL}@${WC_VERSION}:${CONTEXT}:`;
|
|
31
|
+
const RPC_URL = "https://rpc.walletconnect.com/v1/";
|
|
32
|
+
|
|
33
|
+
const REQUIRED_METHODS = ["eth_sendTransaction", "personal_sign"];
|
|
34
|
+
const OPTIONAL_METHODS = [
|
|
35
|
+
"eth_accounts",
|
|
36
|
+
"eth_requestAccounts",
|
|
37
|
+
"eth_sendRawTransaction",
|
|
38
|
+
"eth_sign",
|
|
39
|
+
"eth_signTransaction",
|
|
40
|
+
"eth_signTypedData",
|
|
41
|
+
"eth_signTypedData_v3",
|
|
42
|
+
"eth_signTypedData_v4",
|
|
43
|
+
"eth_sendTransaction",
|
|
44
|
+
"personal_sign",
|
|
45
|
+
"wallet_switchEthereumChain",
|
|
46
|
+
"wallet_addEthereumChain",
|
|
47
|
+
"wallet_getPermissions",
|
|
48
|
+
"wallet_requestPermissions",
|
|
49
|
+
"wallet_registerOnboarding",
|
|
50
|
+
"wallet_watchAsset",
|
|
51
|
+
"wallet_scanQRCode"
|
|
52
|
+
];
|
|
53
|
+
const REQUIRED_EVENTS = ["chainChanged", "accountsChanged"];
|
|
54
|
+
const OPTIONAL_EVENTS = [
|
|
55
|
+
"chainChanged",
|
|
56
|
+
"accountsChanged",
|
|
57
|
+
"message",
|
|
58
|
+
"disconnect",
|
|
59
|
+
"connect"
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
var __defProp = Object.defineProperty;
|
|
63
|
+
var __defProps = Object.defineProperties;
|
|
64
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
65
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
66
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
67
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
68
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
69
|
+
var __spreadValues = (a, b) => {
|
|
70
|
+
for (var prop in b || (b = {}))
|
|
71
|
+
if (__hasOwnProp.call(b, prop))
|
|
72
|
+
__defNormalProp(a, prop, b[prop]);
|
|
73
|
+
if (__getOwnPropSymbols)
|
|
74
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
75
|
+
if (__propIsEnum.call(b, prop))
|
|
76
|
+
__defNormalProp(a, prop, b[prop]);
|
|
77
|
+
}
|
|
78
|
+
return a;
|
|
79
|
+
};
|
|
80
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
81
|
+
function getEthereumChainId(chains) {
|
|
82
|
+
return Number(chains[0].split(":")[1]);
|
|
83
|
+
}
|
|
84
|
+
function toHexChainId(chainId) {
|
|
85
|
+
return `0x${chainId.toString(16)}`;
|
|
86
|
+
}
|
|
87
|
+
function buildNamespaces(params) {
|
|
88
|
+
const { chains, optionalChains, methods, optionalMethods, events, optionalEvents, rpcMap } = params;
|
|
89
|
+
if (!utils.isValidArray(chains)) {
|
|
90
|
+
throw new Error("Invalid chains");
|
|
91
|
+
}
|
|
92
|
+
const required = {
|
|
93
|
+
chains,
|
|
94
|
+
methods: methods || REQUIRED_METHODS,
|
|
95
|
+
events: events || REQUIRED_EVENTS,
|
|
96
|
+
rpcMap: __spreadValues({}, chains.length ? { [getEthereumChainId(chains)]: rpcMap[getEthereumChainId(chains)] } : {})
|
|
97
|
+
};
|
|
98
|
+
const eventsRequiringPermissions = events == null ? void 0 : events.filter((event) => !REQUIRED_EVENTS.includes(event));
|
|
99
|
+
const methodsRequiringPermissions = methods == null ? void 0 : methods.filter((event) => !REQUIRED_METHODS.includes(event));
|
|
100
|
+
if (!optionalChains && !optionalEvents && !optionalMethods && !(eventsRequiringPermissions == null ? void 0 : eventsRequiringPermissions.length) && !(methodsRequiringPermissions == null ? void 0 : methodsRequiringPermissions.length)) {
|
|
101
|
+
return { required: chains.length ? required : void 0 };
|
|
102
|
+
}
|
|
103
|
+
const shouldIncludeRequiredChains = (eventsRequiringPermissions == null ? void 0 : eventsRequiringPermissions.length) && (methodsRequiringPermissions == null ? void 0 : methodsRequiringPermissions.length) || !optionalChains;
|
|
104
|
+
const optional = {
|
|
105
|
+
chains: [
|
|
106
|
+
...new Set(
|
|
107
|
+
shouldIncludeRequiredChains ? required.chains.concat(optionalChains || []) : optionalChains
|
|
108
|
+
)
|
|
109
|
+
],
|
|
110
|
+
methods: [
|
|
111
|
+
...new Set(
|
|
112
|
+
required.methods.concat((optionalMethods == null ? void 0 : optionalMethods.length) ? optionalMethods : OPTIONAL_METHODS)
|
|
113
|
+
)
|
|
114
|
+
],
|
|
115
|
+
events: [
|
|
116
|
+
...new Set(required.events.concat((optionalEvents == null ? void 0 : optionalEvents.length) ? optionalEvents : OPTIONAL_EVENTS))
|
|
117
|
+
],
|
|
118
|
+
rpcMap
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
required: chains.length ? required : void 0,
|
|
122
|
+
optional: optionalChains.length ? optional : void 0
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
class EthereumProvider$1 {
|
|
126
|
+
constructor() {
|
|
127
|
+
this.events = new events.EventEmitter();
|
|
128
|
+
this.namespace = "eip155";
|
|
129
|
+
this.accounts = [];
|
|
130
|
+
this.chainId = 1;
|
|
131
|
+
this.STORAGE_KEY = STORAGE_KEY;
|
|
132
|
+
this.on = (event, listener) => {
|
|
133
|
+
this.events.on(event, listener);
|
|
134
|
+
return this;
|
|
135
|
+
};
|
|
136
|
+
this.once = (event, listener) => {
|
|
137
|
+
this.events.once(event, listener);
|
|
138
|
+
return this;
|
|
139
|
+
};
|
|
140
|
+
this.removeListener = (event, listener) => {
|
|
141
|
+
this.events.removeListener(event, listener);
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
this.off = (event, listener) => {
|
|
145
|
+
this.events.off(event, listener);
|
|
146
|
+
return this;
|
|
147
|
+
};
|
|
148
|
+
this.parseAccount = (payload) => {
|
|
149
|
+
return this.isCompatibleChainId(payload) ? this.parseAccountId(payload).address : payload;
|
|
150
|
+
};
|
|
151
|
+
this.signer = {};
|
|
152
|
+
this.rpc = {};
|
|
153
|
+
}
|
|
154
|
+
static async init(opts) {
|
|
155
|
+
const provider = new EthereumProvider$1();
|
|
156
|
+
await provider.initialize(opts);
|
|
157
|
+
return provider;
|
|
158
|
+
}
|
|
159
|
+
async request(args, expiry) {
|
|
160
|
+
return await this.signer.request(args, this.formatChainId(this.chainId), expiry);
|
|
161
|
+
}
|
|
162
|
+
sendAsync(args, callback, expiry) {
|
|
163
|
+
this.signer.sendAsync(args, callback, this.formatChainId(this.chainId), expiry);
|
|
164
|
+
}
|
|
165
|
+
get connected() {
|
|
166
|
+
if (!this.signer.client)
|
|
167
|
+
return false;
|
|
168
|
+
return this.signer.client.core.relayer.connected;
|
|
169
|
+
}
|
|
170
|
+
get connecting() {
|
|
171
|
+
if (!this.signer.client)
|
|
172
|
+
return false;
|
|
173
|
+
return this.signer.client.core.relayer.connecting;
|
|
174
|
+
}
|
|
175
|
+
async enable() {
|
|
176
|
+
if (!this.session)
|
|
177
|
+
await this.connect();
|
|
178
|
+
const accounts = await this.request({ method: "eth_requestAccounts" });
|
|
179
|
+
return accounts;
|
|
180
|
+
}
|
|
181
|
+
async connect(opts) {
|
|
182
|
+
if (!this.signer.client) {
|
|
183
|
+
throw new Error("Provider not initialized. Call init() first");
|
|
184
|
+
}
|
|
185
|
+
this.loadConnectOpts(opts);
|
|
186
|
+
const { required, optional } = buildNamespaces(this.rpc);
|
|
187
|
+
try {
|
|
188
|
+
const session = await new Promise(
|
|
189
|
+
async (resolve, reject) => {
|
|
190
|
+
var _a;
|
|
191
|
+
if (this.rpc.showQrModal) {
|
|
192
|
+
(_a = this.modal) == null ? void 0 : _a.subscribeModal((state) => {
|
|
193
|
+
if (!state.open && !this.signer.session) {
|
|
194
|
+
this.signer.abortPairingAttempt();
|
|
195
|
+
reject(new Error("Connection request reset. Please try again."));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
await this.signer.connect(__spreadProps(__spreadValues({
|
|
200
|
+
namespaces: __spreadValues({}, required && {
|
|
201
|
+
[this.namespace]: required
|
|
202
|
+
})
|
|
203
|
+
}, optional && {
|
|
204
|
+
optionalNamespaces: {
|
|
205
|
+
[this.namespace]: optional
|
|
206
|
+
}
|
|
207
|
+
}), {
|
|
208
|
+
pairingTopic: opts == null ? void 0 : opts.pairingTopic
|
|
209
|
+
})).then((session2) => {
|
|
210
|
+
resolve(session2);
|
|
211
|
+
}).catch((error) => {
|
|
212
|
+
reject(new Error(error.message));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
if (!session)
|
|
217
|
+
return;
|
|
218
|
+
const accounts = utils.getAccountsFromNamespaces(session.namespaces, [this.namespace]);
|
|
219
|
+
this.setChainIds(this.rpc.chains.length ? this.rpc.chains : accounts);
|
|
220
|
+
this.setAccounts(accounts);
|
|
221
|
+
this.events.emit("connect", { chainId: toHexChainId(this.chainId) });
|
|
222
|
+
} catch (error) {
|
|
223
|
+
this.signer.logger.error(error);
|
|
224
|
+
throw error;
|
|
225
|
+
} finally {
|
|
226
|
+
if (this.modal)
|
|
227
|
+
this.modal.closeModal();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async authenticate(params) {
|
|
231
|
+
if (!this.signer.client) {
|
|
232
|
+
throw new Error("Provider not initialized. Call init() first");
|
|
233
|
+
}
|
|
234
|
+
this.loadConnectOpts({
|
|
235
|
+
chains: params == null ? void 0 : params.chains
|
|
236
|
+
});
|
|
237
|
+
try {
|
|
238
|
+
const result = await new Promise(
|
|
239
|
+
async (resolve, reject) => {
|
|
240
|
+
var _a;
|
|
241
|
+
if (this.rpc.showQrModal) {
|
|
242
|
+
(_a = this.modal) == null ? void 0 : _a.subscribeModal((state) => {
|
|
243
|
+
if (!state.open && !this.signer.session) {
|
|
244
|
+
this.signer.abortPairingAttempt();
|
|
245
|
+
reject(new Error("Connection request reset. Please try again."));
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
await this.signer.authenticate(__spreadProps(__spreadValues({}, params), {
|
|
250
|
+
chains: this.rpc.chains
|
|
251
|
+
})).then((result2) => {
|
|
252
|
+
resolve(result2);
|
|
253
|
+
}).catch((error) => {
|
|
254
|
+
reject(new Error(error.message));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
const session = result.session;
|
|
259
|
+
if (session) {
|
|
260
|
+
const accounts = utils.getAccountsFromNamespaces(session.namespaces, [this.namespace]);
|
|
261
|
+
this.setChainIds(this.rpc.chains.length ? this.rpc.chains : accounts);
|
|
262
|
+
this.setAccounts(accounts);
|
|
263
|
+
this.events.emit("connect", { chainId: toHexChainId(this.chainId) });
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
this.signer.logger.error(error);
|
|
268
|
+
throw error;
|
|
269
|
+
} finally {
|
|
270
|
+
if (this.modal)
|
|
271
|
+
this.modal.closeModal();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async disconnect() {
|
|
275
|
+
if (this.session) {
|
|
276
|
+
await this.signer.disconnect();
|
|
277
|
+
}
|
|
278
|
+
this.reset();
|
|
279
|
+
}
|
|
280
|
+
get isWalletConnect() {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
get session() {
|
|
284
|
+
return this.signer.session;
|
|
285
|
+
}
|
|
286
|
+
// ---------- Protected --------------------------------------------- //
|
|
287
|
+
registerEventListeners() {
|
|
288
|
+
this.signer.on("session_event", (payload) => {
|
|
289
|
+
const { params } = payload;
|
|
290
|
+
const { event } = params;
|
|
291
|
+
if (event.name === "accountsChanged") {
|
|
292
|
+
this.accounts = this.parseAccounts(event.data);
|
|
293
|
+
this.events.emit("accountsChanged", this.accounts);
|
|
294
|
+
} else if (event.name === "chainChanged") {
|
|
295
|
+
this.setChainId(this.formatChainId(event.data));
|
|
296
|
+
} else {
|
|
297
|
+
this.events.emit(event.name, event.data);
|
|
298
|
+
}
|
|
299
|
+
this.events.emit("session_event", payload);
|
|
300
|
+
});
|
|
301
|
+
this.signer.on("chainChanged", (chainId) => {
|
|
302
|
+
const chain = parseInt(chainId);
|
|
303
|
+
this.chainId = chain;
|
|
304
|
+
this.events.emit("chainChanged", toHexChainId(this.chainId));
|
|
305
|
+
this.persist();
|
|
306
|
+
});
|
|
307
|
+
this.signer.on(
|
|
308
|
+
"session_update",
|
|
309
|
+
(payload) => {
|
|
310
|
+
this.events.emit("session_update", payload);
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
this.signer.on(
|
|
314
|
+
"session_delete",
|
|
315
|
+
(payload) => {
|
|
316
|
+
this.reset();
|
|
317
|
+
this.events.emit("session_delete", payload);
|
|
318
|
+
this.events.emit("disconnect", __spreadProps(__spreadValues({}, utils.getSdkError("USER_DISCONNECTED")), {
|
|
319
|
+
data: payload.topic,
|
|
320
|
+
name: "USER_DISCONNECTED"
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
this.signer.on("display_uri", (uri) => {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
if (this.rpc.showQrModal) {
|
|
327
|
+
(_a = this.modal) == null ? void 0 : _a.closeModal();
|
|
328
|
+
(_b = this.modal) == null ? void 0 : _b.openModal({ uri });
|
|
329
|
+
}
|
|
330
|
+
this.events.emit("display_uri", uri);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
switchEthereumChain(chainId) {
|
|
334
|
+
this.request({
|
|
335
|
+
method: "wallet_switchEthereumChain",
|
|
336
|
+
params: [{ chainId: chainId.toString(16) }]
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
isCompatibleChainId(chainId) {
|
|
340
|
+
return typeof chainId === "string" ? chainId.startsWith(`${this.namespace}:`) : false;
|
|
341
|
+
}
|
|
342
|
+
formatChainId(chainId) {
|
|
343
|
+
return `${this.namespace}:${chainId}`;
|
|
344
|
+
}
|
|
345
|
+
parseChainId(chainId) {
|
|
346
|
+
return Number(chainId.split(":")[1]);
|
|
347
|
+
}
|
|
348
|
+
setChainIds(chains) {
|
|
349
|
+
const compatible = chains.filter((x) => this.isCompatibleChainId(x));
|
|
350
|
+
const chainIds = compatible.map((c) => this.parseChainId(c));
|
|
351
|
+
if (chainIds.length) {
|
|
352
|
+
this.chainId = chainIds[0];
|
|
353
|
+
this.events.emit("chainChanged", toHexChainId(this.chainId));
|
|
354
|
+
this.persist();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
setChainId(chain) {
|
|
358
|
+
if (this.isCompatibleChainId(chain)) {
|
|
359
|
+
const chainId = this.parseChainId(chain);
|
|
360
|
+
this.chainId = chainId;
|
|
361
|
+
this.switchEthereumChain(chainId);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
parseAccountId(account) {
|
|
365
|
+
const [namespace, reference, address] = account.split(":");
|
|
366
|
+
const chainId = `${namespace}:${reference}`;
|
|
367
|
+
return { chainId, address };
|
|
368
|
+
}
|
|
369
|
+
setAccounts(accounts) {
|
|
370
|
+
this.accounts = accounts.filter((x) => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId).map((x) => this.parseAccountId(x).address);
|
|
371
|
+
this.events.emit("accountsChanged", this.accounts);
|
|
372
|
+
}
|
|
373
|
+
getRpcConfig(opts) {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
const requiredChains = (_a = opts == null ? void 0 : opts.chains) != null ? _a : [];
|
|
376
|
+
const optionalChains = (_b = opts == null ? void 0 : opts.optionalChains) != null ? _b : [];
|
|
377
|
+
const allChains = requiredChains.concat(optionalChains);
|
|
378
|
+
if (!allChains.length)
|
|
379
|
+
throw new Error("No chains specified in either `chains` or `optionalChains`");
|
|
380
|
+
const requiredMethods = requiredChains.length ? (opts == null ? void 0 : opts.methods) || REQUIRED_METHODS : [];
|
|
381
|
+
const requiredEvents = requiredChains.length ? (opts == null ? void 0 : opts.events) || REQUIRED_EVENTS : [];
|
|
382
|
+
const optionalMethods = (opts == null ? void 0 : opts.optionalMethods) || [];
|
|
383
|
+
const optionalEvents = (opts == null ? void 0 : opts.optionalEvents) || [];
|
|
384
|
+
const rpcMap = (opts == null ? void 0 : opts.rpcMap) || this.buildRpcMap(allChains, opts.projectId);
|
|
385
|
+
const qrModalOptions = (opts == null ? void 0 : opts.qrModalOptions) || void 0;
|
|
386
|
+
return {
|
|
387
|
+
chains: requiredChains == null ? void 0 : requiredChains.map((chain) => this.formatChainId(chain)),
|
|
388
|
+
optionalChains: optionalChains.map((chain) => this.formatChainId(chain)),
|
|
389
|
+
methods: requiredMethods,
|
|
390
|
+
events: requiredEvents,
|
|
391
|
+
optionalMethods,
|
|
392
|
+
optionalEvents,
|
|
393
|
+
rpcMap,
|
|
394
|
+
showQrModal: Boolean(opts == null ? void 0 : opts.showQrModal),
|
|
395
|
+
qrModalOptions,
|
|
396
|
+
projectId: opts.projectId,
|
|
397
|
+
metadata: opts.metadata
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
buildRpcMap(chains, projectId) {
|
|
401
|
+
const map = {};
|
|
402
|
+
chains.forEach((chain) => {
|
|
403
|
+
map[chain] = this.getRpcUrl(chain, projectId);
|
|
404
|
+
});
|
|
405
|
+
return map;
|
|
406
|
+
}
|
|
407
|
+
async initialize(opts) {
|
|
408
|
+
this.rpc = this.getRpcConfig(opts);
|
|
409
|
+
this.chainId = this.rpc.chains.length ? getEthereumChainId(this.rpc.chains) : getEthereumChainId(this.rpc.optionalChains);
|
|
410
|
+
this.signer = await universalProvider.UniversalProvider.init({
|
|
411
|
+
projectId: this.rpc.projectId,
|
|
412
|
+
metadata: this.rpc.metadata,
|
|
413
|
+
disableProviderPing: opts.disableProviderPing,
|
|
414
|
+
relayUrl: opts.relayUrl,
|
|
415
|
+
storageOptions: opts.storageOptions
|
|
416
|
+
});
|
|
417
|
+
this.registerEventListeners();
|
|
418
|
+
await this.loadPersistedSession();
|
|
419
|
+
if (this.rpc.showQrModal) {
|
|
420
|
+
let WalletConnectModalClass;
|
|
421
|
+
try {
|
|
422
|
+
const { WalletConnectModal } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@walletconnect/modal')); });
|
|
423
|
+
WalletConnectModalClass = WalletConnectModal;
|
|
424
|
+
} catch (e) {
|
|
425
|
+
throw new Error("To use QR modal, please install @walletconnect/modal package");
|
|
426
|
+
}
|
|
427
|
+
if (WalletConnectModalClass) {
|
|
428
|
+
try {
|
|
429
|
+
this.modal = new WalletConnectModalClass(__spreadValues({
|
|
430
|
+
projectId: this.rpc.projectId
|
|
431
|
+
}, this.rpc.qrModalOptions));
|
|
432
|
+
} catch (e) {
|
|
433
|
+
this.signer.logger.error(e);
|
|
434
|
+
throw new Error("Could not generate WalletConnectModal Instance");
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
loadConnectOpts(opts) {
|
|
440
|
+
if (!opts)
|
|
441
|
+
return;
|
|
442
|
+
const { chains, optionalChains, rpcMap } = opts;
|
|
443
|
+
if (chains && utils.isValidArray(chains)) {
|
|
444
|
+
this.rpc.chains = chains.map((chain) => this.formatChainId(chain));
|
|
445
|
+
chains.forEach((chain) => {
|
|
446
|
+
this.rpc.rpcMap[chain] = (rpcMap == null ? void 0 : rpcMap[chain]) || this.getRpcUrl(chain);
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (optionalChains && utils.isValidArray(optionalChains)) {
|
|
450
|
+
this.rpc.optionalChains = [];
|
|
451
|
+
this.rpc.optionalChains = optionalChains == null ? void 0 : optionalChains.map((chain) => this.formatChainId(chain));
|
|
452
|
+
optionalChains.forEach((chain) => {
|
|
453
|
+
this.rpc.rpcMap[chain] = (rpcMap == null ? void 0 : rpcMap[chain]) || this.getRpcUrl(chain);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
getRpcUrl(chainId, projectId) {
|
|
458
|
+
var _a;
|
|
459
|
+
const providedRpc = (_a = this.rpc.rpcMap) == null ? void 0 : _a[chainId];
|
|
460
|
+
return providedRpc || `${RPC_URL}?chainId=eip155:${chainId}&projectId=${projectId || this.rpc.projectId}`;
|
|
461
|
+
}
|
|
462
|
+
async loadPersistedSession() {
|
|
463
|
+
if (!this.session)
|
|
464
|
+
return;
|
|
465
|
+
try {
|
|
466
|
+
const chainId = await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);
|
|
467
|
+
const namespace = this.session.namespaces[`${this.namespace}:${chainId}`] ? this.session.namespaces[`${this.namespace}:${chainId}`] : this.session.namespaces[this.namespace];
|
|
468
|
+
this.setChainIds(chainId ? [this.formatChainId(chainId)] : namespace == null ? void 0 : namespace.accounts);
|
|
469
|
+
this.setAccounts(namespace == null ? void 0 : namespace.accounts);
|
|
470
|
+
} catch (error) {
|
|
471
|
+
this.signer.logger.error("Failed to load persisted session, clearing state...");
|
|
472
|
+
this.signer.logger.error(error);
|
|
473
|
+
await this.disconnect().catch((error2) => this.signer.logger.warn(error2));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
reset() {
|
|
477
|
+
this.chainId = 1;
|
|
478
|
+
this.accounts = [];
|
|
479
|
+
}
|
|
480
|
+
persist() {
|
|
481
|
+
if (!this.session)
|
|
482
|
+
return;
|
|
483
|
+
this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`, this.chainId);
|
|
484
|
+
}
|
|
485
|
+
parseAccounts(payload) {
|
|
486
|
+
if (typeof payload === "string" || payload instanceof String) {
|
|
487
|
+
return [this.parseAccount(payload)];
|
|
488
|
+
}
|
|
489
|
+
return payload.map((account) => this.parseAccount(account));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const EthereumProvider = EthereumProvider$1;
|
|
494
|
+
|
|
495
|
+
exports.EthereumProvider = EthereumProvider;
|
|
496
|
+
exports.OPTIONAL_EVENTS = OPTIONAL_EVENTS;
|
|
497
|
+
exports.OPTIONAL_METHODS = OPTIONAL_METHODS;
|
|
498
|
+
exports.REQUIRED_EVENTS = REQUIRED_EVENTS;
|
|
499
|
+
exports.REQUIRED_METHODS = REQUIRED_METHODS;
|
|
500
|
+
exports["default"] = EthereumProvider$1;
|
|
2
501
|
//# sourceMappingURL=index.cjs.js.map
|