@portal-hq/web 1.0.4 → 2.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/lib/commonjs/index.js +28 -18
- package/lib/commonjs/mpc/index.js +56 -10
- package/lib/commonjs/provider/index.js +18 -11
- package/lib/esm/index.js +28 -18
- package/lib/esm/mpc/index.js +56 -10
- package/lib/esm/provider/index.js +18 -11
- package/package.json +1 -1
- package/src/index.ts +51 -19
- package/src/mpc/index.ts +76 -13
- package/src/provider/index.ts +22 -10
- package/types.d.ts +42 -8
package/lib/commonjs/index.js
CHANGED
|
@@ -111,14 +111,14 @@ class Portal {
|
|
|
111
111
|
// Noop
|
|
112
112
|
}, backupConfigs = {}) {
|
|
113
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const
|
|
114
|
+
const response = yield this.mpc.backup({
|
|
115
115
|
backupMethod,
|
|
116
116
|
backupConfigs,
|
|
117
117
|
host: this.host,
|
|
118
118
|
mpcVersion: this.mpcVersion,
|
|
119
119
|
featureFlags: this.featureFlags,
|
|
120
120
|
}, progress);
|
|
121
|
-
return
|
|
121
|
+
return response;
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
recoverWallet(cipherText, backupMethod, backupConfigs = {}, progress = () => {
|
|
@@ -167,84 +167,94 @@ class Portal {
|
|
|
167
167
|
/****************************
|
|
168
168
|
* Provider Methods
|
|
169
169
|
****************************/
|
|
170
|
-
ethEstimateGas(transaction) {
|
|
170
|
+
ethEstimateGas(transaction, chainId) {
|
|
171
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
172
|
return this.provider.request({
|
|
173
|
+
chainId,
|
|
173
174
|
method: 'eth_estimateGas',
|
|
174
175
|
params: transaction,
|
|
175
176
|
});
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
|
-
ethGasPrice() {
|
|
179
|
+
ethGasPrice(chainId) {
|
|
179
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
181
|
return this.provider.request({
|
|
182
|
+
chainId,
|
|
181
183
|
method: 'eth_gasPrice',
|
|
182
184
|
params: [],
|
|
183
185
|
});
|
|
184
186
|
});
|
|
185
187
|
}
|
|
186
|
-
ethGetBalance() {
|
|
188
|
+
ethGetBalance(chainId) {
|
|
187
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
190
|
return this.provider.request({
|
|
191
|
+
chainId,
|
|
189
192
|
method: 'eth_getBalance',
|
|
190
193
|
params: [this.address, 'latest'],
|
|
191
194
|
});
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
|
-
ethSendTransaction(transaction) {
|
|
197
|
+
ethSendTransaction(transaction, chainId) {
|
|
195
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
199
|
return this.provider.request({
|
|
200
|
+
chainId,
|
|
197
201
|
method: 'eth_sendTransaction',
|
|
198
202
|
params: transaction,
|
|
199
203
|
});
|
|
200
204
|
});
|
|
201
205
|
}
|
|
202
|
-
ethSign(message) {
|
|
206
|
+
ethSign(message, chainId) {
|
|
203
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
208
|
return this.provider.request({
|
|
209
|
+
chainId,
|
|
205
210
|
method: 'eth_sign',
|
|
206
211
|
params: [this.address, this.stringToHex(message)],
|
|
207
212
|
});
|
|
208
213
|
});
|
|
209
214
|
}
|
|
210
|
-
ethSignTransaction(transaction) {
|
|
215
|
+
ethSignTransaction(transaction, chainId) {
|
|
211
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
217
|
return this.provider.request({
|
|
218
|
+
chainId,
|
|
213
219
|
method: 'eth_signTransaction',
|
|
214
220
|
params: transaction,
|
|
215
221
|
});
|
|
216
222
|
});
|
|
217
223
|
}
|
|
218
|
-
ethSignTypedData(data) {
|
|
224
|
+
ethSignTypedData(data, chainId) {
|
|
219
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
226
|
return this.provider.request({
|
|
227
|
+
chainId,
|
|
221
228
|
method: 'eth_signTypedData',
|
|
222
229
|
params: [this.address, data],
|
|
223
230
|
});
|
|
224
231
|
});
|
|
225
232
|
}
|
|
226
|
-
ethSignTypedDataV3(data) {
|
|
233
|
+
ethSignTypedDataV3(data, chainId) {
|
|
227
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
228
235
|
return this.provider.request({
|
|
236
|
+
chainId,
|
|
229
237
|
method: 'eth_signTypedData_v3',
|
|
230
238
|
params: [this.address, data],
|
|
231
239
|
});
|
|
232
240
|
});
|
|
233
241
|
}
|
|
234
|
-
ethSignTypedDataV4(data) {
|
|
242
|
+
ethSignTypedDataV4(data, chainId) {
|
|
235
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
244
|
return this.provider.request({
|
|
245
|
+
chainId,
|
|
237
246
|
method: 'eth_signTypedData_v4',
|
|
238
247
|
params: [this.address, data],
|
|
239
248
|
});
|
|
240
249
|
});
|
|
241
250
|
}
|
|
242
|
-
personalSign(message) {
|
|
251
|
+
personalSign(message, chainId) {
|
|
243
252
|
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
return this.provider.request({
|
|
253
|
+
return (yield this.provider.request({
|
|
254
|
+
chainId,
|
|
245
255
|
method: 'personal_sign',
|
|
246
256
|
params: [this.stringToHex(message), this.address],
|
|
247
|
-
});
|
|
257
|
+
}));
|
|
248
258
|
});
|
|
249
259
|
}
|
|
250
260
|
/*******************************
|
|
@@ -295,16 +305,16 @@ class Portal {
|
|
|
295
305
|
/*******************************
|
|
296
306
|
* Swaps Methods
|
|
297
307
|
*******************************/
|
|
298
|
-
getQuote(apiKey, args) {
|
|
308
|
+
getQuote(apiKey, args, chainId) {
|
|
299
309
|
var _a;
|
|
300
310
|
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
|
|
311
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args, chainId);
|
|
302
312
|
});
|
|
303
313
|
}
|
|
304
|
-
getSources(apiKey) {
|
|
314
|
+
getSources(apiKey, chainId) {
|
|
305
315
|
var _a;
|
|
306
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
|
|
317
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey, chainId);
|
|
308
318
|
});
|
|
309
319
|
}
|
|
310
320
|
/*******************************
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MpcErrorCodes = exports.MpcError = void 0;
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const index_1 = require("../index");
|
|
15
|
-
const WEB_SDK_VERSION = '
|
|
15
|
+
const WEB_SDK_VERSION = '2.0.0';
|
|
16
16
|
class Mpc {
|
|
17
17
|
constructor({ portal }) {
|
|
18
18
|
this.configureIframe = () => {
|
|
@@ -76,8 +76,14 @@ class Mpc {
|
|
|
76
76
|
// Remove the event listeners
|
|
77
77
|
window.removeEventListener('message', handleBackup);
|
|
78
78
|
window.removeEventListener('message', handleProgress);
|
|
79
|
+
const storageCallback = () => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', result.backupIds);
|
|
81
|
+
});
|
|
79
82
|
// Resolve the promise with the result
|
|
80
|
-
resolve(
|
|
83
|
+
resolve({
|
|
84
|
+
cipherText: result.cipherText,
|
|
85
|
+
storageCallback,
|
|
86
|
+
});
|
|
81
87
|
}
|
|
82
88
|
};
|
|
83
89
|
const handleProgress = (message) => {
|
|
@@ -334,7 +340,7 @@ class Mpc {
|
|
|
334
340
|
/*******************************
|
|
335
341
|
* API Methods
|
|
336
342
|
*******************************/
|
|
337
|
-
getBalances() {
|
|
343
|
+
getBalances(chainId) {
|
|
338
344
|
return __awaiter(this, void 0, void 0, function* () {
|
|
339
345
|
return new Promise((resolve, reject) => {
|
|
340
346
|
const handleGetBalances = (event) => {
|
|
@@ -362,7 +368,7 @@ class Mpc {
|
|
|
362
368
|
// Send the request to the iframe
|
|
363
369
|
this.postMessage({
|
|
364
370
|
type: 'portal:getBalances',
|
|
365
|
-
data: {},
|
|
371
|
+
data: { chainId },
|
|
366
372
|
});
|
|
367
373
|
});
|
|
368
374
|
});
|
|
@@ -400,7 +406,7 @@ class Mpc {
|
|
|
400
406
|
});
|
|
401
407
|
});
|
|
402
408
|
}
|
|
403
|
-
getNFTs() {
|
|
409
|
+
getNFTs(chainId) {
|
|
404
410
|
return __awaiter(this, void 0, void 0, function* () {
|
|
405
411
|
return new Promise((resolve, reject) => {
|
|
406
412
|
const handleGetNFTs = (event) => {
|
|
@@ -428,12 +434,12 @@ class Mpc {
|
|
|
428
434
|
// Send the request to the iframe
|
|
429
435
|
this.postMessage({
|
|
430
436
|
type: 'portal:getNFTs',
|
|
431
|
-
data: {},
|
|
437
|
+
data: { chainId },
|
|
432
438
|
});
|
|
433
439
|
});
|
|
434
440
|
});
|
|
435
441
|
}
|
|
436
|
-
getQuote(apiKey, args) {
|
|
442
|
+
getQuote(apiKey, args, chainId) {
|
|
437
443
|
return __awaiter(this, void 0, void 0, function* () {
|
|
438
444
|
return new Promise((resolve, reject) => {
|
|
439
445
|
const handleGetQuote = (event) => {
|
|
@@ -464,12 +470,13 @@ class Mpc {
|
|
|
464
470
|
data: {
|
|
465
471
|
apiKey,
|
|
466
472
|
args,
|
|
473
|
+
chainId,
|
|
467
474
|
},
|
|
468
475
|
});
|
|
469
476
|
});
|
|
470
477
|
});
|
|
471
478
|
}
|
|
472
|
-
getSources(apiKey) {
|
|
479
|
+
getSources(apiKey, chainId) {
|
|
473
480
|
return __awaiter(this, void 0, void 0, function* () {
|
|
474
481
|
return new Promise((resolve, reject) => {
|
|
475
482
|
const handleGetSources = (event) => {
|
|
@@ -499,6 +506,7 @@ class Mpc {
|
|
|
499
506
|
type: 'portal:swaps:getSources',
|
|
500
507
|
data: {
|
|
501
508
|
apiKey,
|
|
509
|
+
chainId,
|
|
502
510
|
},
|
|
503
511
|
});
|
|
504
512
|
});
|
|
@@ -542,7 +550,42 @@ class Mpc {
|
|
|
542
550
|
});
|
|
543
551
|
});
|
|
544
552
|
}
|
|
545
|
-
|
|
553
|
+
setBackupStatus(status, backupIds) {
|
|
554
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
555
|
+
return new Promise((resolve, reject) => {
|
|
556
|
+
const handleSetBackupStatus = (event) => {
|
|
557
|
+
const { type, data } = event.data;
|
|
558
|
+
const { origin } = event;
|
|
559
|
+
// ignore any broadcast postMessages
|
|
560
|
+
if (origin !== this.getOrigin()) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (type === 'portal:api:setBackupStatusError') {
|
|
564
|
+
// Remove the event listener
|
|
565
|
+
window.removeEventListener('message', handleSetBackupStatus);
|
|
566
|
+
// Reject the promise with the error
|
|
567
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
568
|
+
}
|
|
569
|
+
else if (type === 'portal:api:setBackupStatusResult') {
|
|
570
|
+
// Remove the event listener
|
|
571
|
+
window.removeEventListener('message', handleSetBackupStatus);
|
|
572
|
+
// Resolve the promise with the result
|
|
573
|
+
return resolve(data);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
// Bind the function to the message event
|
|
577
|
+
window.addEventListener('message', handleSetBackupStatus);
|
|
578
|
+
this.postMessage({
|
|
579
|
+
type: 'portal:api:setBackupStatus',
|
|
580
|
+
data: {
|
|
581
|
+
backupIds,
|
|
582
|
+
status,
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
simulateTransaction(transaction, chainId) {
|
|
546
589
|
return __awaiter(this, void 0, void 0, function* () {
|
|
547
590
|
return new Promise((resolve, reject) => {
|
|
548
591
|
const handleSimulateTransaction = (event) => {
|
|
@@ -570,7 +613,10 @@ class Mpc {
|
|
|
570
613
|
// Send the request to the iframe
|
|
571
614
|
this.postMessage({
|
|
572
615
|
type: 'portal:simulateTransaction',
|
|
573
|
-
data:
|
|
616
|
+
data: {
|
|
617
|
+
chainId,
|
|
618
|
+
transaction,
|
|
619
|
+
},
|
|
574
620
|
});
|
|
575
621
|
});
|
|
576
622
|
});
|
|
@@ -110,17 +110,21 @@ class Provider {
|
|
|
110
110
|
* @param args The arguments of the request being made
|
|
111
111
|
* @returns Promise<any>
|
|
112
112
|
*/
|
|
113
|
-
request({ method, params }) {
|
|
113
|
+
request({ chainId, method, params, }) {
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
if (method === 'eth_chainId') {
|
|
116
|
-
return this.portal.chainId;
|
|
116
|
+
return chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId;
|
|
117
117
|
}
|
|
118
118
|
const isSignerMethod = signerMethods.includes(method);
|
|
119
|
-
let result;
|
|
120
119
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
121
120
|
// Send to Gateway for RPC calls
|
|
122
|
-
const response = yield this.handleGatewayRequest({
|
|
121
|
+
const response = yield this.handleGatewayRequest({
|
|
122
|
+
chainId,
|
|
123
|
+
method,
|
|
124
|
+
params,
|
|
125
|
+
});
|
|
123
126
|
this.emit('portal_signatureReceived', {
|
|
127
|
+
chainId,
|
|
124
128
|
method,
|
|
125
129
|
params,
|
|
126
130
|
signature: response,
|
|
@@ -128,21 +132,23 @@ class Provider {
|
|
|
128
132
|
if (response.error) {
|
|
129
133
|
throw new errors_1.ProviderRpcError(response.error);
|
|
130
134
|
}
|
|
131
|
-
|
|
135
|
+
return response.result;
|
|
132
136
|
}
|
|
133
137
|
else if (isSignerMethod) {
|
|
134
138
|
// Handle signing
|
|
135
139
|
const transactionHash = yield this.handleSigningRequest({
|
|
140
|
+
chainId,
|
|
136
141
|
method,
|
|
137
142
|
params,
|
|
138
143
|
});
|
|
139
144
|
if (transactionHash) {
|
|
140
145
|
this.emit('portal_signatureReceived', {
|
|
146
|
+
chainId,
|
|
141
147
|
method,
|
|
142
148
|
params,
|
|
143
149
|
signature: transactionHash,
|
|
144
150
|
});
|
|
145
|
-
|
|
151
|
+
return transactionHash;
|
|
146
152
|
}
|
|
147
153
|
}
|
|
148
154
|
else {
|
|
@@ -155,7 +161,6 @@ class Provider {
|
|
|
155
161
|
},
|
|
156
162
|
});
|
|
157
163
|
}
|
|
158
|
-
return result;
|
|
159
164
|
});
|
|
160
165
|
}
|
|
161
166
|
/************************
|
|
@@ -218,13 +223,13 @@ class Provider {
|
|
|
218
223
|
* @param args The arguments of the request being made
|
|
219
224
|
* @returns Promise<any>
|
|
220
225
|
*/
|
|
221
|
-
handleGatewayRequest({ method, params, }) {
|
|
226
|
+
handleGatewayRequest({ chainId, method, params, }) {
|
|
222
227
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
228
|
// Pass request off to the gateway
|
|
224
229
|
const result = yield fetch(this.portal.getRpcUrl(), {
|
|
225
230
|
body: JSON.stringify({
|
|
226
231
|
jsonrpc: '2.0',
|
|
227
|
-
id: this.portal.chainId,
|
|
232
|
+
id: chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId,
|
|
228
233
|
method,
|
|
229
234
|
params,
|
|
230
235
|
}),
|
|
@@ -239,7 +244,7 @@ class Provider {
|
|
|
239
244
|
* @param args The arguments of the request being made
|
|
240
245
|
* @returns Promise<any>
|
|
241
246
|
*/
|
|
242
|
-
handleSigningRequest({ method, params, }) {
|
|
247
|
+
handleSigningRequest({ chainId, method, params, }) {
|
|
243
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
244
249
|
const isApproved = passiveSignerMethods.includes(method)
|
|
245
250
|
? true
|
|
@@ -261,7 +266,9 @@ class Provider {
|
|
|
261
266
|
case 'eth_signTypedData_v4':
|
|
262
267
|
case 'personal_sign': {
|
|
263
268
|
const result = yield this.portal.mpc.sign({
|
|
264
|
-
chainId:
|
|
269
|
+
chainId: chainId
|
|
270
|
+
? chainId.split(':')[1]
|
|
271
|
+
: this.portal.chainId.toString(),
|
|
265
272
|
method,
|
|
266
273
|
params: this.buildParams(method, params),
|
|
267
274
|
rpcUrl: this.portal.getRpcUrl(),
|
package/lib/esm/index.js
CHANGED
|
@@ -105,14 +105,14 @@ class Portal {
|
|
|
105
105
|
// Noop
|
|
106
106
|
}, backupConfigs = {}) {
|
|
107
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const
|
|
108
|
+
const response = yield this.mpc.backup({
|
|
109
109
|
backupMethod,
|
|
110
110
|
backupConfigs,
|
|
111
111
|
host: this.host,
|
|
112
112
|
mpcVersion: this.mpcVersion,
|
|
113
113
|
featureFlags: this.featureFlags,
|
|
114
114
|
}, progress);
|
|
115
|
-
return
|
|
115
|
+
return response;
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
recoverWallet(cipherText, backupMethod, backupConfigs = {}, progress = () => {
|
|
@@ -161,84 +161,94 @@ class Portal {
|
|
|
161
161
|
/****************************
|
|
162
162
|
* Provider Methods
|
|
163
163
|
****************************/
|
|
164
|
-
ethEstimateGas(transaction) {
|
|
164
|
+
ethEstimateGas(transaction, chainId) {
|
|
165
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
166
|
return this.provider.request({
|
|
167
|
+
chainId,
|
|
167
168
|
method: 'eth_estimateGas',
|
|
168
169
|
params: transaction,
|
|
169
170
|
});
|
|
170
171
|
});
|
|
171
172
|
}
|
|
172
|
-
ethGasPrice() {
|
|
173
|
+
ethGasPrice(chainId) {
|
|
173
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
175
|
return this.provider.request({
|
|
176
|
+
chainId,
|
|
175
177
|
method: 'eth_gasPrice',
|
|
176
178
|
params: [],
|
|
177
179
|
});
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
|
-
ethGetBalance() {
|
|
182
|
+
ethGetBalance(chainId) {
|
|
181
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
184
|
return this.provider.request({
|
|
185
|
+
chainId,
|
|
183
186
|
method: 'eth_getBalance',
|
|
184
187
|
params: [this.address, 'latest'],
|
|
185
188
|
});
|
|
186
189
|
});
|
|
187
190
|
}
|
|
188
|
-
ethSendTransaction(transaction) {
|
|
191
|
+
ethSendTransaction(transaction, chainId) {
|
|
189
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
193
|
return this.provider.request({
|
|
194
|
+
chainId,
|
|
191
195
|
method: 'eth_sendTransaction',
|
|
192
196
|
params: transaction,
|
|
193
197
|
});
|
|
194
198
|
});
|
|
195
199
|
}
|
|
196
|
-
ethSign(message) {
|
|
200
|
+
ethSign(message, chainId) {
|
|
197
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
202
|
return this.provider.request({
|
|
203
|
+
chainId,
|
|
199
204
|
method: 'eth_sign',
|
|
200
205
|
params: [this.address, this.stringToHex(message)],
|
|
201
206
|
});
|
|
202
207
|
});
|
|
203
208
|
}
|
|
204
|
-
ethSignTransaction(transaction) {
|
|
209
|
+
ethSignTransaction(transaction, chainId) {
|
|
205
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
211
|
return this.provider.request({
|
|
212
|
+
chainId,
|
|
207
213
|
method: 'eth_signTransaction',
|
|
208
214
|
params: transaction,
|
|
209
215
|
});
|
|
210
216
|
});
|
|
211
217
|
}
|
|
212
|
-
ethSignTypedData(data) {
|
|
218
|
+
ethSignTypedData(data, chainId) {
|
|
213
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
220
|
return this.provider.request({
|
|
221
|
+
chainId,
|
|
215
222
|
method: 'eth_signTypedData',
|
|
216
223
|
params: [this.address, data],
|
|
217
224
|
});
|
|
218
225
|
});
|
|
219
226
|
}
|
|
220
|
-
ethSignTypedDataV3(data) {
|
|
227
|
+
ethSignTypedDataV3(data, chainId) {
|
|
221
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
229
|
return this.provider.request({
|
|
230
|
+
chainId,
|
|
223
231
|
method: 'eth_signTypedData_v3',
|
|
224
232
|
params: [this.address, data],
|
|
225
233
|
});
|
|
226
234
|
});
|
|
227
235
|
}
|
|
228
|
-
ethSignTypedDataV4(data) {
|
|
236
|
+
ethSignTypedDataV4(data, chainId) {
|
|
229
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
230
238
|
return this.provider.request({
|
|
239
|
+
chainId,
|
|
231
240
|
method: 'eth_signTypedData_v4',
|
|
232
241
|
params: [this.address, data],
|
|
233
242
|
});
|
|
234
243
|
});
|
|
235
244
|
}
|
|
236
|
-
personalSign(message) {
|
|
245
|
+
personalSign(message, chainId) {
|
|
237
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
return this.provider.request({
|
|
247
|
+
return (yield this.provider.request({
|
|
248
|
+
chainId,
|
|
239
249
|
method: 'personal_sign',
|
|
240
250
|
params: [this.stringToHex(message), this.address],
|
|
241
|
-
});
|
|
251
|
+
}));
|
|
242
252
|
});
|
|
243
253
|
}
|
|
244
254
|
/*******************************
|
|
@@ -289,16 +299,16 @@ class Portal {
|
|
|
289
299
|
/*******************************
|
|
290
300
|
* Swaps Methods
|
|
291
301
|
*******************************/
|
|
292
|
-
getQuote(apiKey, args) {
|
|
302
|
+
getQuote(apiKey, args, chainId) {
|
|
293
303
|
var _a;
|
|
294
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
|
|
305
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args, chainId);
|
|
296
306
|
});
|
|
297
307
|
}
|
|
298
|
-
getSources(apiKey) {
|
|
308
|
+
getSources(apiKey, chainId) {
|
|
299
309
|
var _a;
|
|
300
310
|
return __awaiter(this, void 0, void 0, function* () {
|
|
301
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
|
|
311
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey, chainId);
|
|
302
312
|
});
|
|
303
313
|
}
|
|
304
314
|
/*******************************
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PortalMpcError } from './errors';
|
|
11
11
|
import { BackupMethods } from '../index';
|
|
12
|
-
const WEB_SDK_VERSION = '
|
|
12
|
+
const WEB_SDK_VERSION = '2.0.0';
|
|
13
13
|
class Mpc {
|
|
14
14
|
constructor({ portal }) {
|
|
15
15
|
this.configureIframe = () => {
|
|
@@ -73,8 +73,14 @@ class Mpc {
|
|
|
73
73
|
// Remove the event listeners
|
|
74
74
|
window.removeEventListener('message', handleBackup);
|
|
75
75
|
window.removeEventListener('message', handleProgress);
|
|
76
|
+
const storageCallback = () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', result.backupIds);
|
|
78
|
+
});
|
|
76
79
|
// Resolve the promise with the result
|
|
77
|
-
resolve(
|
|
80
|
+
resolve({
|
|
81
|
+
cipherText: result.cipherText,
|
|
82
|
+
storageCallback,
|
|
83
|
+
});
|
|
78
84
|
}
|
|
79
85
|
};
|
|
80
86
|
const handleProgress = (message) => {
|
|
@@ -331,7 +337,7 @@ class Mpc {
|
|
|
331
337
|
/*******************************
|
|
332
338
|
* API Methods
|
|
333
339
|
*******************************/
|
|
334
|
-
getBalances() {
|
|
340
|
+
getBalances(chainId) {
|
|
335
341
|
return __awaiter(this, void 0, void 0, function* () {
|
|
336
342
|
return new Promise((resolve, reject) => {
|
|
337
343
|
const handleGetBalances = (event) => {
|
|
@@ -359,7 +365,7 @@ class Mpc {
|
|
|
359
365
|
// Send the request to the iframe
|
|
360
366
|
this.postMessage({
|
|
361
367
|
type: 'portal:getBalances',
|
|
362
|
-
data: {},
|
|
368
|
+
data: { chainId },
|
|
363
369
|
});
|
|
364
370
|
});
|
|
365
371
|
});
|
|
@@ -397,7 +403,7 @@ class Mpc {
|
|
|
397
403
|
});
|
|
398
404
|
});
|
|
399
405
|
}
|
|
400
|
-
getNFTs() {
|
|
406
|
+
getNFTs(chainId) {
|
|
401
407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
402
408
|
return new Promise((resolve, reject) => {
|
|
403
409
|
const handleGetNFTs = (event) => {
|
|
@@ -425,12 +431,12 @@ class Mpc {
|
|
|
425
431
|
// Send the request to the iframe
|
|
426
432
|
this.postMessage({
|
|
427
433
|
type: 'portal:getNFTs',
|
|
428
|
-
data: {},
|
|
434
|
+
data: { chainId },
|
|
429
435
|
});
|
|
430
436
|
});
|
|
431
437
|
});
|
|
432
438
|
}
|
|
433
|
-
getQuote(apiKey, args) {
|
|
439
|
+
getQuote(apiKey, args, chainId) {
|
|
434
440
|
return __awaiter(this, void 0, void 0, function* () {
|
|
435
441
|
return new Promise((resolve, reject) => {
|
|
436
442
|
const handleGetQuote = (event) => {
|
|
@@ -461,12 +467,13 @@ class Mpc {
|
|
|
461
467
|
data: {
|
|
462
468
|
apiKey,
|
|
463
469
|
args,
|
|
470
|
+
chainId,
|
|
464
471
|
},
|
|
465
472
|
});
|
|
466
473
|
});
|
|
467
474
|
});
|
|
468
475
|
}
|
|
469
|
-
getSources(apiKey) {
|
|
476
|
+
getSources(apiKey, chainId) {
|
|
470
477
|
return __awaiter(this, void 0, void 0, function* () {
|
|
471
478
|
return new Promise((resolve, reject) => {
|
|
472
479
|
const handleGetSources = (event) => {
|
|
@@ -496,6 +503,7 @@ class Mpc {
|
|
|
496
503
|
type: 'portal:swaps:getSources',
|
|
497
504
|
data: {
|
|
498
505
|
apiKey,
|
|
506
|
+
chainId,
|
|
499
507
|
},
|
|
500
508
|
});
|
|
501
509
|
});
|
|
@@ -539,7 +547,42 @@ class Mpc {
|
|
|
539
547
|
});
|
|
540
548
|
});
|
|
541
549
|
}
|
|
542
|
-
|
|
550
|
+
setBackupStatus(status, backupIds) {
|
|
551
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
552
|
+
return new Promise((resolve, reject) => {
|
|
553
|
+
const handleSetBackupStatus = (event) => {
|
|
554
|
+
const { type, data } = event.data;
|
|
555
|
+
const { origin } = event;
|
|
556
|
+
// ignore any broadcast postMessages
|
|
557
|
+
if (origin !== this.getOrigin()) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (type === 'portal:api:setBackupStatusError') {
|
|
561
|
+
// Remove the event listener
|
|
562
|
+
window.removeEventListener('message', handleSetBackupStatus);
|
|
563
|
+
// Reject the promise with the error
|
|
564
|
+
return reject(new PortalMpcError(data));
|
|
565
|
+
}
|
|
566
|
+
else if (type === 'portal:api:setBackupStatusResult') {
|
|
567
|
+
// Remove the event listener
|
|
568
|
+
window.removeEventListener('message', handleSetBackupStatus);
|
|
569
|
+
// Resolve the promise with the result
|
|
570
|
+
return resolve(data);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
// Bind the function to the message event
|
|
574
|
+
window.addEventListener('message', handleSetBackupStatus);
|
|
575
|
+
this.postMessage({
|
|
576
|
+
type: 'portal:api:setBackupStatus',
|
|
577
|
+
data: {
|
|
578
|
+
backupIds,
|
|
579
|
+
status,
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
simulateTransaction(transaction, chainId) {
|
|
543
586
|
return __awaiter(this, void 0, void 0, function* () {
|
|
544
587
|
return new Promise((resolve, reject) => {
|
|
545
588
|
const handleSimulateTransaction = (event) => {
|
|
@@ -567,7 +610,10 @@ class Mpc {
|
|
|
567
610
|
// Send the request to the iframe
|
|
568
611
|
this.postMessage({
|
|
569
612
|
type: 'portal:simulateTransaction',
|
|
570
|
-
data:
|
|
613
|
+
data: {
|
|
614
|
+
chainId,
|
|
615
|
+
transaction,
|
|
616
|
+
},
|
|
571
617
|
});
|
|
572
618
|
});
|
|
573
619
|
});
|
|
@@ -108,17 +108,21 @@ class Provider {
|
|
|
108
108
|
* @param args The arguments of the request being made
|
|
109
109
|
* @returns Promise<any>
|
|
110
110
|
*/
|
|
111
|
-
request({ method, params }) {
|
|
111
|
+
request({ chainId, method, params, }) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
113
|
if (method === 'eth_chainId') {
|
|
114
|
-
return this.portal.chainId;
|
|
114
|
+
return chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId;
|
|
115
115
|
}
|
|
116
116
|
const isSignerMethod = signerMethods.includes(method);
|
|
117
|
-
let result;
|
|
118
117
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
119
118
|
// Send to Gateway for RPC calls
|
|
120
|
-
const response = yield this.handleGatewayRequest({
|
|
119
|
+
const response = yield this.handleGatewayRequest({
|
|
120
|
+
chainId,
|
|
121
|
+
method,
|
|
122
|
+
params,
|
|
123
|
+
});
|
|
121
124
|
this.emit('portal_signatureReceived', {
|
|
125
|
+
chainId,
|
|
122
126
|
method,
|
|
123
127
|
params,
|
|
124
128
|
signature: response,
|
|
@@ -126,21 +130,23 @@ class Provider {
|
|
|
126
130
|
if (response.error) {
|
|
127
131
|
throw new ProviderRpcError(response.error);
|
|
128
132
|
}
|
|
129
|
-
|
|
133
|
+
return response.result;
|
|
130
134
|
}
|
|
131
135
|
else if (isSignerMethod) {
|
|
132
136
|
// Handle signing
|
|
133
137
|
const transactionHash = yield this.handleSigningRequest({
|
|
138
|
+
chainId,
|
|
134
139
|
method,
|
|
135
140
|
params,
|
|
136
141
|
});
|
|
137
142
|
if (transactionHash) {
|
|
138
143
|
this.emit('portal_signatureReceived', {
|
|
144
|
+
chainId,
|
|
139
145
|
method,
|
|
140
146
|
params,
|
|
141
147
|
signature: transactionHash,
|
|
142
148
|
});
|
|
143
|
-
|
|
149
|
+
return transactionHash;
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
152
|
else {
|
|
@@ -153,7 +159,6 @@ class Provider {
|
|
|
153
159
|
},
|
|
154
160
|
});
|
|
155
161
|
}
|
|
156
|
-
return result;
|
|
157
162
|
});
|
|
158
163
|
}
|
|
159
164
|
/************************
|
|
@@ -216,13 +221,13 @@ class Provider {
|
|
|
216
221
|
* @param args The arguments of the request being made
|
|
217
222
|
* @returns Promise<any>
|
|
218
223
|
*/
|
|
219
|
-
handleGatewayRequest({ method, params, }) {
|
|
224
|
+
handleGatewayRequest({ chainId, method, params, }) {
|
|
220
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
221
226
|
// Pass request off to the gateway
|
|
222
227
|
const result = yield fetch(this.portal.getRpcUrl(), {
|
|
223
228
|
body: JSON.stringify({
|
|
224
229
|
jsonrpc: '2.0',
|
|
225
|
-
id: this.portal.chainId,
|
|
230
|
+
id: chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId,
|
|
226
231
|
method,
|
|
227
232
|
params,
|
|
228
233
|
}),
|
|
@@ -237,7 +242,7 @@ class Provider {
|
|
|
237
242
|
* @param args The arguments of the request being made
|
|
238
243
|
* @returns Promise<any>
|
|
239
244
|
*/
|
|
240
|
-
handleSigningRequest({ method, params, }) {
|
|
245
|
+
handleSigningRequest({ chainId, method, params, }) {
|
|
241
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
247
|
const isApproved = passiveSignerMethods.includes(method)
|
|
243
248
|
? true
|
|
@@ -259,7 +264,9 @@ class Provider {
|
|
|
259
264
|
case 'eth_signTypedData_v4':
|
|
260
265
|
case 'personal_sign': {
|
|
261
266
|
const result = yield this.portal.mpc.sign({
|
|
262
|
-
chainId:
|
|
267
|
+
chainId: chainId
|
|
268
|
+
? chainId.split(':')[1]
|
|
269
|
+
: this.portal.chainId.toString(),
|
|
263
270
|
method,
|
|
264
271
|
params: this.buildParams(method, params),
|
|
265
272
|
rpcUrl: this.portal.getRpcUrl(),
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
BackupConfigs,
|
|
3
|
+
BackupResponse,
|
|
3
4
|
BackupSharePairMetadata,
|
|
4
5
|
Balance,
|
|
5
|
-
|
|
6
|
+
ClientResponse,
|
|
6
7
|
EthereumTransaction,
|
|
7
8
|
FeatureFlags,
|
|
8
9
|
GDriveConfig,
|
|
@@ -168,8 +169,8 @@ class Portal {
|
|
|
168
169
|
// Noop
|
|
169
170
|
},
|
|
170
171
|
backupConfigs: BackupConfigs = {},
|
|
171
|
-
): Promise<
|
|
172
|
-
const
|
|
172
|
+
): Promise<BackupResponse> {
|
|
173
|
+
const response = await this.mpc.backup(
|
|
173
174
|
{
|
|
174
175
|
backupMethod,
|
|
175
176
|
backupConfigs,
|
|
@@ -180,7 +181,7 @@ class Portal {
|
|
|
180
181
|
progress,
|
|
181
182
|
)
|
|
182
183
|
|
|
183
|
-
return
|
|
184
|
+
return response
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
public async recoverWallet(
|
|
@@ -250,22 +251,28 @@ class Portal {
|
|
|
250
251
|
* Provider Methods
|
|
251
252
|
****************************/
|
|
252
253
|
|
|
253
|
-
public async ethEstimateGas(
|
|
254
|
+
public async ethEstimateGas(
|
|
255
|
+
transaction: EthereumTransaction,
|
|
256
|
+
chainId?: string,
|
|
257
|
+
): Promise<any> {
|
|
254
258
|
return this.provider.request({
|
|
259
|
+
chainId,
|
|
255
260
|
method: 'eth_estimateGas',
|
|
256
261
|
params: transaction,
|
|
257
262
|
})
|
|
258
263
|
}
|
|
259
264
|
|
|
260
|
-
public async ethGasPrice(): Promise<string> {
|
|
265
|
+
public async ethGasPrice(chainId?: string): Promise<string> {
|
|
261
266
|
return this.provider.request({
|
|
267
|
+
chainId,
|
|
262
268
|
method: 'eth_gasPrice',
|
|
263
269
|
params: [],
|
|
264
270
|
}) as Promise<string>
|
|
265
271
|
}
|
|
266
272
|
|
|
267
|
-
public async ethGetBalance(): Promise<string> {
|
|
273
|
+
public async ethGetBalance(chainId?: string): Promise<string> {
|
|
268
274
|
return this.provider.request({
|
|
275
|
+
chainId,
|
|
269
276
|
method: 'eth_getBalance',
|
|
270
277
|
params: [this.address, 'latest'],
|
|
271
278
|
}) as Promise<string>
|
|
@@ -273,15 +280,18 @@ class Portal {
|
|
|
273
280
|
|
|
274
281
|
public async ethSendTransaction(
|
|
275
282
|
transaction: EthereumTransaction,
|
|
283
|
+
chainId?: string,
|
|
276
284
|
): Promise<string> {
|
|
277
285
|
return this.provider.request({
|
|
286
|
+
chainId,
|
|
278
287
|
method: 'eth_sendTransaction',
|
|
279
288
|
params: transaction,
|
|
280
289
|
}) as Promise<string>
|
|
281
290
|
}
|
|
282
291
|
|
|
283
|
-
public async ethSign(message: string): Promise<string> {
|
|
292
|
+
public async ethSign(message: string, chainId?: string): Promise<string> {
|
|
284
293
|
return this.provider.request({
|
|
294
|
+
chainId,
|
|
285
295
|
method: 'eth_sign',
|
|
286
296
|
params: [this.address, this.stringToHex(message)],
|
|
287
297
|
}) as Promise<string>
|
|
@@ -289,39 +299,57 @@ class Portal {
|
|
|
289
299
|
|
|
290
300
|
public async ethSignTransaction(
|
|
291
301
|
transaction: EthereumTransaction,
|
|
302
|
+
chainId?: string,
|
|
292
303
|
): Promise<string> {
|
|
293
304
|
return this.provider.request({
|
|
305
|
+
chainId,
|
|
294
306
|
method: 'eth_signTransaction',
|
|
295
307
|
params: transaction,
|
|
296
308
|
}) as Promise<string>
|
|
297
309
|
}
|
|
298
310
|
|
|
299
|
-
public async ethSignTypedData(
|
|
311
|
+
public async ethSignTypedData(
|
|
312
|
+
data: TypedData,
|
|
313
|
+
chainId?: string,
|
|
314
|
+
): Promise<string> {
|
|
300
315
|
return this.provider.request({
|
|
316
|
+
chainId,
|
|
301
317
|
method: 'eth_signTypedData',
|
|
302
318
|
params: [this.address, data],
|
|
303
319
|
}) as Promise<string>
|
|
304
320
|
}
|
|
305
321
|
|
|
306
|
-
public async ethSignTypedDataV3(
|
|
322
|
+
public async ethSignTypedDataV3(
|
|
323
|
+
data: TypedData,
|
|
324
|
+
chainId?: string,
|
|
325
|
+
): Promise<string> {
|
|
307
326
|
return this.provider.request({
|
|
327
|
+
chainId,
|
|
308
328
|
method: 'eth_signTypedData_v3',
|
|
309
329
|
params: [this.address, data],
|
|
310
330
|
}) as Promise<string>
|
|
311
331
|
}
|
|
312
332
|
|
|
313
|
-
public async ethSignTypedDataV4(
|
|
333
|
+
public async ethSignTypedDataV4(
|
|
334
|
+
data: TypedData,
|
|
335
|
+
chainId?: string,
|
|
336
|
+
): Promise<string> {
|
|
314
337
|
return this.provider.request({
|
|
338
|
+
chainId,
|
|
315
339
|
method: 'eth_signTypedData_v4',
|
|
316
340
|
params: [this.address, data],
|
|
317
341
|
}) as Promise<string>
|
|
318
342
|
}
|
|
319
343
|
|
|
320
|
-
public async personalSign(
|
|
321
|
-
|
|
344
|
+
public async personalSign(
|
|
345
|
+
message: string,
|
|
346
|
+
chainId?: string,
|
|
347
|
+
): Promise<string> {
|
|
348
|
+
return (await this.provider.request({
|
|
349
|
+
chainId,
|
|
322
350
|
method: 'personal_sign',
|
|
323
351
|
params: [this.stringToHex(message), this.address],
|
|
324
|
-
}) as Promise<string>
|
|
352
|
+
})) as Promise<string>
|
|
325
353
|
}
|
|
326
354
|
|
|
327
355
|
/*******************************
|
|
@@ -332,7 +360,7 @@ class Portal {
|
|
|
332
360
|
return await this.mpc?.getBalances()
|
|
333
361
|
}
|
|
334
362
|
|
|
335
|
-
public async getClient(): Promise<
|
|
363
|
+
public async getClient(): Promise<ClientResponse> {
|
|
336
364
|
return this.mpc?.getClient()
|
|
337
365
|
}
|
|
338
366
|
|
|
@@ -352,7 +380,7 @@ class Portal {
|
|
|
352
380
|
limit?: number,
|
|
353
381
|
offset?: number,
|
|
354
382
|
order?: GetTransactionsOrder,
|
|
355
|
-
chainId?:
|
|
383
|
+
chainId?: string,
|
|
356
384
|
): Promise<Transaction[]> {
|
|
357
385
|
return this.mpc?.getTransactions(limit, offset, order, chainId)
|
|
358
386
|
}
|
|
@@ -370,12 +398,16 @@ class Portal {
|
|
|
370
398
|
public async getQuote(
|
|
371
399
|
apiKey: string,
|
|
372
400
|
args: QuoteArgs,
|
|
401
|
+
chainId?: string,
|
|
373
402
|
): Promise<QuoteResponse> {
|
|
374
|
-
return this.mpc?.getQuote(apiKey, args)
|
|
403
|
+
return this.mpc?.getQuote(apiKey, args, chainId)
|
|
375
404
|
}
|
|
376
405
|
|
|
377
|
-
public async getSources(
|
|
378
|
-
|
|
406
|
+
public async getSources(
|
|
407
|
+
apiKey: string,
|
|
408
|
+
chainId?: string,
|
|
409
|
+
): Promise<Record<string, string>> {
|
|
410
|
+
return this.mpc?.getSources(apiKey, chainId)
|
|
379
411
|
}
|
|
380
412
|
|
|
381
413
|
/*******************************
|
package/src/mpc/index.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { PortalMpcError } from './errors'
|
|
|
3
3
|
import Portal, { BackupMethods, GetTransactionsOrder } from '../index'
|
|
4
4
|
import type {
|
|
5
5
|
BackupArgs,
|
|
6
|
+
BackupResponse,
|
|
6
7
|
BackupSharePairMetadata,
|
|
7
8
|
Balance,
|
|
8
|
-
|
|
9
|
+
ClientResponse,
|
|
9
10
|
EjectArgs,
|
|
10
11
|
GenerateArgs,
|
|
11
12
|
IframeConfigurationOptions,
|
|
@@ -25,7 +26,7 @@ import type {
|
|
|
25
26
|
WorkerResult,
|
|
26
27
|
} from '../../types'
|
|
27
28
|
|
|
28
|
-
const WEB_SDK_VERSION = '
|
|
29
|
+
const WEB_SDK_VERSION = '2.0.0'
|
|
29
30
|
|
|
30
31
|
class Mpc {
|
|
31
32
|
public iframe?: HTMLIFrameElement
|
|
@@ -51,7 +52,7 @@ class Mpc {
|
|
|
51
52
|
progress: ProgressCallback = () => {
|
|
52
53
|
// Noop
|
|
53
54
|
},
|
|
54
|
-
): Promise<
|
|
55
|
+
): Promise<BackupResponse> {
|
|
55
56
|
const message = {
|
|
56
57
|
type: 'portal:wasm:backup',
|
|
57
58
|
data,
|
|
@@ -83,8 +84,18 @@ class Mpc {
|
|
|
83
84
|
window.removeEventListener('message', handleBackup)
|
|
84
85
|
window.removeEventListener('message', handleProgress)
|
|
85
86
|
|
|
87
|
+
const storageCallback = async () => {
|
|
88
|
+
await this.setBackupStatus(
|
|
89
|
+
'STORED_CLIENT_BACKUP_SHARE',
|
|
90
|
+
result.backupIds,
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
// Resolve the promise with the result
|
|
87
|
-
resolve(
|
|
95
|
+
resolve({
|
|
96
|
+
cipherText: result.cipherText,
|
|
97
|
+
storageCallback,
|
|
98
|
+
})
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
|
|
@@ -394,7 +405,7 @@ class Mpc {
|
|
|
394
405
|
* API Methods
|
|
395
406
|
*******************************/
|
|
396
407
|
|
|
397
|
-
public async getBalances(): Promise<Balance[]> {
|
|
408
|
+
public async getBalances(chainId?: string): Promise<Balance[]> {
|
|
398
409
|
return new Promise((resolve, reject) => {
|
|
399
410
|
const handleGetBalances = (event: MessageEvent<WorkerResult>) => {
|
|
400
411
|
const { type, data } = event.data
|
|
@@ -426,12 +437,12 @@ class Mpc {
|
|
|
426
437
|
// Send the request to the iframe
|
|
427
438
|
this.postMessage({
|
|
428
439
|
type: 'portal:getBalances',
|
|
429
|
-
data: {},
|
|
440
|
+
data: { chainId },
|
|
430
441
|
})
|
|
431
442
|
})
|
|
432
443
|
}
|
|
433
444
|
|
|
434
|
-
public async getClient(): Promise<
|
|
445
|
+
public async getClient(): Promise<ClientResponse> {
|
|
435
446
|
return new Promise((resolve, reject) => {
|
|
436
447
|
const handleGetClient = (event: MessageEvent<WorkerResult>) => {
|
|
437
448
|
const { type, data } = event.data
|
|
@@ -453,7 +464,7 @@ class Mpc {
|
|
|
453
464
|
window.removeEventListener('message', handleGetClient)
|
|
454
465
|
|
|
455
466
|
// Resolve the promise with the result
|
|
456
|
-
resolve(data as
|
|
467
|
+
resolve(data as ClientResponse)
|
|
457
468
|
}
|
|
458
469
|
}
|
|
459
470
|
|
|
@@ -468,7 +479,7 @@ class Mpc {
|
|
|
468
479
|
})
|
|
469
480
|
}
|
|
470
481
|
|
|
471
|
-
public async getNFTs(): Promise<NFT[]> {
|
|
482
|
+
public async getNFTs(chainId?: string): Promise<NFT[]> {
|
|
472
483
|
return new Promise((resolve, reject) => {
|
|
473
484
|
const handleGetNFTs = (event: MessageEvent<WorkerResult>) => {
|
|
474
485
|
const { type, data } = event.data
|
|
@@ -500,7 +511,7 @@ class Mpc {
|
|
|
500
511
|
// Send the request to the iframe
|
|
501
512
|
this.postMessage({
|
|
502
513
|
type: 'portal:getNFTs',
|
|
503
|
-
data: {},
|
|
514
|
+
data: { chainId },
|
|
504
515
|
})
|
|
505
516
|
})
|
|
506
517
|
}
|
|
@@ -508,6 +519,7 @@ class Mpc {
|
|
|
508
519
|
public async getQuote(
|
|
509
520
|
apiKey: string,
|
|
510
521
|
args: QuoteArgs,
|
|
522
|
+
chainId?: string,
|
|
511
523
|
): Promise<QuoteResponse> {
|
|
512
524
|
return new Promise((resolve, reject) => {
|
|
513
525
|
const handleGetQuote = (event: MessageEvent<WorkerResult>) => {
|
|
@@ -542,12 +554,16 @@ class Mpc {
|
|
|
542
554
|
data: {
|
|
543
555
|
apiKey,
|
|
544
556
|
args,
|
|
557
|
+
chainId,
|
|
545
558
|
},
|
|
546
559
|
})
|
|
547
560
|
})
|
|
548
561
|
}
|
|
549
562
|
|
|
550
|
-
public async getSources(
|
|
563
|
+
public async getSources(
|
|
564
|
+
apiKey: string,
|
|
565
|
+
chainId?: string,
|
|
566
|
+
): Promise<Record<string, string>> {
|
|
551
567
|
return new Promise((resolve, reject) => {
|
|
552
568
|
const handleGetSources = (event: MessageEvent<WorkerResult>) => {
|
|
553
569
|
const { type, data: result } = event.data
|
|
@@ -580,6 +596,7 @@ class Mpc {
|
|
|
580
596
|
type: 'portal:swaps:getSources',
|
|
581
597
|
data: {
|
|
582
598
|
apiKey,
|
|
599
|
+
chainId,
|
|
583
600
|
},
|
|
584
601
|
})
|
|
585
602
|
})
|
|
@@ -589,7 +606,7 @@ class Mpc {
|
|
|
589
606
|
limit?: number,
|
|
590
607
|
offset?: number,
|
|
591
608
|
order?: GetTransactionsOrder,
|
|
592
|
-
chainId?:
|
|
609
|
+
chainId?: string,
|
|
593
610
|
): Promise<Transaction[]> {
|
|
594
611
|
return new Promise((resolve, reject) => {
|
|
595
612
|
const handleGetTransactions = (event: MessageEvent<WorkerResult>) => {
|
|
@@ -632,8 +649,51 @@ class Mpc {
|
|
|
632
649
|
})
|
|
633
650
|
}
|
|
634
651
|
|
|
652
|
+
public async setBackupStatus(
|
|
653
|
+
status: string,
|
|
654
|
+
backupIds: string[],
|
|
655
|
+
): Promise<boolean> {
|
|
656
|
+
return new Promise((resolve, reject) => {
|
|
657
|
+
const handleSetBackupStatus = (event: MessageEvent<WorkerResult>) => {
|
|
658
|
+
const { type, data } = event.data
|
|
659
|
+
const { origin } = event
|
|
660
|
+
|
|
661
|
+
// ignore any broadcast postMessages
|
|
662
|
+
if (origin !== this.getOrigin()) {
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (type === 'portal:api:setBackupStatusError') {
|
|
667
|
+
// Remove the event listener
|
|
668
|
+
window.removeEventListener('message', handleSetBackupStatus)
|
|
669
|
+
|
|
670
|
+
// Reject the promise with the error
|
|
671
|
+
return reject(new PortalMpcError(data as PortalError))
|
|
672
|
+
} else if (type === 'portal:api:setBackupStatusResult') {
|
|
673
|
+
// Remove the event listener
|
|
674
|
+
window.removeEventListener('message', handleSetBackupStatus)
|
|
675
|
+
|
|
676
|
+
// Resolve the promise with the result
|
|
677
|
+
return resolve(data)
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Bind the function to the message event
|
|
682
|
+
window.addEventListener('message', handleSetBackupStatus)
|
|
683
|
+
|
|
684
|
+
this.postMessage({
|
|
685
|
+
type: 'portal:api:setBackupStatus',
|
|
686
|
+
data: {
|
|
687
|
+
backupIds,
|
|
688
|
+
status,
|
|
689
|
+
},
|
|
690
|
+
})
|
|
691
|
+
})
|
|
692
|
+
}
|
|
693
|
+
|
|
635
694
|
public async simulateTransaction(
|
|
636
695
|
transaction: SimulateTransactionParam,
|
|
696
|
+
chainId?: string,
|
|
637
697
|
): Promise<SimulatedTransaction> {
|
|
638
698
|
return new Promise((resolve, reject) => {
|
|
639
699
|
const handleSimulateTransaction = (event: MessageEvent<WorkerResult>) => {
|
|
@@ -666,7 +726,10 @@ class Mpc {
|
|
|
666
726
|
// Send the request to the iframe
|
|
667
727
|
this.postMessage({
|
|
668
728
|
type: 'portal:simulateTransaction',
|
|
669
|
-
data:
|
|
729
|
+
data: {
|
|
730
|
+
chainId,
|
|
731
|
+
transaction,
|
|
732
|
+
},
|
|
670
733
|
})
|
|
671
734
|
})
|
|
672
735
|
}
|
package/src/provider/index.ts
CHANGED
|
@@ -113,19 +113,27 @@ class Provider {
|
|
|
113
113
|
* @param args The arguments of the request being made
|
|
114
114
|
* @returns Promise<any>
|
|
115
115
|
*/
|
|
116
|
-
public async request({
|
|
116
|
+
public async request({
|
|
117
|
+
chainId,
|
|
118
|
+
method,
|
|
119
|
+
params,
|
|
120
|
+
}: RequestArguments): Promise<any> {
|
|
117
121
|
if (method === 'eth_chainId') {
|
|
118
|
-
return this.portal.chainId
|
|
122
|
+
return chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
const isSignerMethod = signerMethods.includes(method)
|
|
122
126
|
|
|
123
|
-
let result: any
|
|
124
127
|
if (!isSignerMethod && !method.startsWith('wallet_')) {
|
|
125
128
|
// Send to Gateway for RPC calls
|
|
126
|
-
const response = await this.handleGatewayRequest({
|
|
129
|
+
const response = await this.handleGatewayRequest({
|
|
130
|
+
chainId,
|
|
131
|
+
method,
|
|
132
|
+
params,
|
|
133
|
+
})
|
|
127
134
|
|
|
128
135
|
this.emit('portal_signatureReceived', {
|
|
136
|
+
chainId,
|
|
129
137
|
method,
|
|
130
138
|
params,
|
|
131
139
|
signature: response,
|
|
@@ -135,22 +143,24 @@ class Provider {
|
|
|
135
143
|
throw new ProviderRpcError(response.error as RpcErrorOptions)
|
|
136
144
|
}
|
|
137
145
|
|
|
138
|
-
|
|
146
|
+
return response.result
|
|
139
147
|
} else if (isSignerMethod) {
|
|
140
148
|
// Handle signing
|
|
141
149
|
const transactionHash = await this.handleSigningRequest({
|
|
150
|
+
chainId,
|
|
142
151
|
method,
|
|
143
152
|
params,
|
|
144
153
|
})
|
|
145
154
|
|
|
146
155
|
if (transactionHash) {
|
|
147
156
|
this.emit('portal_signatureReceived', {
|
|
157
|
+
chainId,
|
|
148
158
|
method,
|
|
149
159
|
params,
|
|
150
160
|
signature: transactionHash,
|
|
151
161
|
})
|
|
152
162
|
|
|
153
|
-
|
|
163
|
+
return transactionHash
|
|
154
164
|
}
|
|
155
165
|
} else {
|
|
156
166
|
// Unsupported method
|
|
@@ -162,8 +172,6 @@ class Provider {
|
|
|
162
172
|
},
|
|
163
173
|
})
|
|
164
174
|
}
|
|
165
|
-
|
|
166
|
-
return result
|
|
167
175
|
}
|
|
168
176
|
|
|
169
177
|
/************************
|
|
@@ -252,6 +260,7 @@ class Provider {
|
|
|
252
260
|
* @returns Promise<any>
|
|
253
261
|
*/
|
|
254
262
|
private async handleGatewayRequest({
|
|
263
|
+
chainId,
|
|
255
264
|
method,
|
|
256
265
|
params,
|
|
257
266
|
}: RequestArguments): Promise<any> {
|
|
@@ -259,7 +268,7 @@ class Provider {
|
|
|
259
268
|
const result = await fetch(this.portal.getRpcUrl(), {
|
|
260
269
|
body: JSON.stringify({
|
|
261
270
|
jsonrpc: '2.0',
|
|
262
|
-
id: this.portal.chainId,
|
|
271
|
+
id: chainId ? parseInt(chainId.split(':')[1]) : this.portal.chainId,
|
|
263
272
|
method,
|
|
264
273
|
params,
|
|
265
274
|
}),
|
|
@@ -276,6 +285,7 @@ class Provider {
|
|
|
276
285
|
* @returns Promise<any>
|
|
277
286
|
*/
|
|
278
287
|
private async handleSigningRequest({
|
|
288
|
+
chainId,
|
|
279
289
|
method,
|
|
280
290
|
params,
|
|
281
291
|
}: RequestArguments): Promise<any> {
|
|
@@ -303,7 +313,9 @@ class Provider {
|
|
|
303
313
|
case 'eth_signTypedData_v4':
|
|
304
314
|
case 'personal_sign': {
|
|
305
315
|
const result = await this.portal.mpc.sign({
|
|
306
|
-
chainId:
|
|
316
|
+
chainId: chainId
|
|
317
|
+
? chainId.split(':')[1]
|
|
318
|
+
: this.portal.chainId.toString(),
|
|
307
319
|
method,
|
|
308
320
|
params: this.buildParams(method, params),
|
|
309
321
|
rpcUrl: this.portal.getRpcUrl(),
|
package/types.d.ts
CHANGED
|
@@ -62,8 +62,8 @@ export interface BackupData {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface BackupResult {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
backupIds: string[]
|
|
66
|
+
cipherText: string
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface Bk {
|
|
@@ -77,20 +77,53 @@ export interface Address {
|
|
|
77
77
|
value: string
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
export interface BackupResponse {
|
|
81
|
+
cipherText: string
|
|
82
|
+
storageCallback: () => Promise<void>
|
|
83
|
+
}
|
|
84
|
+
|
|
80
85
|
export interface Balance {
|
|
81
86
|
contractAddress: string
|
|
82
87
|
balance: string
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
export interface
|
|
90
|
+
export interface ClientResponse {
|
|
86
91
|
id: string
|
|
87
92
|
address: string
|
|
88
93
|
backupStatus?: string | null
|
|
89
|
-
custodian:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
custodian: ClientResponseCustodian
|
|
95
|
+
ejectedAt: string | null
|
|
96
|
+
isAccountAbstracted: boolean
|
|
97
|
+
metadata: ClientResponseMetadata
|
|
98
|
+
wallets: ClientResponseWallet[]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface ClientResponseCustodian {
|
|
102
|
+
id: string
|
|
103
|
+
name: string
|
|
104
|
+
}
|
|
105
|
+
interface ClientResponseMetadata {
|
|
106
|
+
namespaces: ClientNamespaceMetadata
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ClientResponseNamespaceMetadata {
|
|
110
|
+
[key: Namespace]: NamespaceMetadataItem
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface ClientResponseSharePair {
|
|
114
|
+
id: string
|
|
115
|
+
createdAt: string
|
|
116
|
+
status: SharePairStatus
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ClientResponseWallet {
|
|
120
|
+
id: string
|
|
121
|
+
createdAt: string
|
|
122
|
+
|
|
123
|
+
backupSharePairs: ClientResponseSharePair[]
|
|
124
|
+
curve: WalletCurve
|
|
125
|
+
publicKey: string
|
|
126
|
+
signingSharePairs: ClientResponseShairPair[]
|
|
94
127
|
}
|
|
95
128
|
|
|
96
129
|
export interface DappOnNetwork {
|
|
@@ -392,6 +425,7 @@ export interface RegisteredEventHandler {
|
|
|
392
425
|
}
|
|
393
426
|
|
|
394
427
|
export interface RequestArguments {
|
|
428
|
+
chainId?: string
|
|
395
429
|
method: string
|
|
396
430
|
params?: unknown[] | SigningRequestParams
|
|
397
431
|
}
|