@portal-hq/web 3.9.0 → 3.10.0-alpha.2

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.
Files changed (36) hide show
  1. package/lib/commonjs/__mocks__/delegations.js +93 -0
  2. package/lib/commonjs/index.js +9 -3
  3. package/lib/commonjs/index.test.js +6 -4
  4. package/lib/commonjs/integrations/delegations/index.js +65 -0
  5. package/lib/commonjs/integrations/delegations/index.test.js +93 -0
  6. package/lib/commonjs/mpc/index.js +56 -2
  7. package/lib/commonjs/namespaces/evmAccountType/index.js +105 -0
  8. package/lib/commonjs/namespaces/evmAccountType/index.test.js +503 -0
  9. package/lib/commonjs/shared/types/delegations.js +2 -0
  10. package/lib/commonjs/shared/types/evmAccountType.js +2 -0
  11. package/lib/commonjs/shared/types/index.js +1 -0
  12. package/lib/esm/__mocks__/delegations.js +90 -0
  13. package/lib/esm/index.js +9 -3
  14. package/lib/esm/index.test.js +6 -4
  15. package/lib/esm/integrations/delegations/index.js +62 -0
  16. package/lib/esm/integrations/delegations/index.test.js +88 -0
  17. package/lib/esm/mpc/index.js +56 -2
  18. package/lib/esm/namespaces/evmAccountType/index.js +101 -0
  19. package/lib/esm/namespaces/evmAccountType/index.test.js +498 -0
  20. package/lib/esm/shared/types/delegations.js +1 -0
  21. package/lib/esm/shared/types/evmAccountType.js +1 -0
  22. package/lib/esm/shared/types/index.js +1 -0
  23. package/package.json +3 -2
  24. package/src/__mocks/constants.ts +116 -1
  25. package/src/__mocks__/delegations.ts +109 -0
  26. package/src/index.test.ts +6 -4
  27. package/src/index.ts +36 -17
  28. package/src/integrations/delegations/index.test.ts +122 -0
  29. package/src/integrations/delegations/index.ts +78 -0
  30. package/src/mpc/index.ts +79 -8
  31. package/src/namespaces/evmAccountType/index.test.ts +629 -0
  32. package/src/namespaces/evmAccountType/index.ts +140 -0
  33. package/src/shared/types/common.ts +1 -0
  34. package/src/shared/types/delegations.ts +114 -0
  35. package/src/shared/types/evmAccountType.ts +94 -0
  36. package/src/shared/types/index.ts +20 -0
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockTransferFromResponse = exports.mockTransferFromRequest = exports.mockGetStatusResponse = exports.mockGetStatusRequest = exports.mockEVMRevokeResponse = exports.mockEVMRevokeRequest = exports.mockEVMApproveResponse = exports.mockEVMApproveRequest = exports.mockHost = void 0;
4
+ exports.mockHost = 'web.portalhq.io';
5
+ exports.mockEVMApproveRequest = {
6
+ chain: 'eip155:1',
7
+ token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
8
+ delegateAddress: '0x1234567890123456789012345678901234567890',
9
+ amount: '1000000000',
10
+ };
11
+ exports.mockEVMApproveResponse = {
12
+ transactions: [
13
+ {
14
+ from: '0xUserAddress',
15
+ to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
16
+ data: '0x095ea7b3',
17
+ value: '0x0',
18
+ },
19
+ ],
20
+ metadata: {
21
+ chainId: 'eip155:1',
22
+ delegateAmount: '1000',
23
+ delegateAmountRaw: '1000000000',
24
+ delegateAddress: '0x1234567890123456789012345678901234567890',
25
+ tokenSymbol: 'USDC',
26
+ tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
27
+ ownerAddress: '0xUserAddress',
28
+ },
29
+ };
30
+ exports.mockEVMRevokeRequest = {
31
+ chain: 'eip155:1',
32
+ token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
33
+ delegateAddress: '0x1234567890123456789012345678901234567890',
34
+ };
35
+ exports.mockEVMRevokeResponse = {
36
+ transactions: [
37
+ {
38
+ from: '0xUserAddress',
39
+ to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
40
+ data: '0x095ea7b3',
41
+ value: '0x0',
42
+ },
43
+ ],
44
+ metadata: {
45
+ chainId: 'eip155:1',
46
+ revokedAddress: '0x1234567890123456789012345678901234567890',
47
+ tokenSymbol: 'USDC',
48
+ tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
49
+ ownerAddress: '0xUserAddress',
50
+ },
51
+ };
52
+ exports.mockGetStatusRequest = {
53
+ chain: 'eip155:1',
54
+ token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
55
+ delegateAddress: '0x1234567890123456789012345678901234567890',
56
+ };
57
+ exports.mockGetStatusResponse = {
58
+ chainId: 'eip155:1',
59
+ token: 'USDC',
60
+ tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
61
+ balance: '5000',
62
+ balanceRaw: '5000000000',
63
+ delegations: [
64
+ {
65
+ address: '0x1234567890123456789012345678901234567890',
66
+ delegateAmount: '1000',
67
+ delegateAmountRaw: '1000000000',
68
+ },
69
+ ],
70
+ };
71
+ exports.mockTransferFromRequest = {
72
+ chain: 'eip155:11155111',
73
+ token: 'USDC',
74
+ fromAddress: '0xc53fbaea2daa07f2a3d7e586aeed7b3b92fe2985',
75
+ toAddress: '0xdFd8302f44727A6348F702fF7B594f127dE3A902',
76
+ amount: '1.0',
77
+ };
78
+ exports.mockTransferFromResponse = {
79
+ transactions: [
80
+ {
81
+ from: exports.mockTransferFromRequest.fromAddress,
82
+ to: exports.mockTransferFromRequest.toAddress,
83
+ data: '0xmockdata',
84
+ value: '0x1',
85
+ },
86
+ ],
87
+ metadata: {
88
+ chainId: 'eip155:11155111',
89
+ amount: exports.mockTransferFromRequest.amount,
90
+ amountRaw: '1000000',
91
+ tokenSymbol: 'USDC',
92
+ },
93
+ };
@@ -42,7 +42,9 @@ const provider_1 = __importStar(require("./provider"));
42
42
  const yield_1 = __importDefault(require("./integrations/yield"));
