@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.
@@ -20,7 +20,7 @@ class Portal {
20
20
  // Required
21
21
  gatewayConfig,
22
22
  // Optional
23
- apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v4', featureFlags = {
23
+ apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
24
24
  optimized: false,
25
25
  }, }) {
26
26
  this.ready = false;
@@ -132,6 +132,10 @@ class Portal {
132
132
  return address;
133
133
  });
134
134
  }
135
+ /**
136
+ * @deprecated This method is deprecated and will be removed in a future version.
137
+ * Use the `recoverWallet` method instead.
138
+ */
135
139
  legacyRecoverWallet(cipherText, progress = () => {
136
140
  // Noop
137
141
  }) {
@@ -146,6 +150,13 @@ class Portal {
146
150
  return recoveredCipherText;
147
151
  });
148
152
  }
153
+ provisionWallet(cipherText, backupMethod, backupConfigs, progress = () => {
154
+ // Noop
155
+ }) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
158
+ });
159
+ }
149
160
  /****************************
150
161
  * Provider Methods
151
162
  ****************************/
@@ -208,22 +219,49 @@ class Portal {
208
219
  /*******************************
209
220
  * API Methods
210
221
  *******************************/
222
+ getBalances() {
223
+ var _a;
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ return yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getBalances());
226
+ });
227
+ }
228
+ getClient() {
229
+ var _a;
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
232
+ });
233
+ }
234
+ getNFTs() {
235
+ var _a;
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTs();
238
+ });
239
+ }
240
+ getTransactions(limit, offset, order, chainId) {
241
+ var _a;
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(limit, offset, order, chainId);
244
+ });
245
+ }
211
246
  simulateTransaction(transaction) {
212
247
  var _a;
213
248
  return __awaiter(this, void 0, void 0, function* () {
214
249
  return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction);
215
250
  });
216
251
  }
217
- getTransactions() {
252
+ /*******************************
253
+ * Swaps Methods
254
+ *******************************/
255
+ getQuote(apiKey, args) {
218
256
  var _a;
219
257
  return __awaiter(this, void 0, void 0, function* () {
220
- return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions();
258
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
221
259
  });
222
260
  }
223
- getClient() {
261
+ getSources(apiKey) {
224
262
  var _a;
225
263
  return __awaiter(this, void 0, void 0, function* () {
226
- return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
264
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
227
265
  });
228
266
  }
229
267
  /*******************************
@@ -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 = '0.0.3';
15
+ const WEB_SDK_VERSION = '0.0.5';
16
16
  class Mpc {
17
17
  constructor({ portal }) {
18
18
  this.configureIframe = () => {
@@ -40,6 +40,9 @@ class Mpc {
40
40
  // Create the iFrame for MPC operations
41
41
  this.appendIframe();
42
42
  }
43
+ /*******************************
44
+ * Wallet Methods
45
+ *******************************/
43
46
  backup(data, progress = () => {
44
47
  // Noop
45
48
  }) {
@@ -341,71 +344,180 @@ class Mpc {
341
344
  });
342
345
  });
343
346
  }
