@portal-hq/web 3.2.2 → 3.3.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/README.md CHANGED
@@ -19,7 +19,7 @@ For a comprehensive guide and API reference, please visit our [documentation por
19
19
 
20
20
  - Node.js and npm or yarn installed.
21
21
  - Basic knowledge of TypeScript and React.
22
- - Access to a Portal Account.
22
+ - Access to a Portal Account.
23
23
 
24
24
  ### Installation
25
25
 
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,23 +35,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PortalCurve = exports.GetTransactionsOrder = exports.BackupMethods = exports.MpcStatuses = exports.MpcErrorCodes = exports.MpcError = void 0;
38
+ exports.ChainNamespace = exports.PortalCurve = exports.GetTransactionsOrder = exports.BackupMethods = exports.MpcStatuses = exports.RequestMethod = exports.MpcErrorCodes = exports.MpcError = void 0;
16
39
  const web3_js_1 = require("@solana/web3.js");
17
40
  const mpc_1 = __importDefault(require("./mpc"));
18
- const provider_1 = __importDefault(require("./provider"));
41
+ const provider_1 = __importStar(require("./provider"));
19
42
  class Portal {
43
+ get ready() {
44
+ return this.mpc.ready;
45
+ }
20
46
  constructor({
21
47
  // Required
22
48
  rpcConfig,
23
49
  // Optional
24
50
  apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, }) {
25
- this.ready = false;
26
51
  this.errorCallbacks = [];
27
52
  this.readyCallbacks = [];
28
53
  this.sendEth = ({ chainId, to, value, }) => __awaiter(this, void 0, void 0, function* () {
29
54
  return this.provider.request({
30
55
  chainId,
31
- method: 'eth_sendTransaction',
56
+ method: provider_1.RequestMethod.eth_sendTransaction,
32
57
  params: [
33
58
  {
34
59
  from: this.address,
@@ -225,6 +250,60 @@ class Portal {
225
250
  return sharesOnDevice.ED25519 && sharesOnDevice.SECP256K1;
226
251
  });
227
252
  }
253
+ isWalletBackedUp(chainId) {
254
+ var _a, _b, _c, _d, _e;
255
+ return __awaiter(this, void 0, void 0, function* () {
256
+ const client = yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient());
257
+ if (chainId) {
258
+ const namespace = ((_b = chainId === null || chainId === void 0 ? void 0 : chainId.split(':')) === null || _b === void 0 ? void 0 : _b[0]) || '';
259
+ const curve = (_e = (_d = (_c = client === null || client === void 0 ? void 0 : client.metadata) === null || _c === void 0 ? void 0 : _c.namespaces) === null || _d === void 0 ? void 0 : _d[namespace]) === null || _e === void 0 ? void 0 : _e.curve;
260
+ if (!curve) {
261
+ return false;
262
+ }
263
+ const wallet = client === null || client === void 0 ? void 0 : client.wallets.find((w) => w.curve === curve);
264
+ if (!wallet) {
265
+ return false;
266
+ }
267
+ return wallet.backupSharePairs.some((share) => share.status === 'completed');
268
+ }
269
+ else {
270
+ return client === null || client === void 0 ? void 0 : client.wallets.some((wallet) => wallet.backupSharePairs.some((share) => share.status === 'completed'));
271
+ }
272
+ });
273
+ }
274
+ isWalletRecoverable(chainId) {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const availableRecoveryMethods = yield this.availableRecoveryMethods(chainId);
277
+ return availableRecoveryMethods.length > 0;
278
+ });
279
+ }
280
+ availableRecoveryMethods(chainId) {
281
+ var _a, _b, _c, _d;
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ const client = yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient());
284
+ // If the client is not found, return an empty array.
285
+ if (!client) {
286
+ return [];
287
+ }
288
+ // If a chainId is provided, return the recovery methods for that chain.
289
+ if (chainId) {
290
+ const namespace = chainId.split(':')[0] || '';
291
+ const curve = (_d = (_c = (_b = client.metadata) === null || _b === void 0 ? void 0 : _b.namespaces) === null || _c === void 0 ? void 0 : _c[namespace]) === null || _d === void 0 ? void 0 : _d.curve;
292
+ if (!curve) {
293
+ return [];
294
+ }
295
+ const wallet = client.wallets.find((w) => w.curve === curve);
296
+ if (!wallet) {
297
+ return [];
298
+ }
299
+ const methods = this.extractBackupMethod(wallet);
300
+ return this.getUniqueBackupMethod(methods);
301
+ }
302
+ // Otherwise, return the recovery methods for all wallets.
303
+ const allMethods = client.wallets.flatMap((wallet) => this.extractBackupMethod(wallet));
304
+ return this.getUniqueBackupMethod(allMethods);
305
+ });
306
+ }
228
307
  /****************************
229
308
  * Provider Methods
230
309
  ****************************/
@@ -247,7 +326,7 @@ class Portal {
247
326
  console.warn('"portal.ethEstimateGas" is deprecated. Use "portal.request" instead.');
248
327
  return this.provider.request({
249
328
  chainId,
250
- method: 'eth_estimateGas',
329
+ method: provider_1.RequestMethod.eth_estimateGas,
251
330
  params: transaction,
252
331
  });
253
332
  });