43
43
  const trading_1 = __importDefault(require("./integrations/trading"));
44
44
  const security_1 = __importDefault(require("./integrations/security"));
45
+ const delegations_1 = __importDefault(require("./integrations/delegations"));
45
46
  const passkeys_1 = __importDefault(require("./passkeys"));
47
+ const evmAccountType_1 = require("./namespaces/evmAccountType");
46
48
  class Portal {
47
49
  get ready() {
48
50
  return this.mpc.ready;
@@ -88,10 +90,12 @@ class Portal {
88
90
  this.yield = new yield_1.default({ mpc: this.mpc });
89
91
  this.trading = new trading_1.default({ mpc: this.mpc });
90
92
  this.security = new security_1.default({ mpc: this.mpc });
93
+ this.delegations = new delegations_1.default({ mpc: this.mpc });
91
94
  this.provider = new provider_1.default({
92
95
  portal: this,
93
96
  chainId: chainId ? Number(chainId) : undefined,
94
97
  });
98
+ this.evmAccountType = new evmAccountType_1.EvmAccountType({ mpc: this.mpc });
95
99
  }
96
100
  /*****************************
97
101
  * Initialization Methods
@@ -156,14 +160,16 @@ class Portal {
156
160
  }) {
157
161
  return __awaiter(this, void 0, void 0, function* () {
158
162
  const response = yield this.mpc.backup({
159
- backupMethod: BackupMethods.custom,
160
- backupConfigs: {},
163
+ backupMethod: BackupMethods.passkey,
164
+ backupConfigs: {
165
+ skipStorageWrite: true,
166
+ },
161
167
  host: this.host,
162
168
  mpcVersion: this.mpcVersion,
163
169
  featureFlags: this.featureFlags,
164
170
  }, progress);
165
171
  if (!response.encryptionKey) {
166
- throw new Error('[Portal] Custom backup did not return an encryption key. Please ensure you are using the latest iframe bundle.');
172
+ throw new Error('[Portal] Passkey backup did not return an encryption key. Please ensure you are using the latest iframe bundle.');
167
173
  }
168
174
  return {
169
175
  cipherText: response.cipherText,
@@ -145,7 +145,7 @@ describe('Portal', () => {
145
145
  }));
146
146
  });
147
147
  describe('generateBackupShare', () => {
148
- it('should request a custom backup and return cipherText and encryptionKey', () => __awaiter(void 0, void 0, void 0, function* () {
148
+ it('should request a passkey backup with skipStorageWrite and return cipherText and encryptionKey', () => __awaiter(void 0, void 0, void 0, function* () {
149
149
  const storageCallback = jest.fn().mockResolvedValue(undefined);
150
150
  portal.mpc.backup.mockResolvedValueOnce({
151
151
  cipherText: constants_1.mockCipherText,
@@ -158,8 +158,10 @@ describe('Portal', () => {
158
158
  encryptionKey: 'manual-key',
159
159
  });
160
160
  expect(portal.mpc.backup).toHaveBeenCalledWith({
161
- backupMethod: _1.BackupMethods.custom,
162
- backupConfigs: {},
161
+ backupMethod: _1.BackupMethods.passkey,
162
+ backupConfigs: {
163
+ skipStorageWrite: true,
164
+ },
163
165
  host: 'web.portalhq.io',
164
166
  mpcVersion: 'v6',
165
167
  featureFlags: {},
@@ -171,7 +173,7 @@ describe('Portal', () => {
171
173
  cipherText: constants_1.mockCipherText,
172
174
  storageCallback: jest.fn(),
173
175
  });
174
- yield expect(portal.generateBackupShare()).rejects.toThrow('Custom backup did not return an encryption key');
176
+ yield expect(portal.generateBackupShare()).rejects.toThrow('Passkey backup did not return an encryption key');
175
177
  }));
176
178
  });
177
179
  describe('registerPasskeyAndStoreEncryptionKey', () => {
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ class Delegations {
13
+ constructor({ mpc }) {
14
+ this.mpc = mpc;
15
+ }
16
+ /**
17
+ * Approves a delegation for a specified token on a given chain.
18
+ * Returns transactions for EVM chains or encodedTransactions for Solana chains.
19
+ * @param params - Delegation approval parameters
20
+ * @returns Promise resolving to approval response with transaction data
21
+ */
22
+ approve(params) {
23
+ var _a;
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.delegationsApprove(params);
26
+ });
27
+ }
28
+ /**
29
+ * Revokes a delegation for a specified token on a given chain.
30
+ * Returns transactions for EVM chains or encodedTransactions for Solana chains.
31
+ * @param params - Delegation revocation parameters
32
+ * @returns Promise resolving to revocation response with transaction data
33
+ */
34
+ revoke(params) {
35
+ var _a;
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.delegationsRevoke(params);
38
+ });
39
+ }
40
+ /**
41
+ * Retrieves the delegation status for a specified token and delegate address.
42
+ * @param params - Delegation status query parameters
43
+ * @returns Promise resolving to delegation status information
44
+ */
45
+ getStatus(params) {
46
+ var _a;
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.delegationsGetStatus(params);
49
+ });
50
+ }
51
+ /**
52
+ * Transfers tokens from one address to another using delegated authority.
53
+ * The caller must have been previously approved as a delegate.
54
+ * Returns transactions for EVM chains or encodedTransactions for Solana chains.
55
+ * @param params - Transfer from delegation parameters
56
+ * @returns Promise resolving to transfer response with transaction data
57
+ */
58
+ transferFrom(params) {
59
+ var _a;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.delegationsTransferFrom(params);
62
+ });
63
+ }
64
+ }
65
+ exports.default = Delegations;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * @jest-environment jsdom
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const _1 = __importDefault(require("."));
19
+ const mpc_1 = __importDefault(require("../../mpc"));
20
+ const portal_1 = __importDefault(require("../../__mocks/portal/portal"));
21
+ const delegations_1 = require("../../__mocks__/delegations");
22
+ describe('Delegations', () => {
23
+ let delegations;
24
+ let mpc;
25
+ beforeEach(() => {
26
+ jest.clearAllMocks();
27
+ portal_1.default.host = delegations_1.mockHost;
28
+ mpc = new mpc_1.default({
29
+ portal: portal_1.default,
30
+ });
31
+ delegations = new _1.default({ mpc });
32
+ });
33
+ describe('approve', () => {
34
+ it('should call mpc.delegationsApprove with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
35
+ const spy = jest
36
+ .spyOn(mpc, 'delegationsApprove')
37
+ .mockResolvedValue(delegations_1.mockEVMApproveResponse);
38
+ const result = yield delegations.approve(delegations_1.mockEVMApproveRequest);
39
+ expect(spy).toHaveBeenCalledWith(delegations_1.mockEVMApproveRequest);
40
+ expect(result).toEqual(delegations_1.mockEVMApproveResponse);
41
+ }));
42
+ it('should propagate errors from mpc.delegationsApprove', () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const error = new Error('Test error');
44
+ jest.spyOn(mpc, 'delegationsApprove').mockRejectedValue(error);
45
+ yield expect(delegations.approve(delegations_1.mockEVMApproveRequest)).rejects.toThrow('Test error');
46
+ }));
47
+ });
48
+ describe('revoke', () => {
49
+ it('should call mpc.delegationsRevoke with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const spy = jest
51
+ .spyOn(mpc, 'delegationsRevoke')
52
+ .mockResolvedValue(delegations_1.mockEVMRevokeResponse);
53
+ const result = yield delegations.revoke(delegations_1.mockEVMRevokeRequest);
54
+ expect(spy).toHaveBeenCalledWith(delegations_1.mockEVMRevokeRequest);
55
+ expect(result).toEqual(delegations_1.mockEVMRevokeResponse);
56
+ }));
57
+ it('should propagate errors from mpc.delegationsRevoke', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ const error = new Error('Test error');
59
+ jest.spyOn(mpc, 'delegationsRevoke').mockRejectedValue(error);
60
+ yield expect(delegations.revoke(delegations_1.mockEVMRevokeRequest)).rejects.toThrow('Test error');
61
+ }));
62
+ });
63
+ describe('getStatus', () => {
64
+ it('should call mpc.delegationsGetStatus with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
65
+ const spy = jest
66
+ .spyOn(mpc, 'delegationsGetStatus')
67
+ .mockResolvedValue(delegations_1.mockGetStatusResponse);
68
+ const result = yield delegations.getStatus(delegations_1.mockGetStatusRequest);
69
+ expect(spy).toHaveBeenCalledWith(delegations_1.mockGetStatusRequest);
70
+ expect(result).toEqual(delegations_1.mockGetStatusResponse);
71
+ }));
72
+ it('should propagate errors from mpc.delegationsGetStatus', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const error = new Error('Test error');
74
+ jest.spyOn(mpc, 'delegationsGetStatus').mockRejectedValue(error);
75
+ yield expect(delegations.getStatus(delegations_1.mockGetStatusRequest)).rejects.toThrow('Test error');
76
+ }));
77
+ });
78
+ describe('transferFrom', () => {
79
+ it('should call mpc.delegationsTransferFrom with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
80
+ const spy = jest
81
+ .spyOn(mpc, 'delegationsTransferFrom')
82
+ .mockResolvedValue(delegations_1.mockTransferFromResponse);
83
+ const result = yield delegations.transferFrom(delegations_1.mockTransferFromRequest);
84
+ expect(spy).toHaveBeenCalledWith(delegations_1.mockTransferFromRequest);
85
+ expect(result).toEqual(delegations_1.mockTransferFromResponse);
86
+ }));
87
+ it('should propagate errors from mpc.delegationsTransferFrom', () => __awaiter(void 0, void 0, void 0, function* () {
88
+ const error = new Error('Test error');
89
+ jest.spyOn(mpc, 'delegationsTransferFrom').mockRejectedValue(error);
90
+ yield expect(delegations.transferFrom(delegations_1.mockTransferFromRequest)).rejects.toThrow('Test error');
91
+ }));
92
+ });
93
+ });
@@ -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 = '3.9.0';
15
+ const WEB_SDK_VERSION = '3.10.0-alpha.2';
16
16
  class Mpc {
17
17
  get ready() {
18
18
  return this._ready;
@@ -650,11 +650,65 @@ class Mpc {
650
650
  });
651
651
  });
