@portal-hq/web 0.0.3 → 0.0.5
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 +43 -5
- package/lib/commonjs/mpc/index.js +197 -49
- package/lib/esm/index.js +43 -5
- package/lib/esm/mpc/index.js +197 -49
- package/package.json +1 -1
- package/src/index.ts +54 -6
- package/src/mpc/index.ts +214 -37
- package/types.d.ts +17 -6
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 = '0.0.
|
|
12
|
+
const WEB_SDK_VERSION = '0.0.5';
|
|
13
13
|
class Mpc {
|
|
14
14
|
constructor({ portal }) {
|
|
15
15
|
this.configureIframe = () => {
|
|
@@ -37,6 +37,9 @@ class Mpc {
|
|
|
37
37
|
// Create the iFrame for MPC operations
|
|
38
38
|
this.appendIframe();
|
|
39
39
|
}
|
|
40
|
+
/*******************************
|
|
41
|
+
* Wallet Methods
|
|
42
|
+
*******************************/
|
|
40
43
|
backup(data, progress = () => {
|
|
41
44
|
// Noop
|
|
42
45
|
}) {
|
|
@@ -338,71 +341,180 @@ class Mpc {
|
|
|
338
341
|
});
|
|
339
342
|
});
|
|
340
343
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
344
|
+
/*******************************
|
|
345
|
+
* API Methods
|
|
346
|
+
*******************************/
|
|
347
|
+
getBalances() {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
return new Promise((resolve, reject) => {
|
|
350
|
+
const handleGetBalances = (event) => {
|
|
351
|
+
const { type, data } = event.data;
|
|
352
|
+
const { origin } = event;
|
|
353
|
+
// ignore any broadcast postMessages
|
|
354
|
+
if (origin !== this.getOrigin()) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (type === 'portal:getBalancesError') {
|
|
358
|
+
// Remove the event listener
|
|
359
|
+
window.removeEventListener('message', handleGetBalances);
|
|
360
|
+
// Reject the promise with the error
|
|
361
|
+
return reject(new PortalMpcError(data));
|
|
362
|
+
}
|
|
363
|
+
else if (type === 'portal:getBalancesResult') {
|
|
364
|
+
// Remove the event listener
|
|
365
|
+
window.removeEventListener('message', handleGetBalances);
|
|
366
|
+
// Resolve the promise with the result
|
|
367
|
+
resolve(data);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
// Bind the function to the message event
|
|
371
|
+
window.addEventListener('message', handleGetBalances);
|
|
372
|
+
// Send the request to the iframe
|
|
373
|
+
this.postMessage({
|
|
374
|
+
type: 'portal:getBalances',
|
|
375
|
+
data: {},
|
|
376
|
+
});
|
|
369
377
|
});
|
|
370
378
|
});
|
|
371
379
|
}
|
|
372
|
-
|
|
380
|
+
getClient() {
|
|
373
381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
374
382
|
return new Promise((resolve, reject) => {
|
|
375
|
-
const
|
|
383
|
+
const handleGetClient = (event) => {
|
|
376
384
|
const { type, data } = event.data;
|
|
377
385
|
const { origin } = event;
|
|
378
386
|
// ignore any broadcast postMessages
|
|
379
387
|
if (origin !== this.getOrigin()) {
|
|
380
388
|
return;
|
|
381
389
|
}
|
|
382
|
-
if (type === 'portal:
|
|
390
|
+
if (type === 'portal:getClientError') {
|
|
383
391
|
// Remove the event listener
|
|
384
|
-
window.removeEventListener('message',
|
|
392
|
+
window.removeEventListener('message', handleGetClient);
|
|
385
393
|
// Reject the promise with the error
|
|
386
394
|
return reject(new PortalMpcError(data));
|
|
387
395
|
}
|
|
388
|
-
else if (type === 'portal:
|
|
396
|
+
else if (type === 'portal:getClientResult') {
|
|
389
397
|
// Remove the event listener
|
|
390
|
-
window.removeEventListener('message',
|
|
398
|
+
window.removeEventListener('message', handleGetClient);
|
|
391
399
|
// Resolve the promise with the result
|
|
392
400
|
resolve(data);
|
|
393
401
|
}
|
|
394
402
|
};
|
|
395
403
|
// Bind the function to the message event
|
|
396
|
-
window.addEventListener('message',
|
|
404
|
+
window.addEventListener('message', handleGetClient);
|
|
397
405
|
// Send the request to the iframe
|
|
398
406
|
this.postMessage({
|
|
399
|
-
type: 'portal:
|
|
400
|
-
data:
|
|
407
|
+
type: 'portal:getClient',
|
|
408
|
+
data: {},
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
getNFTs() {
|
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
+
return new Promise((resolve, reject) => {
|
|
416
|
+
const handleGetNFTs = (event) => {
|
|
417
|
+
const { type, data } = event.data;
|
|
418
|
+
const { origin } = event;
|
|
419
|
+
// ignore any broadcast postMessages
|
|
420
|
+
if (origin !== this.getOrigin()) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (type === 'portal:getNFTsError') {
|
|
424
|
+
// Remove the event listener
|
|
425
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
426
|
+
// Reject the promise with the error
|
|
427
|
+
return reject(new PortalMpcError(data));
|
|
428
|
+
}
|
|
429
|
+
else if (type === 'portal:getNFTsResult') {
|
|
430
|
+
// Remove the event listener
|
|
431
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
432
|
+
// Resolve the promise with the result
|
|
433
|
+
resolve(data);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
// Bind the function to the message event
|
|
437
|
+
window.addEventListener('message', handleGetNFTs);
|
|
438
|
+
// Send the request to the iframe
|
|
439
|
+
this.postMessage({
|
|
440
|
+
type: 'portal:getNFTs',
|
|
441
|
+
data: {},
|
|
401
442
|
});
|
|
402
443
|
});
|
|
403
444
|
});
|
|
404
445
|
}
|
|
405
|
-
|
|
446
|
+
getQuote(apiKey, args) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
return new Promise((resolve, reject) => {
|
|
449
|
+
const handleGetQuote = (event) => {
|
|
450
|
+
const { type, data: result } = event.data;
|
|
451
|
+
const { origin } = event;
|
|
452
|
+
// ignore any broadcast postMessages
|
|
453
|
+
if (origin !== this.getOrigin()) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (type === 'portal:swaps:getQuoteError') {
|
|
457
|
+
// Remove the event listener
|
|
458
|
+
window.removeEventListener('message', handleGetQuote);
|
|
459
|
+
// Reject the promise with the error
|
|
460
|
+
return reject(new PortalMpcError(result));
|
|
461
|
+
}
|
|
462
|
+
else if (type === 'portal:swaps:getQuoteResult') {
|
|
463
|
+
// Remove the event listener
|
|
464
|
+
window.removeEventListener('message', handleGetQuote);
|
|
465
|
+
// Resolve the promise with the result
|
|
466
|
+
resolve(result);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
// Bind the function to the message event
|
|
470
|
+
window.addEventListener('message', handleGetQuote);
|
|
471
|
+
// Send the request to the iframe
|
|
472
|
+
this.postMessage({
|
|
473
|
+
type: 'portal:swaps:getQuote',
|
|
474
|
+
data: {
|
|
475
|
+
apiKey,
|
|
476
|
+
args,
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
getSources(apiKey) {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
return new Promise((resolve, reject) => {
|
|
485
|
+
const handleGetSources = (event) => {
|
|
486
|
+
const { type, data: result } = event.data;
|
|
487
|
+
const { origin } = event;
|
|
488
|
+
// ignore any broadcast postMessages
|
|
489
|
+
if (origin !== this.getOrigin()) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (type === 'portal:swaps:getSourcesError') {
|
|
493
|
+
// Remove the event listener
|
|
494
|
+
window.removeEventListener('message', handleGetSources);
|
|
495
|
+
// Reject the promise with the error
|
|
496
|
+
return reject(new PortalMpcError(result));
|
|
497
|
+
}
|
|
498
|
+
else if (type === 'portal:swaps:getSourcesResult') {
|
|
499
|
+
// Remove the event listener
|
|
500
|
+
window.removeEventListener('message', handleGetSources);
|
|
501
|
+
// Resolve the promise with the result
|
|
502
|
+
resolve(result);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
// Bind the function to the message event
|
|
506
|
+
window.addEventListener('message', handleGetSources);
|
|
507
|
+
// Send the request to the iframe
|
|
508
|
+
this.postMessage({
|
|
509
|
+
type: 'portal:swaps:getSources',
|
|
510
|
+
data: {
|
|
511
|
+
apiKey,
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
getTransactions(limit, offset, order, chainId) {
|
|
406
518
|
return __awaiter(this, void 0, void 0, function* () {
|
|
407
519
|
return new Promise((resolve, reject) => {
|
|
408
520
|
const handleGetTransactions = (event) => {
|
|
@@ -430,44 +542,80 @@ class Mpc {
|
|
|
430
542
|
// Send the request to the iframe
|
|
431
543
|
this.postMessage({
|
|
432
544
|
type: 'portal:getTransactions',
|
|
433
|
-
data: {
|
|
545
|
+
data: {
|
|
546
|
+
limit,
|
|
547
|
+
offset,
|
|
548
|
+
order,
|
|
549
|
+
chainId,
|
|
550
|
+
},
|
|
434
551
|
});
|
|
435
552
|
});
|
|
436
553
|
});
|
|
437
554
|
}
|
|
438
|
-
|
|
555
|
+
simulateTransaction(transaction) {
|
|
439
556
|
return __awaiter(this, void 0, void 0, function* () {
|
|
440
557
|
return new Promise((resolve, reject) => {
|
|
441
|
-
const
|
|
558
|
+
const handleSimulateTransaction = (event) => {
|
|
442
559
|
const { type, data } = event.data;
|
|
443
560
|
const { origin } = event;
|
|
444
561
|
// ignore any broadcast postMessages
|
|
445
562
|
if (origin !== this.getOrigin()) {
|
|
446
563
|
return;
|
|
447
564
|
}
|
|
448
|
-
if (type === 'portal:
|
|
565
|
+
if (type === 'portal:simulateTransactionError') {
|
|
449
566
|
// Remove the event listener
|
|
450
|
-
window.removeEventListener('message',
|
|
567
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
451
568
|
// Reject the promise with the error
|
|
452
569
|
return reject(new PortalMpcError(data));
|
|
453
570
|
}
|
|
454
|
-
else if (type === 'portal:
|
|
571
|
+
else if (type === 'portal:simulateTransactionResult') {
|
|
455
572
|
// Remove the event listener
|
|
456
|
-
window.removeEventListener('message',
|
|
573
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
457
574
|
// Resolve the promise with the result
|
|
458
575
|
resolve(data);
|
|
459
576
|
}
|
|
460
577
|
};
|
|
461
578
|
// Bind the function to the message event
|
|
462
|
-
window.addEventListener('message',
|
|
579
|
+
window.addEventListener('message', handleSimulateTransaction);
|
|
463
580
|
// Send the request to the iframe
|
|
464
581
|
this.postMessage({
|
|
465
|
-
type: 'portal:
|
|
466
|
-
data:
|
|
582
|
+
type: 'portal:simulateTransaction',
|
|
583
|
+
data: transaction,
|
|
467
584
|
});
|
|
468
585
|
});
|
|
469
586
|
});
|
|
470
587
|
}
|
|
588
|
+
storedClientBackupShare(success) {
|
|
589
|
+
return new Promise((resolve, reject) => {
|
|
590
|
+
const handleStoredClientBackupShare = (event) => {
|
|
591
|
+
const { type, data } = event.data;
|
|
592
|
+
const { origin } = event;
|
|
593
|
+
// ignore any broadcast postMessages
|
|
594
|
+
if (origin !== this.getOrigin()) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (type === 'portal:storedClientBackupShareError') {
|
|
598
|
+
// Remove the event listener
|
|
599
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
600
|
+
// Reject the promise with the error
|
|
601
|
+
return reject(new PortalMpcError(data));
|
|
602
|
+
}
|
|
603
|
+
else if (type === 'portal:storedClientBackupShareResult') {
|
|
604
|
+
// Remove the event listener
|
|
605
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
606
|
+
// Resolve the promise with the result
|
|
607
|
+
resolve();
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
// Bind the function to the message event
|
|
611
|
+
window.addEventListener('message', handleStoredClientBackupShare);
|
|
612
|
+
// Send the request to the iframe
|
|
613
|
+
this.postMessage({
|
|
614
|
+
type: 'portal:storedClientBackupShare',
|
|
615
|
+
data: success,
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
}
|
|
471
619
|
/***************************
|
|
472
620
|
* Private Methods
|
|
473
621
|
***************************/
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
ClientWithCustodianData,
|
|
3
2
|
BackupConfigs,
|
|
3
|
+
Balance,
|
|
4
|
+
ClientWithCustodianData,
|
|
4
5
|
EthereumTransaction,
|
|
5
6
|
FeatureFlags,
|
|
6
7
|
GDriveConfig,
|
|
7
8
|
GatewayLike,
|
|
9
|
+
GetTransactionsOrder,
|
|
10
|
+
NFT,
|
|
8
11
|
PortalOptions,
|
|
9
12
|
ProgressCallback,
|
|
13
|
+
QuoteArgs,
|
|
14
|
+
QuoteResponse,
|
|
10
15
|
SimulateTransactionParam,
|
|
11
16
|
SimulatedTransaction,
|
|
12
17
|
Transaction,
|
|
@@ -46,7 +51,7 @@ class Portal {
|
|
|
46
51
|
chainId = 1,
|
|
47
52
|
gdrive,
|
|
48
53
|
host = 'web.portalhq.io',
|
|
49
|
-
mpcVersion = '
|
|
54
|
+
mpcVersion = 'v5',
|
|
50
55
|
featureFlags = {
|
|
51
56
|
optimized: false,
|
|
52
57
|
},
|
|
@@ -191,6 +196,10 @@ class Portal {
|
|
|
191
196
|
return address
|
|
192
197
|
}
|
|
193
198
|
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
201
|
+
* Use the `recoverWallet` method instead.
|
|
202
|
+
*/
|
|
194
203
|
public async legacyRecoverWallet(
|
|
195
204
|
cipherText: string,
|
|
196
205
|
progress: ProgressCallback = () => {
|
|
@@ -212,6 +221,17 @@ class Portal {
|
|
|
212
221
|
return recoveredCipherText
|
|
213
222
|
}
|
|
214
223
|
|
|
224
|
+
public async provisionWallet(
|
|
225
|
+
cipherText: string,
|
|
226
|
+
backupMethod: BackupMethods,
|
|
227
|
+
backupConfigs: BackupConfigs,
|
|
228
|
+
progress: ProgressCallback = () => {
|
|
229
|
+
// Noop
|
|
230
|
+
},
|
|
231
|
+
): Promise<string> {
|
|
232
|
+
return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress)
|
|
233
|
+
}
|
|
234
|
+
|
|
215
235
|
/****************************
|
|
216
236
|
* Provider Methods
|
|
217
237
|
****************************/
|
|
@@ -272,18 +292,46 @@ class Portal {
|
|
|
272
292
|
* API Methods
|
|
273
293
|
*******************************/
|
|
274
294
|
|
|
295
|
+
public async getBalances(): Promise<Balance[]> {
|
|
296
|
+
return await this.mpc?.getBalances()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public async getClient(): Promise<ClientWithCustodianData> {
|
|
300
|
+
return this.mpc?.getClient()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
public async getNFTs(): Promise<NFT[]> {
|
|
304
|
+
return this.mpc?.getNFTs()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
public async getTransactions(
|
|
308
|
+
limit?: number,
|
|
309
|
+
offset?: number,
|
|
310
|
+
order?: GetTransactionsOrder,
|
|
311
|
+
chainId?: number,
|
|
312
|
+
): Promise<Transaction[]> {
|
|
313
|
+
return this.mpc?.getTransactions(limit, offset, order, chainId)
|
|
314
|
+
}
|
|
315
|
+
|
|
275
316
|
public async simulateTransaction(
|
|
276
317
|
transaction: SimulateTransactionParam,
|
|
277
318
|
): Promise<SimulatedTransaction> {
|
|
278
319
|
return this.mpc?.simulateTransaction(transaction)
|
|
279
320
|
}
|
|
280
321
|
|
|
281
|
-
|
|
282
|
-
|
|
322
|
+
/*******************************
|
|
323
|
+
* Swaps Methods
|
|
324
|
+
*******************************/
|
|
325
|
+
|
|
326
|
+
public async getQuote(
|
|
327
|
+
apiKey: string,
|
|
328
|
+
args: QuoteArgs,
|
|
329
|
+
): Promise<QuoteResponse> {
|
|
330
|
+
return this.mpc?.getQuote(apiKey, args)
|
|
283
331
|
}
|
|
284
332
|
|
|
285
|
-
public async
|
|
286
|
-
return this.mpc?.
|
|
333
|
+
public async getSources(apiKey: string): Promise<Record<string, string>> {
|
|
334
|
+
return this.mpc?.getSources(apiKey)
|
|
287
335
|
}
|
|
288
336
|
|
|
289
337
|
/*******************************
|