@keplr-wallet/provider 0.12.119 → 0.12.120-rc.1
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/build/core.d.ts +5 -1
- package/build/core.js +672 -136
- package/build/core.js.map +1 -1
- package/build/inject.js +3 -0
- package/build/inject.js.map +1 -1
- package/package.json +4 -4
- package/src/core.ts +945 -297
- package/src/inject.ts +4 -0
package/build/core.js
CHANGED
@@ -27,7 +27,7 @@ class Keplr {
|
|
27
27
|
this.requester = requester;
|
28
28
|
this.enigmaUtils = new Map();
|
29
29
|
this.defaultOptions = {};
|
30
|
-
this.ethereum = new EthereumProvider(this.requester);
|
30
|
+
this.ethereum = new EthereumProvider(this, this.requester);
|
31
31
|
}
|
32
32
|
ping() {
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -35,11 +35,31 @@ class Keplr {
|
|
35
35
|
});
|
36
36
|
}
|
37
37
|
enable(chainIds) {
|
38
|
+
if (typeof chainIds === "string") {
|
39
|
+
chainIds = [chainIds];
|
40
|
+
}
|
41
|
+
return new Promise((resolve, reject) => {
|
42
|
+
let f = false;
|
43
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "permission-interactive", "enable-access", {
|
44
|
+
chainIds,
|
45
|
+
})
|
46
|
+
.then(resolve)
|
47
|
+
.catch(reject)
|
48
|
+
.finally(() => (f = true));
|
49
|
+
setTimeout(() => {
|
50
|
+
if (!f) {
|
51
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
52
|
+
}
|
53
|
+
}, 100);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
// TODO: 웹페이지에서도 필요할수도 있을 것 같으니 나중에 keplr의 API로 추가해준다.
|
57
|
+
isEnabled(chainIds) {
|
38
58
|
return __awaiter(this, void 0, void 0, function* () {
|
39
59
|
if (typeof chainIds === "string") {
|
40
60
|
chainIds = [chainIds];
|
41
61
|
}
|
42
|
-
yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "permission-interactive", "
|
62
|
+
return yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "permission-interactive", "is-enabled-access", {
|
43
63
|
chainIds,
|
44
64
|
});
|
45
65
|
});
|
@@ -49,8 +69,19 @@ class Keplr {
|
|
49
69
|
if (typeof chainIds === "string") {
|
50
70
|
chainIds = [chainIds];
|
51
71
|
}
|
52
|
-
|
53
|
-
|
72
|
+
return new Promise((resolve, reject) => {
|
73
|
+
let f = false;
|
74
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "permission-interactive", "disable-access", {
|
75
|
+
chainIds: chainIds !== null && chainIds !== void 0 ? chainIds : [],
|
76
|
+
})
|
77
|
+
.then(resolve)
|
78
|
+
.catch(reject)
|
79
|
+
.finally(() => (f = true));
|
80
|
+
setTimeout(() => {
|
81
|
+
if (!f) {
|
82
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
83
|
+
}
|
84
|
+
}, 100);
|
54
85
|
});
|
55
86
|
});
|
56
87
|
}
|
@@ -75,39 +106,98 @@ class Keplr {
|
|
75
106
|
console.warn("The `coinType` field of the `ChainInfo` is removed. This is automatically handled as of right now, but the upcoming update would potentially cause errors.");
|
76
107
|
delete chainInfo.coinType;
|
77
108
|
}
|
78
|
-
return
|
79
|
-
|
109
|
+
return new Promise((resolve, reject) => {
|
110
|
+
let f = false;
|
111
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "chains", "suggest-chain-info", {
|
112
|
+
chainInfo,
|
113
|
+
})
|
114
|
+
.then(resolve)
|
115
|
+
.catch(reject)
|
116
|
+
.finally(() => (f = true));
|
117
|
+
setTimeout(() => {
|
118
|
+
if (!f) {
|
119
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
120
|
+
}
|
121
|
+
}, 100);
|
80
122
|
});
|
81
123
|
});
|
82
124
|
}
|
83
125
|
getKey(chainId) {
|
84
126
|
return __awaiter(this, void 0, void 0, function* () {
|
85
|
-
return
|
86
|
-
|
127
|
+
return new Promise((resolve, reject) => {
|
128
|
+
let f = false;
|
129
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "get-cosmos-key", {
|
130
|
+
chainId,
|
131
|
+
})
|
132
|
+
.then(resolve)
|
133
|
+
.catch(reject)
|
134
|
+
.finally(() => (f = true));
|
135
|
+
setTimeout(() => {
|
136
|
+
if (!f) {
|
137
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
138
|
+
}
|
139
|
+
}, 100);
|
87
140
|
});
|
88
141
|
});
|
89
142
|
}
|
90
143
|
getKeysSettled(chainIds) {
|
91
144
|
return __awaiter(this, void 0, void 0, function* () {
|
92
|
-
return
|
93
|
-
|
145
|
+
return new Promise((resolve, reject) => {
|
146
|
+
let f = false;
|
147
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "get-cosmos-keys-settled", {
|
148
|
+
chainIds,
|
149
|
+
})
|
150
|
+
.then(resolve)
|
151
|
+
.catch(reject)
|
152
|
+
.finally(() => (f = true));
|
153
|
+
setTimeout(() => {
|
154
|
+
if (!f) {
|
155
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
156
|
+
}
|
157
|
+
}, 100);
|
94
158
|
});
|
95
159
|
});
|
96
160
|
}
|
97
161
|
getChainInfosWithoutEndpoints() {
|
98
162
|
return __awaiter(this, void 0, void 0, function* () {
|
99
|
-
return
|
163
|
+
return new Promise((resolve, reject) => {
|
164
|
+
let f = false;
|
165
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "chains", "get-chain-infos-without-endpoints", {})
|
166
|
+
.then((r) => resolve(r.chainInfos))
|
167
|
+
.catch(reject)
|
168
|
+
.finally(() => (f = true));
|
169
|
+
setTimeout(() => {
|
170
|
+
if (!f) {
|
171
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
172
|
+
}
|
173
|
+
}, 100);
|
174
|
+
});
|
100
175
|
});
|
101
176
|
}
|
102
177
|
getChainInfoWithoutEndpoints(chainId) {
|
103
178
|
return __awaiter(this, void 0, void 0, function* () {
|
104
|
-
return
|
105
|
-
|
106
|
-
|
179
|
+
return new Promise((resolve, reject) => {
|
180
|
+
let f = false;
|
181
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "chains", "get-chain-info-without-endpoints", {
|
182
|
+
chainId,
|
183
|
+
})
|
184
|
+
.then((r) => resolve(r.chainInfos))
|
185
|
+
.catch(reject)
|
186
|
+
.finally(() => (f = true));
|
187
|
+
setTimeout(() => {
|
188
|
+
if (!f) {
|
189
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
190
|
+
}
|
191
|
+
}, 100);
|
192
|
+
});
|
107
193
|
});
|
108
194
|
}
|
109
195
|
sendTx(chainId, tx, mode) {
|
110
196
|
return __awaiter(this, void 0, void 0, function* () {
|
197
|
+
// XXX: 원래 enable을 미리하지 않아도 백그라운드에서 알아서 처리해주는 시스템이였는데...
|
198
|
+
// side panel에서는 불가능하기 때문에 이젠 provider에서 permission도 관리해줘야한다...
|
199
|
+
// sendTx의 경우는 일종의 쿼리이기 때문에 언제 결과가 올지 알 수 없다. 그러므로 미리 권한 처리를 해야한다.
|
200
|
+
yield this.enable(chainId);
|
111
201
|
return yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "background-tx", "send-tx-to-background", {
|
112
202
|
chainId,
|
113
203
|
tx,
|
@@ -116,83 +206,125 @@ class Keplr {
|
|
116
206
|
});
|
117
207
|
}
|
118
208
|
signAmino(chainId, signer, signDoc, signOptions = {}) {
|
119
|
-
var _a;
|
120
209
|
return __awaiter(this, void 0, void 0, function* () {
|
121
|
-
return
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
210
|
+
return new Promise((resolve, reject) => {
|
211
|
+
var _a;
|
212
|
+
let f = false;
|
213
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-cosmos-sign-amino", {
|
214
|
+
chainId,
|
215
|
+
signer,
|
216
|
+
signDoc,
|
217
|
+
signOptions: (0, deepmerge_1.default)((_a = this.defaultOptions.sign) !== null && _a !== void 0 ? _a : {}, signOptions),
|
218
|
+
})
|
219
|
+
.then(resolve)
|
220
|
+
.catch(reject)
|
221
|
+
.finally(() => (f = true));
|
222
|
+
setTimeout(() => {
|
223
|
+
if (!f) {
|
224
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
225
|
+
}
|
226
|
+
}, 100);
|
126
227
|
});
|
127
228
|
});
|
128
229
|
}
|
129
230
|
signDirect(chainId, signer, signDoc, signOptions = {}) {
|
130
|
-
var _a;
|
131
231
|
return __awaiter(this, void 0, void 0, function* () {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
:
|
142
|
-
|
143
|
-
|
232
|
+
return new Promise((resolve, reject) => {
|
233
|
+
var _a;
|
234
|
+
let f = false;
|
235
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-cosmos-sign-direct", {
|
236
|
+
chainId,
|
237
|
+
signer,
|
238
|
+
signDoc: {
|
239
|
+
bodyBytes: signDoc.bodyBytes,
|
240
|
+
authInfoBytes: signDoc.authInfoBytes,
|
241
|
+
chainId: signDoc.chainId,
|
242
|
+
accountNumber: signDoc.accountNumber
|
243
|
+
? signDoc.accountNumber.toString()
|
244
|
+
: null,
|
245
|
+
},
|
246
|
+
signOptions: (0, deepmerge_1.default)((_a = this.defaultOptions.sign) !== null && _a !== void 0 ? _a : {}, signOptions),
|
247
|
+
})
|
248
|
+
.then((r) => resolve({
|
249
|
+
signed: {
|
250
|
+
bodyBytes: r.signed.bodyBytes,
|
251
|
+
authInfoBytes: r.signed.authInfoBytes,
|
252
|
+
chainId: r.signed.chainId,
|
253
|
+
accountNumber: long_1.default.fromString(r.signed.accountNumber),
|
254
|
+
},
|
255
|
+
signature: r.signature,
|
256
|
+
}))
|
257
|
+
.catch(reject)
|
258
|
+
.finally(() => (f = true));
|
259
|
+
setTimeout(() => {
|
260
|
+
if (!f) {
|
261
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
262
|
+
}
|
263
|
+
}, 100);
|
144
264
|
});
|
145
|
-
return {
|
146
|
-
signed: {
|
147
|
-
bodyBytes: response.signed.bodyBytes,
|
148
|
-
authInfoBytes: response.signed.authInfoBytes,
|
149
|
-
chainId: response.signed.chainId,
|
150
|
-
accountNumber: long_1.default.fromString(response.signed.accountNumber),
|
151
|
-
},
|
152
|
-
signature: response.signature,
|
153
|
-
};
|
154
265
|
});
|
155
266
|
}
|
156
267
|
signDirectAux(chainId, signer, signDoc, signOptions = {}) {
|
157
|
-
var _a;
|
158
268
|
return __awaiter(this, void 0, void 0, function* () {
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
:
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
269
|
+
return new Promise((resolve, reject) => {
|
270
|
+
var _a;
|
271
|
+
let f = false;
|
272
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-cosmos-sign-direct-aux", {
|
273
|
+
chainId,
|
274
|
+
signer,
|
275
|
+
signDoc: {
|
276
|
+
bodyBytes: signDoc.bodyBytes,
|
277
|
+
publicKey: signDoc.publicKey,
|
278
|
+
chainId: signDoc.chainId,
|
279
|
+
accountNumber: signDoc.accountNumber
|
280
|
+
? signDoc.accountNumber.toString()
|
281
|
+
: null,
|
282
|
+
sequence: signDoc.sequence ? signDoc.sequence.toString() : null,
|
283
|
+
},
|
284
|
+
signOptions: (0, deepmerge_1.default)({
|
285
|
+
preferNoSetMemo: (_a = this.defaultOptions.sign) === null || _a === void 0 ? void 0 : _a.preferNoSetMemo,
|
286
|
+
}, signOptions),
|
287
|
+
})
|
288
|
+
.then((r) => resolve({
|
289
|
+
signed: {
|
290
|
+
bodyBytes: r.signed.bodyBytes,
|
291
|
+
publicKey: r.signed.publicKey,
|
292
|
+
chainId: r.signed.chainId,
|
293
|
+
accountNumber: long_1.default.fromString(r.signed.accountNumber),
|
294
|
+
sequence: long_1.default.fromString(r.signed.sequence),
|
295
|
+
},
|
296
|
+
signature: r.signature,
|
297
|
+
}))
|
298
|
+
.catch(reject)
|
299
|
+
.finally(() => (f = true));
|
300
|
+
setTimeout(() => {
|
301
|
+
if (!f) {
|
302
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
303
|
+
}
|
304
|
+
}, 100);
|
174
305
|
});
|
175
|
-
return {
|
176
|
-
signed: {
|
177
|
-
bodyBytes: response.signed.bodyBytes,
|
178
|
-
publicKey: response.signed.publicKey,
|
179
|
-
chainId: response.signed.chainId,
|
180
|
-
accountNumber: long_1.default.fromString(response.signed.accountNumber),
|
181
|
-
sequence: long_1.default.fromString(response.signed.sequence),
|
182
|
-
},
|
183
|
-
signature: response.signature,
|
184
|
-
};
|
185
306
|
});
|
186
307
|
}
|
187
308
|
signArbitrary(chainId, signer, data) {
|
188
309
|
return __awaiter(this, void 0, void 0, function* () {
|
189
|
-
return
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
310
|
+
return new Promise((resolve, reject) => {
|
311
|
+
let f = false;
|
312
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-cosmos-sign-amino-adr-36", {
|
313
|
+
chainId,
|
314
|
+
signer,
|
315
|
+
data: typeof data === "string" ? buffer_1.Buffer.from(data) : data,
|
316
|
+
signOptions: {
|
317
|
+
isADR36WithString: typeof data === "string",
|
318
|
+
},
|
319
|
+
})
|
320
|
+
.then(resolve)
|
321
|
+
.catch(reject)
|
322
|
+
.finally(() => (f = true));
|
323
|
+
setTimeout(() => {
|
324
|
+
if (!f) {
|
325
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
326
|
+
}
|
327
|
+
}, 100);
|
196
328
|
});
|
197
329
|
});
|
198
330
|
}
|
@@ -201,32 +333,65 @@ class Keplr {
|
|
201
333
|
if (typeof data === "string") {
|
202
334
|
data = buffer_1.Buffer.from(data);
|
203
335
|
}
|
204
|
-
return
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
336
|
+
return new Promise((resolve, reject) => {
|
337
|
+
let f = false;
|
338
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "verify-cosmos-sign-amino-adr-36", {
|
339
|
+
chainId,
|
340
|
+
signer,
|
341
|
+
data,
|
342
|
+
signature,
|
343
|
+
})
|
344
|
+
.then(resolve)
|
345
|
+
.catch(reject)
|
346
|
+
.finally(() => (f = true));
|
347
|
+
setTimeout(() => {
|
348
|
+
if (!f) {
|
349
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
350
|
+
}
|
351
|
+
}, 100);
|
209
352
|
});
|
210
353
|
});
|
211
354
|
}
|
212
355
|
signEthereum(chainId, signer, message, signType) {
|
213
356
|
return __awaiter(this, void 0, void 0, function* () {
|
214
|
-
return
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
357
|
+
return new Promise((resolve, reject) => {
|
358
|
+
let f = false;
|
359
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-ethereum", "request-sign-ethereum", {
|
360
|
+
chainId,
|
361
|
+
signer,
|
362
|
+
message: typeof message === "string" ? buffer_1.Buffer.from(message) : message,
|
363
|
+
signType,
|
364
|
+
})
|
365
|
+
.then(resolve)
|
366
|
+
.catch(reject)
|
367
|
+
.finally(() => (f = true));
|
368
|
+
setTimeout(() => {
|
369
|
+
if (!f) {
|
370
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
371
|
+
}
|
372
|
+
}, 100);
|
219
373
|
});
|
220
374
|
});
|
221
375
|
}
|
222
376
|
signICNSAdr36(chainId, contractAddress, owner, username, addressChainIds) {
|
223
377
|
return __awaiter(this, void 0, void 0, function* () {
|
224
|
-
return
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
378
|
+
return new Promise((resolve, reject) => {
|
379
|
+
let f = false;
|
380
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-icns-adr-36-signatures-v2", {
|
381
|
+
chainId,
|
382
|
+
contractAddress,
|
383
|
+
owner,
|
384
|
+
username,
|
385
|
+
addressChainIds,
|
386
|
+
})
|
387
|
+
.then(resolve)
|
388
|
+
.catch(reject)
|
389
|
+
.finally(() => (f = true));
|
390
|
+
setTimeout(() => {
|
391
|
+
if (!f) {
|
392
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
393
|
+
}
|
394
|
+
}, 100);
|
230
395
|
});
|
231
396
|
});
|
232
397
|
}
|
@@ -247,33 +412,77 @@ class Keplr {
|
|
247
412
|
}
|
248
413
|
suggestToken(chainId, contractAddress, viewingKey) {
|
249
414
|
return __awaiter(this, void 0, void 0, function* () {
|
250
|
-
return
|
251
|
-
|
252
|
-
|
253
|
-
|
415
|
+
return new Promise((resolve, reject) => {
|
416
|
+
let f = false;
|
417
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "token-cw20", "SuggestTokenMsg", {
|
418
|
+
chainId,
|
419
|
+
contractAddress,
|
420
|
+
viewingKey,
|
421
|
+
})
|
422
|
+
.then(resolve)
|
423
|
+
.catch(reject)
|
424
|
+
.finally(() => (f = true));
|
425
|
+
setTimeout(() => {
|
426
|
+
if (!f) {
|
427
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
428
|
+
}
|
429
|
+
}, 100);
|
254
430
|
});
|
255
431
|
});
|
256
432
|
}
|
257
433
|
getSecret20ViewingKey(chainId, contractAddress) {
|
258
434
|
return __awaiter(this, void 0, void 0, function* () {
|
259
|
-
return
|
260
|
-
|
261
|
-
|
435
|
+
return new Promise((resolve, reject) => {
|
436
|
+
let f = false;
|
437
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "token-cw20", "get-secret20-viewing-key", {
|
438
|
+
chainId,
|
439
|
+
contractAddress,
|
440
|
+
})
|
441
|
+
.then(resolve)
|
442
|
+
.catch(reject)
|
443
|
+
.finally(() => (f = true));
|
444
|
+
setTimeout(() => {
|
445
|
+
if (!f) {
|
446
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
447
|
+
}
|
448
|
+
}, 100);
|
262
449
|
});
|
263
450
|
});
|
264
451
|
}
|
265
452
|
getEnigmaPubKey(chainId) {
|
266
453
|
return __awaiter(this, void 0, void 0, function* () {
|
267
|
-
return
|
268
|
-
|
454
|
+
return new Promise((resolve, reject) => {
|
455
|
+
let f = false;
|
456
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "secret-wasm", "get-pubkey-msg", {
|
457
|
+
chainId,
|
458
|
+
})
|
459
|
+
.then(resolve)
|
460
|
+
.catch(reject)
|
461
|
+
.finally(() => (f = true));
|
462
|
+
setTimeout(() => {
|
463
|
+
if (!f) {
|
464
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
465
|
+
}
|
466
|
+
}, 100);
|
269
467
|
});
|
270
468
|
});
|
271
469
|
}
|
272
470
|
getEnigmaTxEncryptionKey(chainId, nonce) {
|
273
471
|
return __awaiter(this, void 0, void 0, function* () {
|
274
|
-
return
|
275
|
-
|
276
|
-
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
let f = false;
|
474
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "secret-wasm", "get-tx-encryption-key-msg", {
|
475
|
+
chainId,
|
476
|
+
nonce,
|
477
|
+
})
|
478
|
+
.then(resolve)
|
479
|
+
.catch(reject)
|
480
|
+
.finally(() => (f = true));
|
481
|
+
setTimeout(() => {
|
482
|
+
if (!f) {
|
483
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
484
|
+
}
|
485
|
+
}, 100);
|
277
486
|
});
|
278
487
|
});
|
279
488
|
}
|
@@ -281,10 +490,21 @@ class Keplr {
|
|
281
490
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
282
491
|
msg) {
|
283
492
|
return __awaiter(this, void 0, void 0, function* () {
|
284
|
-
return
|
285
|
-
|
286
|
-
|
287
|
-
|
493
|
+
return new Promise((resolve, reject) => {
|
494
|
+
let f = false;
|
495
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "secret-wasm", "request-encrypt-msg", {
|
496
|
+
chainId,
|
497
|
+
contractCodeHash,
|
498
|
+
msg,
|
499
|
+
})
|
500
|
+
.then(resolve)
|
501
|
+
.catch(reject)
|
502
|
+
.finally(() => (f = true));
|
503
|
+
setTimeout(() => {
|
504
|
+
if (!f) {
|
505
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
506
|
+
}
|
507
|
+
}, 100);
|
288
508
|
});
|
289
509
|
});
|
290
510
|
}
|
@@ -293,10 +513,21 @@ class Keplr {
|
|
293
513
|
if (!cipherText || cipherText.length === 0) {
|
294
514
|
return new Uint8Array();
|
295
515
|
}
|
296
|
-
return
|
297
|
-
|
298
|
-
|
299
|
-
|
516
|
+
return new Promise((resolve, reject) => {
|
517
|
+
let f = false;
|
518
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "secret-wasm", "request-decrypt-msg", {
|
519
|
+
chainId,
|
520
|
+
cipherText,
|
521
|
+
nonce,
|
522
|
+
})
|
523
|
+
.then(resolve)
|
524
|
+
.catch(reject)
|
525
|
+
.finally(() => (f = true));
|
526
|
+
setTimeout(() => {
|
527
|
+
if (!f) {
|
528
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
529
|
+
}
|
530
|
+
}, 100);
|
300
531
|
});
|
301
532
|
});
|
302
533
|
}
|
@@ -310,14 +541,25 @@ class Keplr {
|
|
310
541
|
return enigmaUtils;
|
311
542
|
}
|
312
543
|
experimentalSignEIP712CosmosTx_v0(chainId, signer, eip712, signDoc, signOptions = {}) {
|
313
|
-
var _a;
|
314
544
|
return __awaiter(this, void 0, void 0, function* () {
|
315
|
-
return
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
545
|
+
return new Promise((resolve, reject) => {
|
546
|
+
var _a;
|
547
|
+
let f = false;
|
548
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-cosmos", "request-sign-eip-712-cosmos-tx-v0", {
|
549
|
+
chainId,
|
550
|
+
signer,
|
551
|
+
eip712,
|
552
|
+
signDoc,
|
553
|
+
signOptions: (0, deepmerge_1.default)((_a = this.defaultOptions.sign) !== null && _a !== void 0 ? _a : {}, signOptions),
|
554
|
+
})
|
555
|
+
.then(resolve)
|
556
|
+
.catch(reject)
|
557
|
+
.finally(() => (f = true));
|
558
|
+
setTimeout(() => {
|
559
|
+
if (!f) {
|
560
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
561
|
+
}
|
562
|
+
}, 100);
|
321
563
|
});
|
322
564
|
});
|
323
565
|
}
|
@@ -328,9 +570,20 @@ class Keplr {
|
|
328
570
|
}
|
329
571
|
changeKeyRingName({ defaultName, editable = true, }) {
|
330
572
|
return __awaiter(this, void 0, void 0, function* () {
|
331
|
-
return
|
332
|
-
|
333
|
-
|
573
|
+
return new Promise((resolve, reject) => {
|
574
|
+
let f = false;
|
575
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-v2", "change-keyring-name-interactive", {
|
576
|
+
defaultName,
|
577
|
+
editable,
|
578
|
+
})
|
579
|
+
.then(resolve)
|
580
|
+
.catch(reject)
|
581
|
+
.finally(() => (f = true));
|
582
|
+
setTimeout(() => {
|
583
|
+
if (!f) {
|
584
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
585
|
+
}
|
586
|
+
}, 100);
|
334
587
|
});
|
335
588
|
});
|
336
589
|
}
|
@@ -354,6 +607,10 @@ class Keplr {
|
|
354
607
|
}
|
355
608
|
sendEthereumTx(chainId, tx) {
|
356
609
|
return __awaiter(this, void 0, void 0, function* () {
|
610
|
+
// XXX: 원래 enable을 미리하지 않아도 백그라운드에서 알아서 처리해주는 시스템이였는데...
|
611
|
+
// side panel에서는 불가능하기 때문에 이젠 provider에서 permission도 관리해줘야한다...
|
612
|
+
// sendTx의 경우는 일종의 쿼리이기 때문에 언제 결과가 올지 알 수 없다. 그러므로 미리 권한 처리를 해야한다.
|
613
|
+
yield this.enable(chainId);
|
357
614
|
return yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "background-tx-ethereum", "send-ethereum-tx-to-background", {
|
358
615
|
chainId,
|
359
616
|
tx,
|
@@ -362,17 +619,259 @@ class Keplr {
|
|
362
619
|
}
|
363
620
|
suggestERC20(chainId, contractAddress) {
|
364
621
|
return __awaiter(this, void 0, void 0, function* () {
|
365
|
-
return
|
366
|
-
|
367
|
-
|
622
|
+
return new Promise((resolve, reject) => {
|
623
|
+
let f = false;
|
624
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "token-erc20", "SuggestERC20TokenMsg", {
|
625
|
+
chainId,
|
626
|
+
contractAddress,
|
627
|
+
})
|
628
|
+
.then(resolve)
|
629
|
+
.catch(reject)
|
630
|
+
.finally(() => (f = true));
|
631
|
+
setTimeout(() => {
|
632
|
+
if (!f) {
|
633
|
+
this.protectedTryOpenSidePanelIfEnabled();
|
634
|
+
}
|
635
|
+
}, 100);
|
368
636
|
});
|
369
637
|
});
|
370
638
|
}
|
639
|
+
// IMPORTANT: protected로 시작하는 method는 InjectedKeplr.startProxy()에서 injected 쪽에서 event system으로도 호출할 수 없도록 막혀있다.
|
640
|
+
// protected로 시작하지 않는 method는 injected keplr에 없어도 event system을 통하면 호출 할 수 있다.
|
641
|
+
// 이를 막기 위해서 method 이름을 protected로 시작하게 한다.
|
642
|
+
protectedTryOpenSidePanelIfEnabled(ignoreGestureFailure = false) {
|
643
|
+
return __awaiter(this, void 0, void 0, function* () {
|
644
|
+
let isInContentScript = false;
|
645
|
+
// 이 provider가 content script 위에서 동작하고 있는지 아닌지 구분해야한다.
|
646
|
+
// content script일때만 side panel을 열도록 시도해볼 가치가 있다.
|
647
|
+
// 근데 js 자체적으로 api등을 통해서는 이를 알아낼 방법이 없다.
|
648
|
+
// extension 상에서 content script에서 keplr provider proxy를 시작하기 전에 window에 밑의 field를 알아서 주입하는 방식으로 처리한다.
|
649
|
+
if (typeof window !== "undefined" &&
|
650
|
+
window.__keplr_content_script === true) {
|
651
|
+
isInContentScript = true;
|
652
|
+
}
|
653
|
+
if (isInContentScript) {
|
654
|
+
const isEnabled = yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "side-panel", "GetSidePanelEnabledMsg", {});
|
655
|
+
if (isEnabled.enabled) {
|
656
|
+
try {
|
657
|
+
// IMPORTANT: "tryOpenSidePanelIfEnabled"는 다른 msg system과 아예 분리되어있고 다르게 동작한다.
|
658
|
+
// router-extension package의 src/router/extension.ts에 있는 주석을 참고할 것.
|
659
|
+
return yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "router-extension/src/router/extension.ts", "tryOpenSidePanelIfEnabled", {});
|
660
|
+
}
|
661
|
+
catch (e) {
|
662
|
+
console.log(e);
|
663
|
+
if (!ignoreGestureFailure &&
|
664
|
+
e.message &&
|
665
|
+
e.message.includes("in response to a user gesture")) {
|
666
|
+
if (!document.getElementById("__open_keplr_side_panel__")) {
|
667
|
+
const sidePanelPing = yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "interaction", "ping-content-script-tab-has-opened-side-panel", {});
|
668
|
+
// 유저가 직접 side panel을 이미 열어논 상태일 수 있다.
|
669
|
+
// 이 경우는 무시하도록 한다.
|
670
|
+
if (sidePanelPing) {
|
671
|
+
return;
|
672
|
+
}
|
673
|
+
const isKeplrLocked = yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring", "GetIsLockedMsg", {});
|
674
|
+
const keplrThemeOption = yield (0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "settings", "GetThemeOptionMsg", {});
|
675
|
+
// extension에서 `web_accessible_resources`에 추가된 파일은 이렇게 접근이 가능함
|
676
|
+
const fontUrl = chrome.runtime.getURL("/assets/Inter-SemiBold.ttf");
|
677
|
+
const fontFaceAndKeyFrames = `
|
678
|
+
@font-face {
|
679
|
+
font-family: 'Inter-SemiBold-Keplr';
|
680
|
+
src: url('${fontUrl}') format('truetype');
|
681
|
+
font-weight: 600;
|
682
|
+
font-style: normal;
|
683
|
+
}
|
684
|
+
|
685
|
+
@keyframes slide-left {
|
686
|
+
0% {
|
687
|
+
transform: translateY(0%) translateX(100%);
|
688
|
+
}
|
689
|
+
100% {
|
690
|
+
transform: translateY(0%) translateX(0);
|
691
|
+
}
|
692
|
+
}
|
693
|
+
|
694
|
+
@keyframes tada {
|
695
|
+
0% {
|
696
|
+
transform: scale3d(1, 1, 1);
|
697
|
+
}
|
698
|
+
10%, 20% {
|
699
|
+
transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg);
|
700
|
+
}
|
701
|
+
30%, 50%, 70%, 90% {
|
702
|
+
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg);
|
703
|
+
}
|
704
|
+
40%, 60%, 80% {
|
705
|
+
transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg);
|
706
|
+
}
|
707
|
+
100% {
|
708
|
+
transform: scale3d(1, 1, 1);
|
709
|
+
}
|
710
|
+
}
|
711
|
+
|
712
|
+
`;
|
713
|
+
const isLightMode = keplrThemeOption === "auto"
|
714
|
+
? !window.matchMedia("(prefers-color-scheme: dark)").matches
|
715
|
+
: keplrThemeOption === "light";
|
716
|
+
// 폰트와 애니메이션을 위한 스타일 요소를 head에 추가
|
717
|
+
const styleElement = document.createElement("style");
|
718
|
+
styleElement.appendChild(document.createTextNode(fontFaceAndKeyFrames));
|
719
|
+
document.head.appendChild(styleElement);
|
720
|
+
const button = document.createElement("div");
|
721
|
+
button.id = "__open_keplr_side_panel__";
|
722
|
+
button.style.boxSizing = "border-box";
|
723
|
+
button.style.animation = "slide-left 0.5s forwards";
|
724
|
+
button.style.position = "fixed";
|
725
|
+
button.style.right = "1.5rem";
|
726
|
+
button.style.top = "1.5rem";
|
727
|
+
button.style.padding = "1rem 1.75rem 1rem 0.75rem";
|
728
|
+
button.style.zIndex = "2147483647"; // 페이지 상의 다른 요소보다 버튼이 위에 오도록 함
|
729
|
+
button.style.borderRadius = "1rem";
|
730
|
+
button.style.display = "flex";
|
731
|
+
button.style.alignItems = "center";
|
732
|
+
button.style.fontFamily = "Inter-SemiBold-Keplr";
|
733
|
+
button.style.fontWeight = "600";
|
734
|
+
// button.style.cursor = "pointer";
|
735
|
+
button.style.background = isLightMode ? "#FEFEFE" : "#1D1D1F";
|
736
|
+
// if (isLightMode) {
|
737
|
+
// button.style.boxShadow =
|
738
|
+
// "0px 0px 15.5px 0px rgba(0, 0, 0, 0.20)";
|
739
|
+
// }
|
740
|
+
// button.addEventListener("mouseover", () => {
|
741
|
+
// button.style.background = isLightMode ? "#F2F2F6" : "#242428";
|
742
|
+
// });
|
743
|
+
// button.addEventListener("mouseout", () => {
|
744
|
+
// button.style.background = isLightMode ? "#FEFEFE" : "#1D1D1F";
|
745
|
+
// });
|
746
|
+
// const megaphoneWrapper = document.createElement("div");
|
747
|
+
// megaphoneWrapper.style.boxSizing = "border-box";
|
748
|
+
// megaphoneWrapper.style.display = "flex";
|
749
|
+
// megaphoneWrapper.style.position = "absolute";
|
750
|
+
// megaphoneWrapper.style.left = "-10px";
|
751
|
+
// megaphoneWrapper.style.top = "-10px";
|
752
|
+
// megaphoneWrapper.style.padding = "6.5px 6px 5.5px";
|
753
|
+
// megaphoneWrapper.style.borderRadius = "255px";
|
754
|
+
// megaphoneWrapper.style.background = "#FC8441";
|
755
|
+
//
|
756
|
+
// const megaphone = document.createElement("img");
|
757
|
+
// const megaphoneUrl = chrome.runtime.getURL(
|
758
|
+
// "/assets/megaphone.svg"
|
759
|
+
// );
|
760
|
+
// megaphone.src = megaphoneUrl;
|
761
|
+
// megaphone.style.width = "1.25rem";
|
762
|
+
// megaphone.style.height = "1.25rem";
|
763
|
+
// megaphone.style.animation = "tada 1s infinite";
|
764
|
+
// megaphoneWrapper.appendChild(megaphone);
|
765
|
+
const arrowTop = document.createElement("div");
|
766
|
+
arrowTop.style.boxSizing = "border-box";
|
767
|
+
arrowTop.style.transform = "translateY(-0.65rem)";
|
768
|
+
arrowTop.style.marginRight = "0.35rem";
|
769
|
+
arrowTop.innerHTML = `
|
770
|
+
<svg width="31" height="31" viewBox="0 0 31 31" fill="none" xmlns="http://www.w3.org/2000/svg">
|
771
|
+
<path d="M30 29.7522C25.1484 31.0691 16.7109 27.1184 18.6093 18.3391C20.5078 9.55979 25.5703 11.5351 26.414 12.852C27.2578 14.1689 28.3125 22.2898 15.8672 19.2171C5.9109 16.7589 7.15625 6.04811 8 1M8 1L14 8M8 1L1 7.5" stroke="${isLightMode ? "#2C4BE2" : "#72747B"}"/>
|
772
|
+
</svg>
|
773
|
+
`;
|
774
|
+
const keplrLogoWrap = document.createElement("div");
|
775
|
+
keplrLogoWrap.style.boxSizing = "border-box";
|
776
|
+
keplrLogoWrap.style.position = "relative";
|
777
|
+
keplrLogoWrap.style.marginRight = "1rem";
|
778
|
+
const keplrLogo = document.createElement("img");
|
779
|
+
const keplrLogoUrl = chrome.runtime.getURL(`/assets/${isKeplrLocked ? "locked-keplr-logo" : "icon"}-128.png`);
|
780
|
+
keplrLogo.src = keplrLogoUrl;
|
781
|
+
keplrLogo.style.boxSizing = "border-box";
|
782
|
+
keplrLogo.style.width = "3rem";
|
783
|
+
keplrLogo.style.height = "3rem";
|
784
|
+
keplrLogoWrap.appendChild(keplrLogo);
|
785
|
+
const logoClickCursor = document.createElement("img");
|
786
|
+
const logoClickCursorUrl = chrome.runtime.getURL("assets/icon-click-cursor.png");
|
787
|
+
logoClickCursor.src = logoClickCursorUrl;
|
788
|
+
logoClickCursor.style.boxSizing = "border-box";
|
789
|
+
logoClickCursor.style.position = "absolute";
|
790
|
+
logoClickCursor.style.right = "-0.2rem";
|
791
|
+
logoClickCursor.style.bottom = "-0.2rem";
|
792
|
+
logoClickCursor.style.aspectRatio = "78/98";
|
793
|
+
logoClickCursor.style.height = "1.375rem";
|
794
|
+
keplrLogoWrap.appendChild(logoClickCursor);
|
795
|
+
const mainText = document.createElement("span");
|
796
|
+
mainText.style.boxSizing = "border-box";
|
797
|
+
// mainText.style.maxWidth = "9.125rem";
|
798
|
+
mainText.style.fontSize = "1rem";
|
799
|
+
mainText.style.color = isLightMode ? "#020202" : "#FEFEFE";
|
800
|
+
mainText.textContent = isKeplrLocked
|
801
|
+
? "Unlock Keplr to proceed"
|
802
|
+
: "Open Keplr to approve request(s)";
|
803
|
+
// const arrowLeftOpenWrapper = document.createElement("div");
|
804
|
+
// arrowLeftOpenWrapper.style.boxSizing = "border-box";
|
805
|
+
// arrowLeftOpenWrapper.style.display = "flex";
|
806
|
+
// arrowLeftOpenWrapper.style.alignItems = "center";
|
807
|
+
// arrowLeftOpenWrapper.style.padding = "0.5rem 0.75rem";
|
808
|
+
//
|
809
|
+
// arrowLeftOpenWrapper.innerHTML = `
|
810
|
+
// <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
811
|
+
// <path d="M13 5L6.25 11.75L13 18.5" stroke=${
|
812
|
+
// isLightMode ? "#1633C0" : "#566FEC"
|
813
|
+
// } stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
814
|
+
// <path d="M19.3333 5L12.5833 11.75L19.3333 18.5" stroke=${
|
815
|
+
// isLightMode ? "#1633C0" : "#566FEC"
|
816
|
+
// } stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
817
|
+
// </svg>`;
|
818
|
+
//
|
819
|
+
// const openText = document.createElement("span");
|
820
|
+
// openText.style.boxSizing = "border-box";
|
821
|
+
// openText.style.fontSize = "1rem";
|
822
|
+
// openText.style.color = isLightMode ? "#1633C0" : "#566FEC";
|
823
|
+
// openText.textContent = "OPEN";
|
824
|
+
//
|
825
|
+
// arrowLeftOpenWrapper.appendChild(openText);
|
826
|
+
// button.appendChild(megaphoneWrapper);
|
827
|
+
button.appendChild(arrowTop);
|
828
|
+
button.appendChild(keplrLogoWrap);
|
829
|
+
button.appendChild(mainText);
|
830
|
+
// button.appendChild(arrowLeftOpenWrapper);
|
831
|
+
// 버튼을 추가하기 전에 한 번 더 이미 추가된 버튼이 있는지 확인
|
832
|
+
const hasAlready = document.getElementById("__open_keplr_side_panel__");
|
833
|
+
if (!hasAlready) {
|
834
|
+
let removed = false;
|
835
|
+
// 유저가 이 button이 아니라 다른 방식(직접 작업줄의 아이콘을 눌러서 등등)으로 side panel을 열수도 있다.
|
836
|
+
// 이 경우를 감지해서 side panel이 열렸으면 자동으로 이 버튼이 삭제되도록 한다.
|
837
|
+
const intervalId = setInterval(() => {
|
838
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "interaction", "ping-content-script-tab-has-opened-side-panel", {}).then((sidePanelPing) => {
|
839
|
+
if (sidePanelPing) {
|
840
|
+
clearInterval(intervalId);
|
841
|
+
if (!removed) {
|
842
|
+
button.remove();
|
843
|
+
removed = true;
|
844
|
+
}
|
845
|
+
}
|
846
|
+
});
|
847
|
+
}, 300);
|
848
|
+
// 버튼을 body에 추가
|
849
|
+
document.body.appendChild(button);
|
850
|
+
// XXX: 현재 크롬의 버그로 인해서 밑의 코드가 동작할 수 없기 때문에 일단 주석처리한다.
|
851
|
+
// 버튼 클릭 이벤트 추가 (필요한 동작을 정의)
|
852
|
+
// button.addEventListener("click", () => {
|
853
|
+
// this.protectedTryOpenSidePanelIfEnabled(true);
|
854
|
+
//
|
855
|
+
// clearInterval(intervalId);
|
856
|
+
// if (!removed) {
|
857
|
+
// button.remove();
|
858
|
+
// removed = true;
|
859
|
+
// }
|
860
|
+
// });
|
861
|
+
}
|
862
|
+
}
|
863
|
+
}
|
864
|
+
}
|
865
|
+
}
|
866
|
+
}
|
867
|
+
});
|
868
|
+
}
|
371
869
|
}
|
372
870
|
exports.Keplr = Keplr;
|
373
871
|
class EthereumProvider extends events_1.default {
|
374
|
-
constructor(requester) {
|
872
|
+
constructor(keplr, requester) {
|
375
873
|
super();
|
874
|
+
this.keplr = keplr;
|
376
875
|
this.requester = requester;
|
377
876
|
this.chainId = null;
|
378
877
|
this.selectedAddress = null;
|
@@ -380,16 +879,47 @@ class EthereumProvider extends events_1.default {
|
|
380
879
|
this.isKeplr = true;
|
381
880
|
this.isMetaMask = true;
|
382
881
|
}
|
882
|
+
protectedEnableAccess() {
|
883
|
+
return __awaiter(this, void 0, void 0, function* () {
|
884
|
+
return new Promise((resolve, reject) => {
|
885
|
+
let f = false;
|
886
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "permission-interactive", "enable-access-for-evm", {})
|
887
|
+
.then(resolve)
|
888
|
+
.catch(reject)
|
889
|
+
.finally(() => (f = true));
|
890
|
+
setTimeout(() => {
|
891
|
+
if (!f) {
|
892
|
+
this.keplr.protectedTryOpenSidePanelIfEnabled();
|
893
|
+
}
|
894
|
+
}, 100);
|
895
|
+
});
|
896
|
+
});
|
897
|
+
}
|
383
898
|
isConnected() {
|
384
899
|
return true;
|
385
900
|
}
|
386
901
|
request({ method, params, providerId, chainId, }) {
|
387
902
|
return __awaiter(this, void 0, void 0, function* () {
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
903
|
+
// XXX: 원래 enable을 미리하지 않아도 백그라운드에서 알아서 처리해주는 시스템이였는데...
|
904
|
+
// side panel에서는 불가능하기 때문에 이젠 provider에서 permission도 관리해줘야한다...
|
905
|
+
// request의 경우는 일종의 쿼리이기 때문에 언제 결과가 올지 알 수 없다. 그러므로 미리 권한 처리를 해야한다.
|
906
|
+
yield this.protectedEnableAccess();
|
907
|
+
return new Promise((resolve, reject) => {
|
908
|
+
let f = false;
|
909
|
+
(0, router_1.sendSimpleMessage)(this.requester, router_1.BACKGROUND_PORT, "keyring-ethereum", "request-json-rpc-to-evm", {
|
910
|
+
method,
|
911
|
+
params,
|
912
|
+
providerId,
|
913
|
+
chainId,
|
914
|
+
})
|
915
|
+
.then(resolve)
|
916
|
+
.catch(reject)
|
917
|
+
.finally(() => (f = true));
|
918
|
+
setTimeout(() => {
|
919
|
+
if (!f && sidePanelOpenNeededJSONRPCMethods.includes(method)) {
|
920
|
+
this.keplr.protectedTryOpenSidePanelIfEnabled();
|
921
|
+
}
|
922
|
+
}, 100);
|
393
923
|
});
|
394
924
|
});
|
395
925
|
}
|
@@ -398,17 +928,23 @@ class EthereumProvider extends events_1.default {
|
|
398
928
|
*/
|
399
929
|
enable() {
|
400
930
|
return __awaiter(this, void 0, void 0, function* () {
|
401
|
-
return yield
|
402
|
-
method: "eth_requestAccounts",
|
403
|
-
});
|
931
|
+
return yield this.request({ method: "eth_requestAccounts" });
|
404
932
|
});
|
405
933
|
}
|
406
934
|
net_version() {
|
407
935
|
return __awaiter(this, void 0, void 0, function* () {
|
408
|
-
return yield
|
409
|
-
method: "net_version",
|
410
|
-
});
|
936
|
+
return yield this.request({ method: "net_version" });
|
411
937
|
});
|
412
938
|
}
|
413
939
|
}
|
940
|
+
// IMPORTANT: 사이드 패널을 열어야하는 JSON-RPC 메소드들이 생길 때마다 여기에 추가해야한다.
|
941
|
+
const sidePanelOpenNeededJSONRPCMethods = [
|
942
|
+
"eth_sendTransaction",
|
943
|
+
"personal_sign",
|
944
|
+
"eth_signTypedData_v3",
|
945
|
+
"eth_signTypedData_v4",
|
946
|
+
"wallet_addEthereumChain",
|
947
|
+
"wallet_switchEthereumChain",
|
948
|
+
"wallet_watchAsset",
|
949
|
+
];
|
414
950
|
//# sourceMappingURL=core.js.map
|