344
- storedClientBackupShare(success) {
345
- return new Promise((resolve, reject) => {
346
- const handleStoredClientBackupShare = (event) => {
347
- const { type, data } = event.data;
348
- const { origin } = event;
349
- // ignore any broadcast postMessages
350
- if (origin !== this.getOrigin()) {
351
- return;
352
- }
353
- if (type === 'portal:storedClientBackupShareError') {
354
- // Remove the event listener
355
- window.removeEventListener('message', handleStoredClientBackupShare);
356
- // Reject the promise with the error
357
- return reject(new errors_1.PortalMpcError(data));
358
- }
359
- else if (type === 'portal:storedClientBackupShareResult') {
360
- // Remove the event listener
361
- window.removeEventListener('message', handleStoredClientBackupShare);
362
- // Resolve the promise with the result
363
- resolve();
364
- }
365
- };
366
- // Bind the function to the message event
367
- window.addEventListener('message', handleStoredClientBackupShare);
368
- // Send the request to the iframe
369
- this.postMessage({
370
- type: 'portal:storedClientBackupShare',
371
- data: success,
347
+ /*******************************
348
+ * API Methods
349
+ *******************************/
350
+ getBalances() {
351
+ return __awaiter(this, void 0, void 0, function* () {
352
+ return new Promise((resolve, reject) => {
353
+ const handleGetBalances = (event) => {
354
+ const { type, data } = event.data;
355
+ const { origin } = event;
356
+ // ignore any broadcast postMessages
357
+ if (origin !== this.getOrigin()) {
358
+ return;
359
+ }
360
+ if (type === 'portal:getBalancesError') {
361
+ // Remove the event listener
362
+ window.removeEventListener('message', handleGetBalances);
363
+ // Reject the promise with the error
364
+ return reject(new errors_1.PortalMpcError(data));
365
+ }
366
+ else if (type === 'portal:getBalancesResult') {
367
+ // Remove the event listener
368
+ window.removeEventListener('message', handleGetBalances);
369
+ // Resolve the promise with the result
370
+ resolve(data);
371
+ }
372
+ };
373
+ // Bind the function to the message event
374
+ window.addEventListener('message', handleGetBalances);
375
+ // Send the request to the iframe
376
+ this.postMessage({
377
+ type: 'portal:getBalances',
378
+ data: {},
379
+ });
372
380
  });
373
381
  });
374
382
  }
375
- simulateTransaction(transaction) {
383
+ getClient() {
376
384
  return __awaiter(this, void 0, void 0, function* () {
377
385
  return new Promise((resolve, reject) => {
378
- const handleSimulateTransaction = (event) => {
386
+ const handleGetClient = (event) => {
379
387
  const { type, data } = event.data;
380
388
  const { origin } = event;
381
389
  // ignore any broadcast postMessages
382
390
  if (origin !== this.getOrigin()) {
383
391
  return;
384
392
  }
385
- if (type === 'portal:simulateTransactionError') {
393
+ if (type === 'portal:getClientError') {
386
394
  // Remove the event listener
387
- window.removeEventListener('message', handleSimulateTransaction);
395
+ window.removeEventListener('message', handleGetClient);
388
396
  // Reject the promise with the error
389
397
  return reject(new errors_1.PortalMpcError(data));
390
398
  }
391
- else if (type === 'portal:simulateTransactionResult') {
399
+ else if (type === 'portal:getClientResult') {
392
400
  // Remove the event listener
393
- window.removeEventListener('message', handleSimulateTransaction);
401
+ window.removeEventListener('message', handleGetClient);
394
402
  // Resolve the promise with the result
395
403
  resolve(data);
396
404
  }
397
405
  };
398
406
  // Bind the function to the message event
399
- window.addEventListener('message', handleSimulateTransaction);
407
+ window.addEventListener('message', handleGetClient);
400
408
  // Send the request to the iframe
401
409
  this.postMessage({
402
- type: 'portal:simulateTransaction',
403
- data: transaction,
410
+ type: 'portal:getClient',
411
+ data: {},
412
+ });
413
+ });
414
+ });
415
+ }
416
+ getNFTs() {
417
+ return __awaiter(this, void 0, void 0, function* () {
418
+ return new Promise((resolve, reject) => {
419
+ const handleGetNFTs = (event) => {
420
+ const { type, data } = event.data;
421
+ const { origin } = event;
422
+ // ignore any broadcast postMessages
423
+ if (origin !== this.getOrigin()) {
424
+ return;
425
+ }
426
+ if (type === 'portal:getNFTsError') {
427
+ // Remove the event listener
428
+ window.removeEventListener('message', handleGetNFTs);
429
+ // Reject the promise with the error
430
+ return reject(new errors_1.PortalMpcError(data));
431
+ }
432
+ else if (type === 'portal:getNFTsResult') {
433
+ // Remove the event listener
434
+ window.removeEventListener('message', handleGetNFTs);
435
+ // Resolve the promise with the result
436
+ resolve(data);
437
+ }
438
+ };
439
+ // Bind the function to the message event
440
+ window.addEventListener('message', handleGetNFTs);
441
+ // Send the request to the iframe
442
+ this.postMessage({
443
+ type: 'portal:getNFTs',
444
+ data: {},
404
445
  });
405
446
  });
406
447
  });
407
448
  }
408
- getTransactions() {
449
+ getQuote(apiKey, args) {
450
+ return __awaiter(this, void 0, void 0, function* () {
451
+ return new Promise((resolve, reject) => {
452
+ const handleGetQuote = (event) => {
453
+ const { type, data: result } = event.data;
454
+ const { origin } = event;
455
+ // ignore any broadcast postMessages
456
+ if (origin !== this.getOrigin()) {
457
+ return;
458
+ }
459
+ if (type === 'portal:swaps:getQuoteError') {
460
+ // Remove the event listener
461
+ window.removeEventListener('message', handleGetQuote);
462
+ // Reject the promise with the error
463
+ return reject(new errors_1.PortalMpcError(result));
464
+ }
465
+ else if (type === 'portal:swaps:getQuoteResult') {
466
+ // Remove the event listener
467
+ window.removeEventListener('message', handleGetQuote);
468
+ // Resolve the promise with the result
469
+ resolve(result);
470
+ }
471
+ };
472
+ // Bind the function to the message event
473
+ window.addEventListener('message', handleGetQuote);
474
+ // Send the request to the iframe
475
+ this.postMessage({
476
+ type: 'portal:swaps:getQuote',
477
+ data: {
478
+ apiKey,
479
+ args,
480
+ },
481
+ });
482
+ });
483
+ });
484
+ }
485
+ getSources(apiKey) {
486
+ return __awaiter(this, void 0, void 0, function* () {
487
+ return new Promise((resolve, reject) => {
488
+ const handleGetSources = (event) => {
489
+ const { type, data: result } = event.data;
490
+ const { origin } = event;
491
+ // ignore any broadcast postMessages
492
+ if (origin !== this.getOrigin()) {
493
+ return;
494
+ }
495
+ if (type === 'portal:swaps:getSourcesError') {
496
+ // Remove the event listener
497
+ window.removeEventListener('message', handleGetSources);
498
+ // Reject the promise with the error
499
+ return reject(new errors_1.PortalMpcError(result));
500
+ }
501
+ else if (type === 'portal:swaps:getSourcesResult') {
502
+ // Remove the event listener
503
+ window.removeEventListener('message', handleGetSources);
504
+ // Resolve the promise with the result
505
+ resolve(result);
506
+ }
507
+ };
508
+ // Bind the function to the message event
509
+ window.addEventListener('message', handleGetSources);
510
+ // Send the request to the iframe
511
+ this.postMessage({
512
+ type: 'portal:swaps:getSources',
513
+ data: {
514
+ apiKey,
515
+ },
516
+ });
517
+ });
518
+ });
519
+ }
520
+ getTransactions(limit, offset, order, chainId) {
409
521
  return __awaiter(this, void 0, void 0, function* () {
410
522
  return new Promise((resolve, reject) => {
411
523
  const handleGetTransactions = (event) => {
@@ -433,44 +545,80 @@ class Mpc {
433
545
  // Send the request to the iframe
434
546
  this.postMessage({
435
547
  type: 'portal:getTransactions',
436
- data: {},
548
+ data: {
549
+ limit,
550
+ offset,
551
+ order,
552
+ chainId,
553
+ },
437
554
  });
438
555
  });
439
556
  });
440
557
  }
441
- getClient() {
558
+ simulateTransaction(transaction) {
442
559
  return __awaiter(this, void 0, void 0, function* () {
443
560
  return new Promise((resolve, reject) => {
444
- const handleGetClient = (event) => {
561
+ const handleSimulateTransaction = (event) => {
445
562
  const { type, data } = event.data;
446
563
  const { origin } = event;
447
564
  // ignore any broadcast postMessages
448
565
  if (origin !== this.getOrigin()) {
449
566
  return;
450
567
  }
451
- if (type === 'portal:getClientError') {
568
+ if (type === 'portal:simulateTransactionError') {
452
569
  // Remove the event listener
453
- window.removeEventListener('message', handleGetClient);
570
+ window.removeEventListener('message', handleSimulateTransaction);
454
571
  // Reject the promise with the error
455
572
  return reject(new errors_1.PortalMpcError(data));
456
573
  }
457
- else if (type === 'portal:getClientResult') {
574
+ else if (type === 'portal:simulateTransactionResult') {
458
575
  // Remove the event listener
459
- window.removeEventListener('message', handleGetClient);
576
+ window.removeEventListener('message', handleSimulateTransaction);
460
577
  // Resolve the promise with the result
461
578
  resolve(data);
462
579
  }
463
580
  };
464
581
  // Bind the function to the message event
465
- window.addEventListener('message', handleGetClient);
582
+ window.addEventListener('message', handleSimulateTransaction);
466
583
  // Send the request to the iframe
467
584
  this.postMessage({
468
- type: 'portal:getClient',
469
- data: {},
585
+ type: 'portal:simulateTransaction',
586
+ data: transaction,
470
587
  });
471
588
  });
472
589
  });
473
590
  }
591
+ storedClientBackupShare(success) {
592
+ return new Promise((resolve, reject) => {
593
+ const handleStoredClientBackupShare = (event) => {
594
+ const { type, data } = event.data;
595
+ const { origin } = event;
596
+ // ignore any broadcast postMessages
597
+ if (origin !== this.getOrigin()) {
598
+ return;
599
+ }
600
+ if (type === 'portal:storedClientBackupShareError') {
601
+ // Remove the event listener
602
+ window.removeEventListener('message', handleStoredClientBackupShare);
603
+ // Reject the promise with the error
604
+ return reject(new errors_1.PortalMpcError(data));
605
+ }
606
+ else if (type === 'portal:storedClientBackupShareResult') {
607
+ // Remove the event listener
608
+ window.removeEventListener('message', handleStoredClientBackupShare);
609
+ // Resolve the promise with the result
610
+ resolve();
611
+ }
612
+ };
613
+ // Bind the function to the message event
614
+ window.addEventListener('message', handleStoredClientBackupShare);
615
+ // Send the request to the iframe
616
+ this.postMessage({
617
+ type: 'portal:storedClientBackupShare',
618
+ data: success,
619
+ });
620
+ });
621
+ }
474
622
  /***************************
475
623
  * Private Methods
476
624
  ***************************/
package/lib/esm/index.js CHANGED
@@ -14,7 +14,7 @@ class Portal {
14
14
  // Required
15
15
  gatewayConfig,
16
16
  // Optional
17
- apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v4', featureFlags = {
17
+ apiKey, authToken, authUrl, autoApprove = false, chainId = 1, gdrive, host = 'web.portalhq.io', mpcVersion = 'v5', featureFlags = {
18
18
  optimized: false,
19
19
  }, }) {
20
20
  this.ready = false;
@@ -126,6 +126,10 @@ class Portal {
126
126
  return address;
127
127
  });
128
128
  }
129
+ /**
130
+ * @deprecated This method is deprecated and will be removed in a future version.
131
+ * Use the `recoverWallet` method instead.
132
+ */
129
133
  legacyRecoverWallet(cipherText, progress = () => {
130
134
  // Noop
131
135
  }) {
@@ -140,6 +144,13 @@ class Portal {
140
144
  return recoveredCipherText;
141
145
  });
142
146
  }
147
+ provisionWallet(cipherText, backupMethod, backupConfigs, progress = () => {
148
+ // Noop
149
+ }) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ return this.recoverWallet(cipherText, backupMethod, backupConfigs, progress);
152
+ });
153
+ }
143
154
  /****************************
144
155
  * Provider Methods
145
156
  ****************************/
@@ -202,22 +213,49 @@ class Portal {
202
213
  /*******************************
203
214
  * API Methods
204
215
  *******************************/
216
+ getBalances() {
217
+ var _a;
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ return yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getBalances());
220
+ });
221
+ }
222
+ getClient() {
223
+ var _a;
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
226
+ });
227
+ }
228
+ getNFTs() {
229
+ var _a;
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTs();
232
+ });
233
+ }
234
+ getTransactions(limit, offset, order, chainId) {
235
+ var _a;
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(limit, offset, order, chainId);
238
+ });
239
+ }
205
240
  simulateTransaction(transaction) {
206
241
  var _a;
207
242
  return __awaiter(this, void 0, void 0, function* () {
208
243
  return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction);
209
244
  });
210
245
  }
211
- getTransactions() {
246
+ /*******************************
247
+ * Swaps Methods
248
+ *******************************/
249
+ getQuote(apiKey, args) {
212
250
  var _a;
213
251
  return __awaiter(this, void 0, void 0, function* () {
214
- return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions();
252
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
215
253
  });
216
254
  }
217
- getClient() {
255
+ getSources(apiKey) {
218
256
  var _a;
219
257
  return __awaiter(this, void 0, void 0, function* () {
220
- return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
258
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
221
259
  });
222
260
  }
223
261
  /*******************************