@@ -265,7 +344,7 @@ class Portal {
265
344
  console.warn('"portal.ethGasPrice" is deprecated. Use "portal.request" instead.');
266
345
  return this.provider.request({
267
346
  chainId,
268
- method: 'eth_gasPrice',
347
+ method: provider_1.RequestMethod.eth_gasPrice,
269
348
  params: [],
270
349
  });
271
350
  });
@@ -283,7 +362,7 @@ class Portal {
283
362
  console.warn('"portal.ethGetBalance" is deprecated. Use "portal.request" instead.');
284
363
  return this.provider.request({
285
364
  chainId,
286
- method: 'eth_getBalance',
365
+ method: provider_1.RequestMethod.eth_getBalance,
287
366
  params: [this.address, 'latest'],
288
367
  });
289
368
  });
@@ -302,7 +381,7 @@ class Portal {
302
381
  console.warn('"portal.ethSendTransaction" is deprecated. Use "portal.request" instead.');
303
382
  return this.provider.request({
304
383
  chainId,
305
- method: 'eth_sendTransaction',
384
+ method: provider_1.RequestMethod.eth_sendTransaction,
306
385
  params: transaction,
307
386
  });
308
387
  });
@@ -321,7 +400,7 @@ class Portal {
321
400
  console.warn('"portal.ethSignTransaction" is deprecated. Use "portal.request" instead.');
322
401
  return this.provider.request({
323
402
  chainId,
324
- method: 'eth_signTransaction',
403
+ method: provider_1.RequestMethod.eth_signTransaction,
325
404
  params: transaction,
326
405
  });
327
406
  });
@@ -340,7 +419,7 @@ class Portal {
340
419
  console.warn('"portal.ethSignTypedData" is deprecated. Use "portal.request" instead.');
341
420
  return this.provider.request({
342
421
  chainId,
343
- method: 'eth_signTypedData',
422
+ method: provider_1.RequestMethod.eth_signTypedData,
344
423
  params: [this.address, data],
345
424
  });
346
425
  });
@@ -359,7 +438,7 @@ class Portal {
359
438
  console.warn('"portal.ethSignTypedDataV3" is deprecated. Use "portal.request" instead.');
360
439
  return this.provider.request({
361
440
  chainId,
362
- method: 'eth_signTypedData_v3',
441
+ method: provider_1.RequestMethod.eth_signTypedData_v3,
363
442
  params: [this.address, data],
364
443
  });
365
444
  });
@@ -378,7 +457,7 @@ class Portal {
378
457
  console.warn('"portal.ethSignTypedDataV4" is deprecated. Use "portal.request" instead.');
379
458
  return this.provider.request({
380
459
  chainId,
381
- method: 'eth_signTypedData_v4',
460
+ method: provider_1.RequestMethod.eth_signTypedData_v4,
382
461
  params: [this.address, data],
383
462
  });
384
463
  });
@@ -388,7 +467,7 @@ class Portal {
388
467
  console.warn('"portal.personalSign" is deprecated. Use "portal.request" instead.');
389
468
  return (yield this.provider.request({
390
469
  chainId,
391
- method: 'personal_sign',
470
+ method: provider_1.RequestMethod.personal_sign,
392
471
  params: [this.stringToHex(message), this.address],
393
472
  }));
394
473
  });