652
652
  }
653
+ /*******************************
654
+ * Delegations Methods
655
+ *******************************/
656
+ delegationsApprove(data) {
657
+ return __awaiter(this, void 0, void 0, function* () {
658
+ return this.handleRequestToIframeAndPost({
659
+ methodMessage: 'portal:delegations:approve',
660
+ errorMessage: 'portal:delegations:approveError',
661
+ resultMessage: 'portal:delegations:approveResult',
662
+ data,
663
+ });
664
+ });
665
+ }
666
+ delegationsRevoke(data) {
667
+ return __awaiter(this, void 0, void 0, function* () {
668
+ return this.handleRequestToIframeAndPost({
669
+ methodMessage: 'portal:delegations:revoke',
670
+ errorMessage: 'portal:delegations:revokeError',
671
+ resultMessage: 'portal:delegations:revokeResult',
672
+ data,
673
+ });
674
+ });
675
+ }
676
+ delegationsGetStatus(data) {
677
+ return __awaiter(this, void 0, void 0, function* () {
678
+ return this.handleRequestToIframeAndPost({
679
+ methodMessage: 'portal:delegations:getStatus',
680
+ errorMessage: 'portal:delegations:getStatusError',
681
+ resultMessage: 'portal:delegations:getStatusResult',
682
+ data,
683
+ });
684
+ });
685
+ }
686
+ delegationsTransferFrom(data) {
687
+ return __awaiter(this, void 0, void 0, function* () {
688
+ return this.handleRequestToIframeAndPost({
689
+ methodMessage: 'portal:delegations:transferFrom',
690
+ errorMessage: 'portal:delegations:transferFromError',
691
+ resultMessage: 'portal:delegations:transferFromResult',
692
+ data,
693
+ });
694
+ });
695
+ }
653
696
  /***************************
654
697
  * Private Methods
655
698
  ***************************/
