@portal-hq/web 3.2.3 → 3.3.1
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 +1 -1
- package/lib/commonjs/index.js +147 -19
- package/lib/commonjs/index.test.js +548 -0
- package/lib/commonjs/mpc/errors/index.js +1 -1
- package/lib/commonjs/mpc/index.js +145 -2
- package/lib/commonjs/mpc/index.test.js +1414 -0
- package/lib/commonjs/provider/index.js +172 -39
- package/lib/commonjs/provider/index.test.js +1222 -0
- package/lib/esm/index.js +122 -18
- package/lib/esm/index.test.js +520 -0
- package/lib/esm/mpc/errors/index.js +1 -1
- package/lib/esm/mpc/index.js +145 -2
- package/lib/esm/mpc/index.test.js +1409 -0
- package/lib/esm/provider/index.js +171 -39
- package/lib/esm/provider/index.test.js +1217 -0
- package/package.json +5 -5
- package/src/__mocks/constants.ts +771 -0
- package/src/__mocks/portal/mpc.ts +27 -0
- package/src/__mocks/portal/portal.ts +14 -0
- package/src/__mocks/portal/provider.ts +7 -0
- package/src/index.test.ts +820 -0
- package/src/index.ts +183 -44
- package/src/mpc/errors/index.ts +1 -1
- package/src/mpc/index.test.ts +1716 -0
- package/src/mpc/index.ts +182 -2
- package/src/provider/index.test.ts +1570 -0
- package/src/provider/index.ts +184 -39
- package/types.d.ts +298 -33
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
|
|
package/lib/commonjs/index.js
CHANGED
|
@@ -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 =
|
|
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
|
-
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, }) {
|
|
25
|
-
this.ready = false;
|
|
50
|
+
apiKey, authToken, authUrl, autoApprove = false, gdrive, passkey, host = 'web.portalhq.io', mpcVersion = 'v6', mpcHost = 'mpc-client.portalhq.io', featureFlags = {}, chainId, }) {
|
|
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:
|
|
56
|
+
method: provider_1.RequestMethod.eth_sendTransaction,
|
|
32
57
|
params: [
|
|
33
58
|
{
|
|
34
59
|
from: this.address,
|
|
@@ -58,6 +83,7 @@ class Portal {
|
|
|
58
83
|
});
|
|
59
84
|
this.provider = new provider_1.default({
|
|
60
85
|
portal: this,
|
|
86
|
+
chainId: chainId ? Number(chainId) : undefined,
|
|
61
87
|
});
|
|
62
88
|
}
|
|
63
89
|
/*****************************
|
|
@@ -225,6 +251,60 @@ class Portal {
|
|
|
225
251
|
return sharesOnDevice.ED25519 && sharesOnDevice.SECP256K1;
|
|
226
252
|
});
|
|
227
253
|
}
|
|
254
|
+
isWalletBackedUp(chainId) {
|
|
255
|
+
var _a, _b, _c, _d, _e;
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const client = yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient());
|
|
258
|
+
if (chainId) {
|
|
259
|
+
const namespace = ((_b = chainId === null || chainId === void 0 ? void 0 : chainId.split(':')) === null || _b === void 0 ? void 0 : _b[0]) || '';
|
|
260
|
+
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;
|
|
261
|
+
if (!curve) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
const wallet = client === null || client === void 0 ? void 0 : client.wallets.find((w) => w.curve === curve);
|
|
265
|
+
if (!wallet) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
return wallet.backupSharePairs.some((share) => share.status === 'completed');
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return client === null || client === void 0 ? void 0 : client.wallets.some((wallet) => wallet.backupSharePairs.some((share) => share.status === 'completed'));
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
isWalletRecoverable(chainId) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
const availableRecoveryMethods = yield this.availableRecoveryMethods(chainId);
|
|
278
|
+
return availableRecoveryMethods.length > 0;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
availableRecoveryMethods(chainId) {
|
|
282
|
+
var _a, _b, _c, _d;
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
const client = yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient());
|
|
285
|
+
// If the client is not found, return an empty array.
|
|
286
|
+
if (!client) {
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
// If a chainId is provided, return the recovery methods for that chain.
|
|
290
|
+
if (chainId) {
|
|
291
|
+
const namespace = chainId.split(':')[0] || '';
|
|
292
|
+
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;
|
|
293
|
+
if (!curve) {
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
const wallet = client.wallets.find((w) => w.curve === curve);
|
|
297
|
+
if (!wallet) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const methods = this.extractBackupMethod(wallet);
|
|
301
|
+
return this.getUniqueBackupMethod(methods);
|
|
302
|
+
}
|
|
303
|
+
// Otherwise, return the recovery methods for all wallets.
|
|
304
|
+
const allMethods = client.wallets.flatMap((wallet) => this.extractBackupMethod(wallet));
|
|
305
|
+
return this.getUniqueBackupMethod(allMethods);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
228
308
|
/****************************
|
|
229
309
|
* Provider Methods
|
|
230
310
|
****************************/
|
|
@@ -233,6 +313,9 @@ class Portal {
|
|
|
233
313
|
return this.provider.request(request);
|
|
234
314
|
});
|
|
235
315
|
}
|
|
316
|
+
updateChain(newChainId) {
|
|
317
|
+
this.provider.setChainId(Number(newChainId));
|
|
318
|
+
}
|
|
236
319
|
/**
|
|
237
320
|
* Estimates the amount of gas that will be required to execute an Ethereum transaction.
|
|
238
321
|
*
|
|
@@ -247,7 +330,7 @@ class Portal {
|
|
|
247
330
|
console.warn('"portal.ethEstimateGas" is deprecated. Use "portal.request" instead.');
|
|
248
331
|
return this.provider.request({
|
|
249
332
|
chainId,
|
|
250
|
-
method:
|
|
333
|
+
method: provider_1.RequestMethod.eth_estimateGas,
|
|
251
334
|
params: transaction,
|
|
252
335
|
});
|
|
253
336
|
});
|
|
@@ -265,7 +348,7 @@ class Portal {
|
|
|
265
348
|
console.warn('"portal.ethGasPrice" is deprecated. Use "portal.request" instead.');
|
|
266
349
|
return this.provider.request({
|
|
267
350
|
chainId,
|
|
268
|
-
method:
|
|
351
|
+
method: provider_1.RequestMethod.eth_gasPrice,
|
|
269
352
|
params: [],
|
|
270
353
|
});
|
|
271
354
|
});
|
|
@@ -283,7 +366,7 @@ class Portal {
|
|
|
283
366
|
console.warn('"portal.ethGetBalance" is deprecated. Use "portal.request" instead.');
|
|
284
367
|
return this.provider.request({
|
|
285
368
|
chainId,
|
|
286
|
-
method:
|
|
369
|
+
method: provider_1.RequestMethod.eth_getBalance,
|
|
287
370
|
params: [this.address, 'latest'],
|
|
288
371
|
});
|
|
289
372
|
});
|
|
@@ -302,7 +385,7 @@ class Portal {
|
|
|
302
385
|
console.warn('"portal.ethSendTransaction" is deprecated. Use "portal.request" instead.');
|
|
303
386
|
return this.provider.request({
|
|
304
387
|
chainId,
|
|
305
|
-
method:
|
|
388
|
+
method: provider_1.RequestMethod.eth_sendTransaction,
|
|
306
389
|
params: transaction,
|
|
307
390
|
});
|
|
308
391
|
});
|
|
@@ -321,7 +404,7 @@ class Portal {
|
|
|
321
404
|
console.warn('"portal.ethSignTransaction" is deprecated. Use "portal.request" instead.');
|
|
322
405
|
return this.provider.request({
|
|
323
406
|
chainId,
|
|
324
|
-
method:
|
|
407
|
+
method: provider_1.RequestMethod.eth_signTransaction,
|
|
325
408
|
params: transaction,
|
|
326
409
|
});
|
|
327
410
|
});
|
|
@@ -340,7 +423,7 @@ class Portal {
|
|
|
340
423
|
console.warn('"portal.ethSignTypedData" is deprecated. Use "portal.request" instead.');
|
|
341
424
|
return this.provider.request({
|
|
342
425
|
chainId,
|
|
343
|
-
method:
|
|
426
|
+
method: provider_1.RequestMethod.eth_signTypedData,
|
|
344
427
|
params: [this.address, data],
|
|
345
428
|
});
|
|
346
429
|
});
|
|
@@ -359,7 +442,7 @@ class Portal {
|
|
|
359
442
|
console.warn('"portal.ethSignTypedDataV3" is deprecated. Use "portal.request" instead.');
|
|
360
443
|
return this.provider.request({
|
|
361
444
|
chainId,
|
|
362
|
-
method:
|
|
445
|
+
method: provider_1.RequestMethod.eth_signTypedData_v3,
|
|
363
446
|
params: [this.address, data],
|
|
364
447
|
});
|
|
365
448
|
});
|
|
@@ -378,7 +461,7 @@ class Portal {
|
|
|
378
461
|
console.warn('"portal.ethSignTypedDataV4" is deprecated. Use "portal.request" instead.');
|
|
379
462
|
return this.provider.request({
|
|
380
463
|
chainId,
|
|
381
|
-
method:
|
|
464
|
+
method: provider_1.RequestMethod.eth_signTypedData_v4,
|
|
382
465
|
params: [this.address, data],
|
|
383
466
|
});
|
|
384
467
|
});
|
|
@@ -388,7 +471,7 @@ class Portal {
|
|
|
388
471
|
console.warn('"portal.personalSign" is deprecated. Use "portal.request" instead.');
|
|
389
472
|
return (yield this.provider.request({
|
|
390
473
|
chainId,
|
|
391
|
-
method:
|
|
474
|
+
method: provider_1.RequestMethod.personal_sign,
|
|
392
475
|
params: [this.stringToHex(message), this.address],
|
|
393
476
|
}));
|
|
394
477
|
});
|
|
@@ -417,7 +500,7 @@ class Portal {
|
|
|
417
500
|
// Get the most recent blockhash.
|
|
418
501
|
const blockhashResponse = yield this.provider.request({
|
|
419
502
|
chainId: chainId,
|
|
420
|
-
method:
|
|
503
|
+
method: provider_1.RequestMethod.sol_getLatestBlockhash,
|
|
421
504
|
params: [],
|
|
422
505
|
});
|
|
423
506
|
const blockhash = ((_a = blockhashResponse === null || blockhashResponse === void 0 ? void 0 : blockhashResponse.value) === null || _a === void 0 ? void 0 : _a.blockhash) || '';
|
|
@@ -464,7 +547,7 @@ class Portal {
|
|
|
464
547
|
// Attempt to sign and send the transaction
|
|
465
548
|
const transactionResult = yield this.provider.request({
|
|
466
549
|
chainId: chainId,
|
|
467
|
-
method:
|
|
550
|
+
method: provider_1.RequestMethod.sol_signAndSendTransaction,
|
|
468
551
|
params: [formattedTransaction],
|
|
469
552
|
});
|
|
470
553
|
// If we didn't get a transactionResult, throw an error.
|
|
@@ -478,6 +561,9 @@ class Portal {
|
|
|
478
561
|
/*******************************
|
|
479
562
|
* API Methods
|
|
480
563
|
*******************************/
|
|
564
|
+
/**
|
|
565
|
+
* @deprecated This method is deprecated. Use `portal.getAssets` instead.
|
|
566
|
+
*/
|
|
481
567
|
getBalances(chainId) {
|
|
482
568
|
var _a;
|
|
483
569
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -490,6 +576,9 @@ class Portal {
|
|
|
490
576
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
|
|
491
577
|
});
|
|
492
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* @deprecated This method is deprecated. Use `portal.getNFTAssets` instead.
|
|
581
|
+
*/
|
|
493
582
|
getNFTs(chainId) {
|
|
494
583
|
var _a;
|
|
495
584
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -502,12 +591,39 @@ class Portal {
|
|
|
502
591
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(chainId, limit, offset, order);
|
|
503
592
|
});
|
|
504
593
|
}
|
|
594
|
+
/**
|
|
595
|
+
* @deprecated This method is deprecated. Use `portal.evaluateTransaction` instead.
|
|
596
|
+
*/
|
|
505
597
|
simulateTransaction(chainId, transaction) {
|
|
506
598
|
var _a;
|
|
507
599
|
return __awaiter(this, void 0, void 0, function* () {
|
|
508
600
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction, chainId);
|
|
509
601
|
});
|
|
510
602
|
}
|
|
603
|
+
evaluateTransaction(chainId, transaction, operationType = 'all') {
|
|
604
|
+
var _a;
|
|
605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.evaluateTransaction(chainId, transaction, operationType);
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
getAssets(chainId, includeNfts = false) {
|
|
610
|
+
var _a;
|
|
611
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getAssets(chainId, includeNfts);
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
getNFTAssets(chainId) {
|
|
616
|
+
var _a;
|
|
617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
618
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTAssets(chainId);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
buildTransaction(chainId, to, token, amount) {
|
|
622
|
+
var _a;
|
|
623
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
624
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.buildTransaction(chainId, to, token, amount);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
511
627
|
/*******************************
|
|
512
628
|
* Swaps Methods
|
|
513
629
|
*******************************/
|
|
@@ -554,9 +670,6 @@ class Portal {
|
|
|
554
670
|
// Otherwise, something is wrong with the configuration.
|
|
555
671
|
throw new Error(`[Portal] Could not find a valid rpcConfig entry for chainId: ${chainId}`);
|
|
556
672
|
}
|
|
557
|
-
/**************************
|
|
558
|
-
* RPC Encoding Methods
|
|
559
|
-
**************************/
|
|
560
673
|
stringToHex(str) {
|
|
561
674
|
if (str.startsWith('0x')) {
|
|
562
675
|
return str;
|
|
@@ -569,10 +682,20 @@ class Portal {
|
|
|
569
682
|
}
|
|
570
683
|
return hex;
|
|
571
684
|
}
|
|
685
|
+
extractBackupMethod(wallet) {
|
|
686
|
+
return wallet.backupSharePairs
|
|
687
|
+
.filter((share) => share.status === 'completed')
|
|
688
|
+
.map((share) => share.backupMethod);
|
|
689
|
+
}
|
|
690
|
+
getUniqueBackupMethod(methods) {
|
|
691
|
+
return Array.from(new Set(methods));
|
|
692
|
+
}
|
|
572
693
|
}
|
|
573
694
|
var mpc_2 = require("./mpc");
|
|
574
695
|
Object.defineProperty(exports, "MpcError", { enumerable: true, get: function () { return mpc_2.MpcError; } });
|
|
575
696
|
Object.defineProperty(exports, "MpcErrorCodes", { enumerable: true, get: function () { return mpc_2.MpcErrorCodes; } });
|
|
697
|
+
var provider_2 = require("./provider");
|
|
698
|
+
Object.defineProperty(exports, "RequestMethod", { enumerable: true, get: function () { return provider_2.RequestMethod; } });
|
|
576
699
|
var MpcStatuses;
|
|
577
700
|
(function (MpcStatuses) {
|
|
578
701
|
MpcStatuses["DecryptingShare"] = "Decrypting share";
|
|
@@ -602,4 +725,9 @@ var PortalCurve;
|
|
|
602
725
|
PortalCurve["ED25519"] = "ED25519";
|
|
603
726
|
PortalCurve["SECP256K1"] = "SECP256K1";
|
|
604
727
|
})(PortalCurve = exports.PortalCurve || (exports.PortalCurve = {}));
|
|
728
|
+
var ChainNamespace;
|
|
729
|
+
(function (ChainNamespace) {
|
|
730
|
+
ChainNamespace["EIP155"] = "eip155";
|
|
731
|
+
ChainNamespace["SOLANA"] = "solana";
|
|
732
|
+
})(ChainNamespace = exports.ChainNamespace || (exports.ChainNamespace = {}));
|
|
605
733
|
exports.default = Portal;
|