@@ -417,7 +496,7 @@ class Portal {
417
496
  // Get the most recent blockhash.
418
497
  const blockhashResponse = yield this.provider.request({
419
498
  chainId: chainId,
420
- method: 'getLatestBlockhash',
499
+ method: provider_1.RequestMethod.sol_getLatestBlockhash,
421
500
  params: [],
422
501
  });
423
502
  const blockhash = ((_a = blockhashResponse === null || blockhashResponse === void 0 ? void 0 : blockhashResponse.value) === null || _a === void 0 ? void 0 : _a.blockhash) || '';
@@ -464,7 +543,7 @@ class Portal {
464
543
  // Attempt to sign and send the transaction
465
544
  const transactionResult = yield this.provider.request({
466
545
  chainId: chainId,
467
- method: 'sol_signAndSendTransaction',
546
+ method: provider_1.RequestMethod.sol_signAndSendTransaction,
468
547
  params: [formattedTransaction],
469
548
  });
470
549
  // If we didn't get a transactionResult, throw an error.
@@ -478,6 +557,9 @@ class Portal {
478
557
  /*******************************
479
558
  * API Methods
480
559
  *******************************/
560
+ /**
561
+ * @deprecated This method is deprecated. Use `portal.getAssets` instead.
562
+ */
481
563
  getBalances(chainId) {
482
564
  var _a;
483
565
  return __awaiter(this, void 0, void 0, function* () {
@@ -490,6 +572,9 @@ class Portal {
490
572
  return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
491
573
  });
492
574
  }
575
+ /**
576
+ * @deprecated This method is deprecated. Use `portal.getNFTAssets` instead.
577
+ */
493
578
  getNFTs(chainId) {
494
579
  var _a;
495
580
  return __awaiter(this, void 0, void 0, function* () {
@@ -502,12 +587,39 @@ class Portal {
502
587
  return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(chainId, limit, offset, order);
503
588
  });
504
589
  }
590
+ /**
591
+ * @deprecated This method is deprecated. Use `portal.evaluateTransaction` instead.
592
+ */
505
593
  simulateTransaction(chainId, transaction) {
506
594
  var _a;
507
595
  return __awaiter(this, void 0, void 0, function* () {
508
596
  return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction, chainId);
509
597
  });
510
598
  }
599
+ evaluateTransaction(chainId, transaction, operationType = 'all') {
600
+ var _a;
601
+ return __awaiter(this, void 0, void 0, function* () {
602
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.evaluateTransaction(chainId, transaction, operationType);
603
+ });
604
+ }
605
+ getAssets(chainId, includeNfts = false) {
606
+ var _a;
607
+ return __awaiter(this, void 0, void 0, function* () {
608
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getAssets(chainId, includeNfts);
609
+ });
610
+ }
611
+ getNFTAssets(chainId) {
612
+ var _a;
613
+ return __awaiter(this, void 0, void 0, function* () {
614
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTAssets(chainId);
615
+ });
616
+ }
617
+ buildTransaction(chainId, to, token, amount) {
618
+ var _a;
619
+ return __awaiter(this, void 0, void 0, function* () {
620
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.buildTransaction(chainId, to, token, amount);
621
+ });
622
+ }
511
623
  /*******************************
512
624
  * Swaps Methods
513
625
  *******************************/
@@ -554,9 +666,6 @@ class Portal {
554
666
  // Otherwise, something is wrong with the configuration.
555
667
  throw new Error(`[Portal] Could not find a valid rpcConfig entry for chainId: ${chainId}`);
556
668
  }
557
- /**************************
558
- * RPC Encoding Methods
559
- **************************/
560
669
  stringToHex(str) {
561
670
  if (str.startsWith('0x')) {
562
671
  return str;
@@ -569,10 +678,20 @@ class Portal {
569
678
  }
570
679
  return hex;
571
680
  }
681
+ extractBackupMethod(wallet) {
682
+ return wallet.backupSharePairs
683
+ .filter((share) => share.status === 'completed')
684
+ .map((share) => share.backupMethod);
685
+ }
686
+ getUniqueBackupMethod(methods) {
687
+ return Array.from(new Set(methods));
688
+ }
572
689
  }
573
690
  var mpc_2 = require("./mpc");
574
691
  Object.defineProperty(exports, "MpcError", { enumerable: true, get: function () { return mpc_2.MpcError; } });
575
692
  Object.defineProperty(exports, "MpcErrorCodes", { enumerable: true, get: function () { return mpc_2.MpcErrorCodes; } });
693
+ var provider_2 = require("./provider");
694
+ Object.defineProperty(exports, "RequestMethod", { enumerable: true, get: function () { return provider_2.RequestMethod; } });
576
695
  var MpcStatuses;
577
696
  (function (MpcStatuses) {
578
697
  MpcStatuses["DecryptingShare"] = "Decrypting share";
@@ -602,4 +721,9 @@ var PortalCurve;
602
721
  PortalCurve["ED25519"] = "ED25519";
603
722
  PortalCurve["SECP256K1"] = "SECP256K1";
604
723
  })(PortalCurve = exports.PortalCurve || (exports.PortalCurve = {}));
724
+ var ChainNamespace;
725
+ (function (ChainNamespace) {
726
+ ChainNamespace["EIP155"] = "eip155";
727
+ ChainNamespace["SOLANA"] = "solana";
728
+ })(ChainNamespace = exports.ChainNamespace || (exports.ChainNamespace = {}));
605
729
  exports.default = Portal;