656
699
  /**
657
- * Util to handle requests to the iframe and post the result to the parent
700
+ * Util to handle requests to the iframe and post the result to the parent.
701
+ *
702
+ * @remarks
703
+ * This is an advanced/internal API intended primarily for low-level integrations
704
+ * (for example, framework or account-type abstractions such as EvmAccountType).
705
+ * Typical consumers should prefer using the higher-level methods exposed on
706
+ * the {@link Mpc} class (e.g. {@link delegationsApprove}, {@link delegationsRevoke},
707
+ * {@link delegationsGetStatus}, {@link delegationsTransferFrom}) instead of calling
708
+ * this method directly.
709
+ *
710
+ * This method is not part of the stable public surface area and may change in
711
+ * future releases without notice.
658
712
  */
659
713
  handleRequestToIframeAndPost({ methodMessage, errorMessage, resultMessage, data, progressMessage, progressCallback, mapReturnValue, }) {
660
714
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EvmAccountType = void 0;
13
+ const index_1 = require("../../index");
14
+ class EvmAccountType {
15
+ constructor({ mpc }) {
16
+ this.mpc = mpc;
17
+ }
18
+ /**
19
+ * Get the account type for a given chain
20
+ * @param {EvmAccountTypeGetStatusRequest} params - The request parameters
21
+ * @returns {Promise<EvmAccountTypeGetStatusResponse>} The account type
22
+ */
23
+ getStatus({ chain, }) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return this.mpc.handleRequestToIframeAndPost({
26
+ methodMessage: 'portal:evmAccountType:getStatus',
27
+ errorMessage: 'portal:evmAccountType:getStatusError',
28
+ resultMessage: 'portal:evmAccountType:getStatusResult',
29
+ data: { chain },
30
+ });
31
+ });
32
+ }
33
+ /**
34
+ * Build the authorization list for a given chain.
35
+ * @param {BuildAuthorizationListRequest} params - The request parameters
36
+ * @returns {Promise<BuildAuthorizationListResponse>} The authorization list
37
+ */
38
+ buildAuthorizationList(params) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.mpc.handleRequestToIframeAndPost({
41
+ methodMessage: 'portal:evmAccountType:buildAuthorizationList',
42
+ errorMessage: 'portal:evmAccountType:buildAuthorizationListError',
43
+ resultMessage: 'portal:evmAccountType:buildAuthorizationListResult',
44
+ data: params,
45
+ });
46
+ });
47
+ }
48
+ /**
49
+ * Build the 7702 upgrade transaction for a given chain.
50
+ * @param {Build7702UpgradeTxRequest} params - The request parameters
51
+ * @returns {Promise<Build7702UpgradeTxResponse>} The upgrade transaction
52
+ */
53
+ build7702UpgradeTx(params) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return this.mpc.handleRequestToIframeAndPost({
56
+ methodMessage: 'portal:evmAccountType:build7702UpgradeTx',
57
+ errorMessage: 'portal:evmAccountType:build7702UpgradeTxError',
58
+ resultMessage: 'portal:evmAccountType:build7702UpgradeTxResult',
59
+ data: params,
60
+ });
61
+ });
62
+ }
63
+ /**
64
+ * Upgrade the account to EIP-7702. This handles the entire upgrade process, including building the authorization list, signing the transaction, and sending the transaction.
65
+ * @param {UpgradeTo7702Request} params - The request parameters
66
+ * @returns {Promise<UpgradeTo7702Response>} The upgrade response
67
+ */
68
+ upgradeTo7702(params) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const { chain } = params;
71
+ if (!chain.startsWith('eip155:')) {
72
+ throw new Error(`Invalid chain for EIP-7702 upgrade. Expected EVM chain (eip155:*), got: ${chain}`);
73
+ }
74
+ const accountType = yield this.getStatus({ chain });
75
+ if (accountType.data.status === 'SMART_CONTRACT') {
76
+ throw new Error('Account is already a smart contract. EIP-7702 upgrade is only available for EOA accounts.');
77
+ }
78
+ if (accountType.data.status === 'EIP_7702_EOA') {
79
+ throw new Error('Account is already upgraded to EIP-7702.');
80
+ }
81
+ if (accountType.data.status !== 'EIP_155_EOA') {
82
+ throw new Error(`Unexpected account type: ${accountType.data.status}`);
83
+ }
84
+ const authorizationList = yield this.buildAuthorizationList({
85
+ chain,
86
+ subsidize: true,
87
+ });
88
+ const hashWithoutPrefix = authorizationList.data.hash.startsWith('0x')
89
+ ? authorizationList.data.hash.slice(2)
90
+ : authorizationList.data.hash;
91
+ const rawSignTx = yield this.mpc.rawSign(index_1.PortalCurve.SECP256K1, hashWithoutPrefix);
92
+ const upgradeTx = yield this.build7702UpgradeTx({
93
+ chain,
94
+ signature: rawSignTx,
95
+ subsidize: true,
96
+ });
97
+ const txHash = upgradeTx.data.transactionHash;
98
+ if (!txHash) {
99
+ throw new Error('Transaction hash not returned from build7702UpgradeTx. The upgrade transaction may not have been submitted.');
100
+ }
101
+ return { txHash };
102
+ });
103
+ }
104
+ }
105
+ exports.EvmAccountType = EvmAccountType;