@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/src/mpc/index.ts
CHANGED
|
@@ -3,14 +3,19 @@ import { PortalMpcError } from './errors'
|
|
|
3
3
|
import Portal, { BackupMethods } from '../index'
|
|
4
4
|
import type {
|
|
5
5
|
BackupArgs,
|
|
6
|
+
Balance,
|
|
6
7
|
ClientWithCustodianData,
|
|
7
8
|
GenerateArgs,
|
|
9
|
+
GetTransactionsOrder,
|
|
8
10
|
IframeConfigurationOptions,
|
|
9
11
|
LegacyRecoverArgs,
|
|
10
12
|
MpcOptions,
|
|
11
13
|
MpcStatus,
|
|
14
|
+
NFT,
|
|
12
15
|
PortalError,
|
|
13
16
|
ProgressCallback,
|
|
17
|
+
QuoteArgs,
|
|
18
|
+
QuoteResponse,
|
|
14
19
|
RecoverArgs,
|
|
15
20
|
SignArgs,
|
|
16
21
|
SimulateTransactionParam,
|
|
@@ -19,7 +24,7 @@ import type {
|
|
|
19
24
|
WorkerResult,
|
|
20
25
|
} from '../../types'
|
|
21
26
|
|
|
22
|
-
const WEB_SDK_VERSION = '0.0.
|
|
27
|
+
const WEB_SDK_VERSION = '0.0.5'
|
|
23
28
|
|
|
24
29
|
class Mpc {
|
|
25
30
|
public iframe?: HTMLIFrameElement
|
|
@@ -36,6 +41,10 @@ class Mpc {
|
|
|
36
41
|
this.appendIframe()
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
/*******************************
|
|
45
|
+
* Wallet Methods
|
|
46
|
+
*******************************/
|
|
47
|
+
|
|
39
48
|
public async backup(
|
|
40
49
|
data: BackupArgs,
|
|
41
50
|
progress: ProgressCallback = () => {
|
|
@@ -402,11 +411,13 @@ class Mpc {
|
|
|
402
411
|
})
|
|
403
412
|
}
|
|
404
413
|
|
|
405
|
-
|
|
414
|
+
/*******************************
|
|
415
|
+
* API Methods
|
|
416
|
+
*******************************/
|
|
417
|
+
|
|
418
|
+
public async getBalances(): Promise<Balance[]> {
|
|
406
419
|
return new Promise((resolve, reject) => {
|
|
407
|
-
const
|
|
408
|
-
event: MessageEvent<WorkerResult>,
|
|
409
|
-
) => {
|
|
420
|
+
const handleGetBalances = (event: MessageEvent<WorkerResult>) => {
|
|
410
421
|
const { type, data } = event.data
|
|
411
422
|
const { origin } = event
|
|
412
423
|
|
|
@@ -415,37 +426,35 @@ class Mpc {
|
|
|
415
426
|
return
|
|
416
427
|
}
|
|
417
428
|
|
|
418
|
-
if (type === 'portal:
|
|
429
|
+
if (type === 'portal:getBalancesError') {
|
|
419
430
|
// Remove the event listener
|
|
420
|
-
window.removeEventListener('message',
|
|
431
|
+
window.removeEventListener('message', handleGetBalances)
|
|
421
432
|
|
|
422
433
|
// Reject the promise with the error
|
|
423
434
|
return reject(new PortalMpcError(data as PortalError))
|
|
424
|
-
} else if (type === 'portal:
|
|
435
|
+
} else if (type === 'portal:getBalancesResult') {
|
|
425
436
|
// Remove the event listener
|
|
426
|
-
window.removeEventListener('message',
|
|
437
|
+
window.removeEventListener('message', handleGetBalances)
|
|
427
438
|
|
|
428
439
|
// Resolve the promise with the result
|
|
429
|
-
resolve()
|
|
440
|
+
resolve(data as Balance[])
|
|
430
441
|
}
|
|
431
442
|
}
|
|
432
443
|
|
|
433
444
|
// Bind the function to the message event
|
|
434
|
-
window.addEventListener('message',
|
|
445
|
+
window.addEventListener('message', handleGetBalances)
|
|
435
446
|
|
|
436
447
|
// Send the request to the iframe
|
|
437
448
|
this.postMessage({
|
|
438
|
-
type: 'portal:
|
|
439
|
-
data:
|
|
449
|
+
type: 'portal:getBalances',
|
|
450
|
+
data: {},
|
|
440
451
|
})
|
|
441
452
|
})
|
|
442
453
|
}
|
|
443
454
|
|
|
444
|
-
public async
|
|
445
|
-
transaction: SimulateTransactionParam,
|
|
446
|
-
): Promise<SimulatedTransaction> {
|
|
455
|
+
public async getClient(): Promise<ClientWithCustodianData> {
|
|
447
456
|
return new Promise((resolve, reject) => {
|
|
448
|
-
const
|
|
457
|
+
const handleGetClient = (event: MessageEvent<WorkerResult>) => {
|
|
449
458
|
const { type, data } = event.data
|
|
450
459
|
const { origin } = event
|
|
451
460
|
|
|
@@ -454,33 +463,155 @@ class Mpc {
|
|
|
454
463
|
return
|
|
455
464
|
}
|
|
456
465
|
|
|
457
|
-
if (type === 'portal:
|
|
466
|
+
if (type === 'portal:getClientError') {
|
|
458
467
|
// Remove the event listener
|
|
459
|
-
window.removeEventListener('message',
|
|
468
|
+
window.removeEventListener('message', handleGetClient)
|
|
460
469
|
|
|
461
470
|
// Reject the promise with the error
|
|
462
471
|
return reject(new PortalMpcError(data as PortalError))
|
|
463
|
-
} else if (type === 'portal:
|
|
472
|
+
} else if (type === 'portal:getClientResult') {
|
|
464
473
|
// Remove the event listener
|
|
465
|
-
window.removeEventListener('message',
|
|
474
|
+
window.removeEventListener('message', handleGetClient)
|
|
466
475
|
|
|
467
476
|
// Resolve the promise with the result
|
|
468
|
-
resolve(data as
|
|
477
|
+
resolve(data as ClientWithCustodianData)
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
|
|
472
481
|
// Bind the function to the message event
|
|
473
|
-
window.addEventListener('message',
|
|
482
|
+
window.addEventListener('message', handleGetClient)
|
|
474
483
|
|
|
475
484
|
// Send the request to the iframe
|
|
476
485
|
this.postMessage({
|
|
477
|
-
type: 'portal:
|
|
478
|
-
data:
|
|
486
|
+
type: 'portal:getClient',
|
|
487
|
+
data: {},
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
public async getNFTs(): Promise<NFT[]> {
|
|
493
|
+
return new Promise((resolve, reject) => {
|
|
494
|
+
const handleGetNFTs = (event: MessageEvent<WorkerResult>) => {
|
|
495
|
+
const { type, data } = event.data
|
|
496
|
+
const { origin } = event
|
|
497
|
+
|
|
498
|
+
// ignore any broadcast postMessages
|
|
499
|
+
if (origin !== this.getOrigin()) {
|
|
500
|
+
return
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (type === 'portal:getNFTsError') {
|
|
504
|
+
// Remove the event listener
|
|
505
|
+
window.removeEventListener('message', handleGetNFTs)
|
|
506
|
+
|
|
507
|
+
// Reject the promise with the error
|
|
508
|
+
return reject(new PortalMpcError(data as PortalError))
|
|
509
|
+
} else if (type === 'portal:getNFTsResult') {
|
|
510
|
+
// Remove the event listener
|
|
511
|
+
window.removeEventListener('message', handleGetNFTs)
|
|
512
|
+
|
|
513
|
+
// Resolve the promise with the result
|
|
514
|
+
resolve(data as NFT[])
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Bind the function to the message event
|
|
519
|
+
window.addEventListener('message', handleGetNFTs)
|
|
520
|
+
|
|
521
|
+
// Send the request to the iframe
|
|
522
|
+
this.postMessage({
|
|
523
|
+
type: 'portal:getNFTs',
|
|
524
|
+
data: {},
|
|
479
525
|
})
|
|
480
526
|
})
|
|
481
527
|
}
|
|
482
528
|
|
|
483
|
-
public async
|
|
529
|
+
public async getQuote(
|
|
530
|
+
apiKey: string,
|
|
531
|
+
args: QuoteArgs,
|
|
532
|
+
): Promise<QuoteResponse> {
|
|
533
|
+
return new Promise((resolve, reject) => {
|
|
534
|
+
const handleGetQuote = (event: MessageEvent<WorkerResult>) => {
|
|
535
|
+
const { type, data: result } = event.data
|
|
536
|
+
const { origin } = event
|
|
537
|
+
|
|
538
|
+
// ignore any broadcast postMessages
|
|
539
|
+
if (origin !== this.getOrigin()) {
|
|
540
|
+
return
|
|
541
|
+
}
|
|
542
|
+
if (type === 'portal:swaps:getQuoteError') {
|
|
543
|
+
// Remove the event listener
|
|
544
|
+
window.removeEventListener('message', handleGetQuote)
|
|
545
|
+
|
|
546
|
+
// Reject the promise with the error
|
|
547
|
+
return reject(new PortalMpcError(result as PortalError))
|
|
548
|
+
} else if (type === 'portal:swaps:getQuoteResult') {
|
|
549
|
+
// Remove the event listener
|
|
550
|
+
window.removeEventListener('message', handleGetQuote)
|
|
551
|
+
|
|
552
|
+
// Resolve the promise with the result
|
|
553
|
+
resolve(result as QuoteResponse)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Bind the function to the message event
|
|
558
|
+
window.addEventListener('message', handleGetQuote)
|
|
559
|
+
|
|
560
|
+
// Send the request to the iframe
|
|
561
|
+
this.postMessage({
|
|
562
|
+
type: 'portal:swaps:getQuote',
|
|
563
|
+
data: {
|
|
564
|
+
apiKey,
|
|
565
|
+
args,
|
|
566
|
+
},
|
|
567
|
+
})
|
|
568
|
+
})
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
public async getSources(apiKey: string): Promise<Record<string, string>> {
|
|
572
|
+
return new Promise((resolve, reject) => {
|
|
573
|
+
const handleGetSources = (event: MessageEvent<WorkerResult>) => {
|
|
574
|
+
const { type, data: result } = event.data
|
|
575
|
+
const { origin } = event
|
|
576
|
+
|
|
577
|
+
// ignore any broadcast postMessages
|
|
578
|
+
if (origin !== this.getOrigin()) {
|
|
579
|
+
return
|
|
580
|
+
}
|
|
581
|
+
if (type === 'portal:swaps:getSourcesError') {
|
|
582
|
+
// Remove the event listener
|
|
583
|
+
window.removeEventListener('message', handleGetSources)
|
|
584
|
+
|
|
585
|
+
// Reject the promise with the error
|
|
586
|
+
return reject(new PortalMpcError(result as PortalError))
|
|
587
|
+
} else if (type === 'portal:swaps:getSourcesResult') {
|
|
588
|
+
// Remove the event listener
|
|
589
|
+
window.removeEventListener('message', handleGetSources)
|
|
590
|
+
|
|
591
|
+
// Resolve the promise with the result
|
|
592
|
+
resolve(result as Record<string, string>)
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Bind the function to the message event
|
|
597
|
+
window.addEventListener('message', handleGetSources)
|
|
598
|
+
|
|
599
|
+
// Send the request to the iframe
|
|
600
|
+
this.postMessage({
|
|
601
|
+
type: 'portal:swaps:getSources',
|
|
602
|
+
data: {
|
|
603
|
+
apiKey,
|
|
604
|
+
},
|
|
605
|
+
})
|
|
606
|
+
})
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
public async getTransactions(
|
|
610
|
+
limit?: number,
|
|
611
|
+
offset?: number,
|
|
612
|
+
order?: GetTransactionsOrder,
|
|
613
|
+
chainId?: number,
|
|
614
|
+
): Promise<Transaction[]> {
|
|
484
615
|
return new Promise((resolve, reject) => {
|
|
485
616
|
const handleGetTransactions = (event: MessageEvent<WorkerResult>) => {
|
|
486
617
|
const { type, data } = event.data
|
|
@@ -512,14 +643,21 @@ class Mpc {
|
|
|
512
643
|
// Send the request to the iframe
|
|
513
644
|
this.postMessage({
|
|
514
645
|
type: 'portal:getTransactions',
|
|
515
|
-
data: {
|
|
646
|
+
data: {
|
|
647
|
+
limit,
|
|
648
|
+
offset,
|
|
649
|
+
order,
|
|
650
|
+
chainId,
|
|
651
|
+
},
|
|
516
652
|
})
|
|
517
653
|
})
|
|
518
654
|
}
|
|
519
655
|
|
|
520
|
-
public async
|
|
656
|
+
public async simulateTransaction(
|
|
657
|
+
transaction: SimulateTransactionParam,
|
|
658
|
+
): Promise<SimulatedTransaction> {
|
|
521
659
|
return new Promise((resolve, reject) => {
|
|
522
|
-
const
|
|
660
|
+
const handleSimulateTransaction = (event: MessageEvent<WorkerResult>) => {
|
|
523
661
|
const { type, data } = event.data
|
|
524
662
|
const { origin } = event
|
|
525
663
|
|
|
@@ -528,28 +666,67 @@ class Mpc {
|
|
|
528
666
|
return
|
|
529
667
|
}
|
|
530
668
|
|
|
531
|
-
if (type === 'portal:
|
|
669
|
+
if (type === 'portal:simulateTransactionError') {
|
|
532
670
|
// Remove the event listener
|
|
533
|
-
window.removeEventListener('message',
|
|
671
|
+
window.removeEventListener('message', handleSimulateTransaction)
|
|
534
672
|
|
|
535
673
|
// Reject the promise with the error
|
|
536
674
|
return reject(new PortalMpcError(data as PortalError))
|
|
537
|
-
} else if (type === 'portal:
|
|
675
|
+
} else if (type === 'portal:simulateTransactionResult') {
|
|
538
676
|
// Remove the event listener
|
|
539
|
-
window.removeEventListener('message',
|
|
677
|
+
window.removeEventListener('message', handleSimulateTransaction)
|
|
540
678
|
|
|
541
679
|
// Resolve the promise with the result
|
|
542
|
-
resolve(data as
|
|
680
|
+
resolve(data as SimulatedTransaction)
|
|
543
681
|
}
|
|
544
682
|
}
|
|
545
683
|
|
|
546
684
|
// Bind the function to the message event
|
|
547
|
-
window.addEventListener('message',
|
|
685
|
+
window.addEventListener('message', handleSimulateTransaction)
|
|
548
686
|
|
|
549
687
|
// Send the request to the iframe
|
|
550
688
|
this.postMessage({
|
|
551
|
-
type: 'portal:
|
|
552
|
-
data:
|
|
689
|
+
type: 'portal:simulateTransaction',
|
|
690
|
+
data: transaction,
|
|
691
|
+
})
|
|
692
|
+
})
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
public storedClientBackupShare(success: boolean): Promise<void> {
|
|
696
|
+
return new Promise((resolve, reject) => {
|
|
697
|
+
const handleStoredClientBackupShare = (
|
|
698
|
+
event: MessageEvent<WorkerResult>,
|
|
699
|
+
) => {
|
|
700
|
+
const { type, data } = event.data
|
|
701
|
+
const { origin } = event
|
|
702
|
+
|
|
703
|
+
// ignore any broadcast postMessages
|
|
704
|
+
if (origin !== this.getOrigin()) {
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (type === 'portal:storedClientBackupShareError') {
|
|
709
|
+
// Remove the event listener
|
|
710
|
+
window.removeEventListener('message', handleStoredClientBackupShare)
|
|
711
|
+
|
|
712
|
+
// Reject the promise with the error
|
|
713
|
+
return reject(new PortalMpcError(data as PortalError))
|
|
714
|
+
} else if (type === 'portal:storedClientBackupShareResult') {
|
|
715
|
+
// Remove the event listener
|
|
716
|
+
window.removeEventListener('message', handleStoredClientBackupShare)
|
|
717
|
+
|
|
718
|
+
// Resolve the promise with the result
|
|
719
|
+
resolve()
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Bind the function to the message event
|
|
724
|
+
window.addEventListener('message', handleStoredClientBackupShare)
|
|
725
|
+
|
|
726
|
+
// Send the request to the iframe
|
|
727
|
+
this.postMessage({
|
|
728
|
+
type: 'portal:storedClientBackupShare',
|
|
729
|
+
data: success,
|
|
553
730
|
})
|
|
554
731
|
})
|
|
555
732
|
}
|
package/types.d.ts
CHANGED
|
@@ -107,15 +107,16 @@ export interface DecryptArgs {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export interface DkgData {
|
|
110
|
-
share: string
|
|
111
|
-
ssid: string
|
|
112
|
-
pubkey: Pubkey
|
|
113
|
-
partialPubKey: Pubkey[]
|
|
114
110
|
allY: Pubkey[]
|
|
111
|
+
bks: Bk[]
|
|
115
112
|
p: string
|
|
116
|
-
|
|
113
|
+
partialPubKey: Pubkey[]
|
|
117
114
|
pederson: PedersonParams[]
|
|
118
|
-
|
|
115
|
+
pubkey: Pubkey
|
|
116
|
+
q: string
|
|
117
|
+
share: string
|
|
118
|
+
signingSharePairId?: string
|
|
119
|
+
ssid: string
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
export interface EIP1559Transaction {
|
|
@@ -328,6 +329,7 @@ export interface QuoteArgs {
|
|
|
328
329
|
}
|
|
329
330
|
|
|
330
331
|
export interface QuoteResponse {
|
|
332
|
+
allowanceTarget: string
|
|
331
333
|
cost: string
|
|
332
334
|
transaction: Eip1559 | LegacyTx
|
|
333
335
|
}
|
|
@@ -427,14 +429,23 @@ export interface SimulatedTransaction {
|
|
|
427
429
|
requestError?: SimulatedTransactionError
|
|
428
430
|
}
|
|
429
431
|
|
|
432
|
+
export enum GetTransactionsOrder {
|
|
433
|
+
ASC = 'asc',
|
|
434
|
+
DESC = 'desc',
|
|
435
|
+
}
|
|
436
|
+
|
|
430
437
|
export interface Transaction {
|
|
431
438
|
asset: string
|
|
432
439
|
blockNum: string
|
|
433
440
|
category: string
|
|
441
|
+
chainId: number
|
|
434
442
|
erc1155Metadata: null | string
|
|
435
443
|
erc721TokenId: null | string
|
|
436
444
|
from: string
|
|
437
445
|
hash: string
|
|
446
|
+
metadata: {
|
|
447
|
+
blockTimestamp: string
|
|
448
|
+
}
|
|
438
449
|
rawContract: {
|
|
439
450
|
address: string
|
|
440
451
|
decimal: string
|