@portal-hq/utils 3.0.6 → 4.1.0-beta

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.
@@ -0,0 +1,87 @@
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
+ const index_1 = require("../index");
13
+ class PortalRequests {
14
+ buildHeaders(headers = {}) {
15
+ return Object.assign({ 'Content-Type': 'application/json' }, headers);
16
+ }
17
+ delete(baseUrl, path, options) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const requestOptions = {
20
+ method: 'DELETE',
21
+ url: `${baseUrl}${path}`,
22
+ };
23
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
24
+ const request = new index_1.HttpRequest(requestOptions);
25
+ const response = (yield request.send());
26
+ return response;
27
+ });
28
+ }
29
+ get(baseUrl, path, options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const requestOptions = {
32
+ method: 'GET',
33
+ url: `${baseUrl}${path}`,
34
+ };
35
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
36
+ const request = new index_1.HttpRequest(requestOptions);
37
+ const response = (yield request.send());
38
+ return response;
39
+ });
40
+ }
41
+ post(baseUrl, path, options) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const requestOptions = {
44
+ method: 'POST',
45
+ url: `${baseUrl}${path}`,
46
+ };
47
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
48
+ if (options && options.body) {
49
+ requestOptions.body = options.body;
50
+ }
51
+ const request = new index_1.HttpRequest(requestOptions);
52
+ const response = (yield request.send());
53
+ return response;
54
+ });
55
+ }
56
+ put(baseUrl, path, options) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const requestOptions = {
59
+ method: 'PUT',
60
+ url: `${baseUrl}${path}`,
61
+ };
62
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
63
+ if (options && options.body) {
64
+ requestOptions.body = options.body;
65
+ }
66
+ const request = new index_1.HttpRequest(requestOptions);
67
+ const response = (yield request.send());
68
+ return response;
69
+ });
70
+ }
71
+ patch(baseUrl, path, options) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const requestOptions = {
74
+ method: 'PATCH',
75
+ url: `${baseUrl}${path}`,
76
+ };
77
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
78
+ if (options && options.body) {
79
+ requestOptions.body = options.body;
80
+ }
81
+ const request = new index_1.HttpRequest(requestOptions);
82
+ const response = (yield request.send());
83
+ return response;
84
+ });
85
+ }
86
+ }
87
+ exports.default = PortalRequests;
@@ -2,27 +2,47 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PasswordStorage = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = void 0;
4
4
  class KeychainAdapter {
5
+ loadMetadata() {
6
+ throw new Error('[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.');
7
+ }
5
8
  deleteAddress() {
6
9
  throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.');
7
10
  }
11
+ deleteShares() {
12
+ throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.');
13
+ }
8
14
  deleteDkgResult() {
9
15
  throw new Error('[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.');
10
16
  }
11
17
  getAddress(isSim) {
12
18
  throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
13
19
  }
14
- getDkgResult(isSim, _progress = () => {
20
+ getDkgResult(isSim) {
21
+ throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
22
+ }
23
+ getShares(_progress = () => {
15
24
  // Noop
16
25
  }) {
17
- throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
26
+ throw new Error('[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.');
27
+ }
28
+ getSigningShare(curve, _progress = () => {
29
+ // Noop
30
+ }) {
31
+ throw new Error(`[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`);
32
+ }
33
+ getAddresses() {
34
+ throw new Error('[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.');
35
+ }
36
+ getEip155Address() {
37
+ throw new Error('[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.');
18
38
  }
19
39
  storeAddress(address, isSim) {
20
40
  throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
21
41
  }
22
- storeDkgResult(result, isSim, _progress = () => {
42
+ storeShares(result, _progress = () => {
23
43
  // Noop
24
44
  }) {
25
- throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
45
+ throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`);
26
46
  }
27
47
  validateOperations() {
28
48
  throw new Error(`[Portal] KeychainAdapter method validateOperations() cannot be called directly. Please extend KeychainAdapter.`);
@@ -11,6 +11,7 @@ var Events;
11
11
  Events["GetBackupShareMetadata"] = "Get Backup Share Metadata";
12
12
  Events["GetBalances"] = "Get Balances";
13
13
  Events["GetClient"] = "Get Client";
14
+ Events["GetClientCipherText"] = "Get Client Cipher Text";
14
15
  Events["GetEnabledDapps"] = "Get Enabled Dapps";
15
16
  Events["GetNFTs"] = "Get NFTs";
16
17
  Events["GetNetworks"] = "Get Networks";
@@ -18,7 +19,9 @@ var Events;
18
19
  Events["GetSigningShareMetadata"] = "Get Signing Share Metadata";
19
20
  Events["GetSources"] = "Get Sources";
20
21
  Events["GetTransactions"] = "Get Transactions";
22
+ Events["PrepareClientEject"] = "Prepare Client Eject";
21
23
  Events["SimulateTransaction"] = "Simulate Transaction";
24
+ Events["StoreClientCipherText"] = "Store Client Cipher Text";
22
25
  Events["StoredClientBackupShare"] = "Stored Client Backup Share";
23
26
  Events["StoredClientBackupShareKey"] = "Stored Client Backup Share Key";
24
27
  Events["StoredClientSigningShare"] = "Stored Client Signing Share";
@@ -15,7 +15,7 @@ class HttpRequest {
15
15
  // Sets headers on the request
16
16
  this.prepareRequest();
17
17
  // Sends the request with a formatted request body
18
- if (['POST', 'PUT'].includes(this.method)) {
18
+ if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
19
19
  const body = this.prepareBody();
20
20
  this.request.send(body);
21
21
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HttpRequester = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
6
+ exports.HttpRequester = exports.PortalRequests = exports.HttpRequest = exports.parseRequest = exports.numberToHexString = exports.Events = exports.RpcErrorCodes = exports.ProviderRpcError = exports.PortalMpcError = exports.PortalErrorCodeTypes = exports.PortalErrorCodes = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.CloudStorageReadError = exports.Storage = exports.MpcStatuses = exports.KeychainAdapter = exports.convert = exports.convertCryptoToLocal = exports.convertLocalToCrypto = exports.getChainNameForId = exports.getChainIdForName = exports.chainNameToId = exports.chainIdToName = void 0;
7
7
  var chains_1 = require("./chains");
8
8
  Object.defineProperty(exports, "chainIdToName", { enumerable: true, get: function () { return chains_1.chainIdToName; } });
9
9
  Object.defineProperty(exports, "chainNameToId", { enumerable: true, get: function () { return chains_1.chainNameToId; } });
@@ -38,5 +38,7 @@ Object.defineProperty(exports, "numberToHexString", { enumerable: true, get: fun
38
38
  Object.defineProperty(exports, "parseRequest", { enumerable: true, get: function () { return eth_requests_1.parseRequest; } });
39
39
  var http_request_1 = require("./http-request");
40
40
  Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return __importDefault(http_request_1).default; } });
41
+ var PortalRequests_1 = require("./PortalRequests");
42
+ Object.defineProperty(exports, "PortalRequests", { enumerable: true, get: function () { return __importDefault(PortalRequests_1).default; } });
41
43
  var requesters_1 = require("./requesters");
42
44
  Object.defineProperty(exports, "HttpRequester", { enumerable: true, get: function () { return requesters_1.HttpRequester; } });
@@ -71,5 +71,20 @@ class HttpRequester {
71
71
  return response;
72
72
  });
73
73
  }
74
+ patch(path, options) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const requestOptions = {
77
+ method: 'PATCH',
78
+ url: `${this.baseUrl}${path}`,
79
+ };
80
+ requestOptions.headers = this.buildHeaders((options === null || options === void 0 ? void 0 : options.headers) ? options.headers : {});
81
+ if (options && options.body) {
82
+ requestOptions.body = options.body;
83
+ }
84
+ const request = new index_1.HttpRequest(requestOptions);
85
+ const response = (yield request.send());
86
+ return response;
87
+ });
88
+ }
74
89
  }
75
90
  exports.default = HttpRequester;
@@ -0,0 +1,85 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { HttpRequest } from '../index';
11
+ class PortalRequests {
12
+ buildHeaders(headers = {}) {
13
+ return Object.assign({ 'Content-Type': 'application/json' }, headers);
14
+ }
15
+ delete(baseUrl, path, options) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const requestOptions = {
18
+ method: 'DELETE',
19
+ url: `${baseUrl}${path}`,
20
+ };
21
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
22
+ const request = new HttpRequest(requestOptions);
23
+ const response = (yield request.send());
24
+ return response;
25
+ });
26
+ }
27
+ get(baseUrl, path, options) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const requestOptions = {
30
+ method: 'GET',
31
+ url: `${baseUrl}${path}`,
32
+ };
33
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
34
+ const request = new HttpRequest(requestOptions);
35
+ const response = (yield request.send());
36
+ return response;
37
+ });
38
+ }
39
+ post(baseUrl, path, options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const requestOptions = {
42
+ method: 'POST',
43
+ url: `${baseUrl}${path}`,
44
+ };
45
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
46
+ if (options && options.body) {
47
+ requestOptions.body = options.body;
48
+ }
49
+ const request = new HttpRequest(requestOptions);
50
+ const response = (yield request.send());
51
+ return response;
52
+ });
53
+ }
54
+ put(baseUrl, path, options) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const requestOptions = {
57
+ method: 'PUT',
58
+ url: `${baseUrl}${path}`,
59
+ };
60
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
61
+ if (options && options.body) {
62
+ requestOptions.body = options.body;
63
+ }
64
+ const request = new HttpRequest(requestOptions);
65
+ const response = (yield request.send());
66
+ return response;
67
+ });
68
+ }
69
+ patch(baseUrl, path, options) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const requestOptions = {
72
+ method: 'PATCH',
73
+ url: `${baseUrl}${path}`,
74
+ };
75
+ requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
76
+ if (options && options.body) {
77
+ requestOptions.body = options.body;
78
+ }
79
+ const request = new HttpRequest(requestOptions);
80
+ const response = (yield request.send());
81
+ return response;
82
+ });
83
+ }
84
+ }
85
+ export default PortalRequests;
@@ -1,25 +1,45 @@
1
1
  export class KeychainAdapter {
2
+ loadMetadata() {
3
+ throw new Error('[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.');
4
+ }
2
5
  deleteAddress() {
3
6
  throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.');
4
7
  }
8
+ deleteShares() {
9
+ throw new Error('[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.');
10
+ }
5
11
  deleteDkgResult() {
6
12
  throw new Error('[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.');
7
13
  }
8
14
  getAddress(isSim) {
9
15
  throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
10
16
  }
11
- getDkgResult(isSim, _progress = () => {
17
+ getDkgResult(isSim) {
18
+ throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
19
+ }
20
+ getShares(_progress = () => {
12
21
  // Noop
13
22
  }) {
14
- throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
23
+ throw new Error('[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.');
24
+ }
25
+ getSigningShare(curve, _progress = () => {
26
+ // Noop
27
+ }) {
28
+ throw new Error(`[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`);
29
+ }
30
+ getAddresses() {
31
+ throw new Error('[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.');
32
+ }
33
+ getEip155Address() {
34
+ throw new Error('[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.');
15
35
  }
16
36
  storeAddress(address, isSim) {
17
37
  throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
18
38
  }
19
- storeDkgResult(result, isSim, _progress = () => {
39
+ storeShares(result, _progress = () => {
20
40
  // Noop
21
41
  }) {
22
- throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
42
+ throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`);
23
43
  }
24
44
  validateOperations() {
25
45
  throw new Error(`[Portal] KeychainAdapter method validateOperations() cannot be called directly. Please extend KeychainAdapter.`);
@@ -9,6 +9,7 @@ var Events;
9
9
  Events["GetBackupShareMetadata"] = "Get Backup Share Metadata";
10
10
  Events["GetBalances"] = "Get Balances";
11
11
  Events["GetClient"] = "Get Client";
12
+ Events["GetClientCipherText"] = "Get Client Cipher Text";
12
13
  Events["GetEnabledDapps"] = "Get Enabled Dapps";
13
14
  Events["GetNFTs"] = "Get NFTs";
14
15
  Events["GetNetworks"] = "Get Networks";
@@ -16,7 +17,9 @@ var Events;
16
17
  Events["GetSigningShareMetadata"] = "Get Signing Share Metadata";
17
18
  Events["GetSources"] = "Get Sources";
18
19
  Events["GetTransactions"] = "Get Transactions";
20
+ Events["PrepareClientEject"] = "Prepare Client Eject";
19
21
  Events["SimulateTransaction"] = "Simulate Transaction";
22
+ Events["StoreClientCipherText"] = "Store Client Cipher Text";
20
23
  Events["StoredClientBackupShare"] = "Stored Client Backup Share";
21
24
  Events["StoredClientBackupShareKey"] = "Stored Client Backup Share Key";
22
25
  Events["StoredClientSigningShare"] = "Stored Client Signing Share";
@@ -13,7 +13,7 @@ class HttpRequest {
13
13
  // Sets headers on the request
14
14
  this.prepareRequest();
15
15
  // Sends the request with a formatted request body
16
- if (['POST', 'PUT'].includes(this.method)) {
16
+ if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
17
17
  const body = this.prepareBody();
18
18
  this.request.send(body);
19
19
  }
package/lib/esm/index.js CHANGED
@@ -5,4 +5,5 @@ export { CloudStorageReadError, HttpError, InvalidApiKeyError, InvalidChainIdErr
5
5
  export { default as Events } from './events';
6
6
  export { numberToHexString, parseRequest } from './eth-requests';
7
7
  export { default as HttpRequest } from './http-request';
8
+ export { default as PortalRequests } from './PortalRequests';
8
9
  export { HttpRequester } from './requesters';
@@ -69,5 +69,20 @@ class HttpRequester {
69
69
  return response;
70
70
  });
71
71
  }
72
+ patch(path, options) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const requestOptions = {
75
+ method: 'PATCH',
76
+ url: `${this.baseUrl}${path}`,
77
+ };
78
+ requestOptions.headers = this.buildHeaders((options === null || options === void 0 ? void 0 : options.headers) ? options.headers : {});
79
+ if (options && options.body) {
80
+ requestOptions.body = options.body;
81
+ }
82
+ const request = new HttpRequest(requestOptions);
83
+ const response = (yield request.send());
84
+ return response;
85
+ });
86
+ }
72
87
  }
73
88
  export default HttpRequester;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "3.0.6",
3
+ "version": "4.1.0-beta",
4
4
  "main": "lib/commonjs/index",
5
5
  "module": "lib/esm/index",
6
6
  "source": "src/index",
@@ -26,5 +26,5 @@
26
26
  "ts-jest": "^29.0.3",
27
27
  "typescript": "^4.8.4"
28
28
  },
29
- "gitHead": "884d505870ff81f79fde92abdcea508619eaf86e"
29
+ "gitHead": "87317816c3fb6475dc655746b2023fa84e0417d7"
30
30
  }
@@ -0,0 +1,125 @@
1
+ import { type HttpOptions, type HttpRequestOptions } from '../../types'
2
+ import { HttpRequest } from '../index'
3
+
4
+ class PortalRequests {
5
+ public buildHeaders(headers: Record<string, any> = {}): Record<string, any> {
6
+ return {
7
+ 'Content-Type': 'application/json',
8
+ ...headers,
9
+ }
10
+ }
11
+
12
+ public async delete<T>(
13
+ baseUrl: string,
14
+ path: string,
15
+ options?: HttpOptions,
16
+ ): Promise<T> {
17
+ const requestOptions = {
18
+ method: 'DELETE',
19
+ url: `${baseUrl}${path}`,
20
+ } as HttpRequestOptions
21
+
22
+ requestOptions.headers = this.buildHeaders(
23
+ options && options.headers ? options.headers : {},
24
+ )
25
+
26
+ const request = new HttpRequest(requestOptions)
27
+ const response = (await request.send()) as T
28
+
29
+ return response
30
+ }
31
+
32
+ public async get<T>(
33
+ baseUrl: string,
34
+ path: string,
35
+ options?: HttpOptions,
36
+ ): Promise<T> {
37
+ const requestOptions = {
38
+ method: 'GET',
39
+ url: `${baseUrl}${path}`,
40
+ } as HttpRequestOptions
41
+
42
+ requestOptions.headers = this.buildHeaders(
43
+ options && options.headers ? options.headers : {},
44
+ )
45
+
46
+ const request = new HttpRequest(requestOptions)
47
+ const response = (await request.send()) as T
48
+
49
+ return response
50
+ }
51
+
52
+ public async post<T>(
53
+ baseUrl: string,
54
+ path: string,
55
+ options?: HttpOptions,
56
+ ): Promise<T> {
57
+ const requestOptions = {
58
+ method: 'POST',
59
+ url: `${baseUrl}${path}`,
60
+ } as HttpRequestOptions
61
+
62
+ requestOptions.headers = this.buildHeaders(
63
+ options && options.headers ? options.headers : {},
64
+ )
65
+
66
+ if (options && options.body) {
67
+ requestOptions.body = options.body
68
+ }
69
+
70
+ const request = new HttpRequest(requestOptions)
71
+ const response = (await request.send()) as T
72
+
73
+ return response
74
+ }
75
+
76
+ public async put<T>(
77
+ baseUrl: string,
78
+ path: string,
79
+ options: HttpOptions,
80
+ ): Promise<T> {
81
+ const requestOptions = {
82
+ method: 'PUT',
83
+ url: `${baseUrl}${path}`,
84
+ } as HttpRequestOptions
85
+
86
+ requestOptions.headers = this.buildHeaders(
87
+ options && options.headers ? options.headers : {},
88
+ )
89
+
90
+ if (options && options.body) {
91
+ requestOptions.body = options.body
92
+ }
93
+
94
+ const request = new HttpRequest(requestOptions)
95
+ const response = (await request.send()) as T
96
+
97
+ return response
98
+ }
99
+
100
+ public async patch<T>(
101
+ baseUrl: string,
102
+ path: string,
103
+ options: HttpOptions,
104
+ ): Promise<T> {
105
+ const requestOptions = {
106
+ method: 'PATCH',
107
+ url: `${baseUrl}${path}`,
108
+ } as HttpRequestOptions
109
+
110
+ requestOptions.headers = this.buildHeaders(
111
+ options && options.headers ? options.headers : {},
112
+ )
113
+
114
+ if (options && options.body) {
115
+ requestOptions.body = options.body
116
+ }
117
+
118
+ const request = new HttpRequest(requestOptions)
119
+ const response = (await request.send()) as T
120
+
121
+ return response
122
+ }
123
+ }
124
+
125
+ export default PortalRequests
@@ -1,22 +1,27 @@
1
1
  import PortalConnect from '@portal-hq/connect'
2
+ import { BackupMethods } from '@portal-hq/core'
2
3
 
3
4
  import type {
5
+ AddressesByNamespace,
4
6
  BackupSharePairMetadata,
5
7
  Balance,
6
- ClientWithCustodianData,
8
+ ClientResponse,
7
9
  Dapp,
8
- DkgData,
10
+ GenerateResponse,
9
11
  GetTransactionsOrder,
10
12
  NFT,
11
13
  Network,
14
+ PortalKeychainMetadata,
12
15
  ProgressCallback,
13
16
  QuoteArgs,
14
17
  QuoteResponse,
18
+ Shares,
15
19
  SigningSharePairMetadata,
16
20
  SimulateTransactionParam,
17
21
  SimulatedTransaction,
18
22
  Transaction,
19
23
  } from '../../types'
24
+ import PortalRequests from '../PortalRequests'
20
25
  import { HttpRequester } from '../requesters'
21
26
 
22
27
  export type EventHandler = (data: any) => void
@@ -48,25 +53,44 @@ export interface IPortalApi {
48
53
  apiUrl: string
49
54
  requests: HttpRequester
50
55
 
51
- getBackupShareMetadata(): Promise<BackupSharePairMetadata[]>
52
- getBalances(): Promise<Balance[]>
53
- getClient(): Promise<ClientWithCustodianData>
56
+ getBackupSharesMetadata(chainId?: string): Promise<BackupSharePairMetadata[]>
57
+ getBalances(chainId?: string): Promise<Balance[]>
58
+ getClient(): Promise<ClientResponse>
59
+ getClientCipherText(backupSharePairId: string): Promise<string>
54
60
  getEnabledDapps(): Promise<Dapp[]>
55
- getNFTs(): Promise<NFT[]>
61
+ getNFTs(chainId?: string): Promise<NFT[]>
56
62
  getNetworks(): Promise<Network[]>
57
- getQuote(apiKey: string, args: QuoteArgs): Promise<QuoteResponse>
58
- getSigningShareMetadata(): Promise<SigningSharePairMetadata[]>
59
- getSources(apiKey: string): Promise<Record<string, string>>
63
+ getQuote(
64
+ apiKey: string,
65
+ args: QuoteArgs,
66
+ chainId?: string,
67
+ ): Promise<QuoteResponse>
68
+ getSigningSharesMetadata(
69
+ chainId?: string,
70
+ ): Promise<SigningSharePairMetadata[]>
71
+ getSources(apiKey: string, chainId?: string): Promise<Record<string, string>>
60
72
  getTransactions(
73
+ chainId?: string,
61
74
  limit?: number,
62
75
  offset?: number,
63
76
  order?: GetTransactionsOrder,
64
- chainId?: number,
65
77
  ): Promise<Transaction[]>
66
78
  identify(traits?: Record<string, any>): Promise<{ success: boolean }>
79
+ prepareClientEject(
80
+ walletId: string,
81
+ backupMethod: BackupMethods,
82
+ ): Promise<string>
67
83
  simulateTransaction(
68
84
  params: SimulateTransactionParam,
85
+ chainId?: string,
69
86
  ): Promise<SimulatedTransaction>
87
+ storeClientCipherText(
88
+ backupSharePairId: string,
89
+ cipherText: string,
90
+ ): Promise<boolean>
91
+ storedClientSigningShares(signingSharePairIds: string[]): Promise<void>
92
+ storedClientBackupShares(backupSharePairIds: string[]): Promise<void>
93
+ storedClientBackupSharesKey(backupSharePairIds: string[]): Promise<void>
70
94
  storedClientBackupShare(
71
95
  success: boolean,
72
96
  backupMethod:
@@ -87,7 +111,7 @@ export interface IPortalApi {
87
111
  | 'PASSWORD'
88
112
  | 'UNKNOWN',
89
113
  ): Promise<void>
90
- storedClientSigningShare(signingSharePairId: string): Promise<void>
114
+ storedClientSigningShares(signingSharePairIds: string[]): Promise<void>
91
115
  track(
92
116
  event: string,
93
117
  properties?: Record<string, any>,
@@ -109,30 +133,42 @@ export interface IPortalConnect {
109
133
  export interface IPortalProvider {
110
134
  apiKey: string
111
135
  autoApprove: boolean
112
- chainId: number
136
+ chainId?: string
113
137
  log: Console
114
- gateway: HttpRequester
115
-
138
+ gateway: PortalRequests
116
139
  address: Promise<string | undefined>
117
- gatewayUrl: string
140
+ addresses: Promise<AddressesByNamespace | undefined>
118
141
 
119
142
  emit(event: string, data: any): IPortalProvider
120
- getGatewayUrl(): string
143
+ getGatewayUrl(chainId: string): string
121
144
  on(event: string, callback: EventHandler): IPortalProvider
122
145
  once(event: string, callback: EventHandler): IPortalProvider
123
146
  removeEventListener(event: string, listenerToRemove?: EventHandler): void
124
147
  request(args: RequestArguments): Promise<any>
125
- setChainId(chainId: number, connect?: PortalConnect): Promise<IPortalProvider>
148
+ setChainId(
149
+ chainId: string | number,
150
+ connect?: PortalConnect | undefined,
151
+ ): Promise<IPortalProvider>
126
152
  }
127
153
 
128
154
  export abstract class KeychainAdapter {
129
155
  public api?: IPortalApi
130
-
156
+ public metadata?: PortalKeychainMetadata
157
+ loadMetadata(): Promise<void> {
158
+ throw new Error(
159
+ '[Portal] KeychainAdapter method loadMetadata cannot be called directly. Please extend KeychainAdapter.',
160
+ )
161
+ }
131
162
  deleteAddress(): Promise<boolean> {
132
163
  throw new Error(
133
164
  '[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.',
134
165
  )
135
166
  }
167
+ deleteShares(): Promise<boolean> {
168
+ throw new Error(
169
+ '[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.',
170
+ )
171
+ }
136
172
  deleteDkgResult(): Promise<boolean> {
137
173
  throw new Error(
138
174
  '[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.',
@@ -143,14 +179,38 @@ export abstract class KeychainAdapter {
143
179
  `[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
144
180
  )
145
181
  }
146
- getDkgResult(
147
- isSim?: boolean,
182
+ getDkgResult(isSim?: boolean): Promise<string> {
183
+ throw new Error(
184
+ `[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
185
+ )
186
+ }
187
+ getShares(
148
188
  _progress: ProgressCallback = () => {
149
189
  // Noop
150
190
  },
151
- ): Promise<string> {
191
+ ): Promise<Shares> {
152
192
  throw new Error(
153
- `[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
193
+ '[Portal] KeychainAdapter method getShares cannot be called directly. Please extend KeychainAdapter.',
194
+ )
195
+ }
196
+ getSigningShare(
197
+ curve: string,
198
+ _progress: ProgressCallback = () => {
199
+ // Noop
200
+ },
201
+ ): Promise<GenerateResponse> {
202
+ throw new Error(
203
+ `[Portal] KeychainAdapter method getSigningShare(${curve}) cannot be called directly. Please extend KeychainAdapter.`,
204
+ )
205
+ }
206
+ getAddresses(): Promise<AddressesByNamespace> {
207
+ throw new Error(
208
+ '[Portal] KeychainAdapter method getAddresses cannot be called directly. Please extend KeychainAdapter.',
209
+ )
210
+ }
211
+ getEip155Address(): Promise<string> {
212
+ throw new Error(
213
+ '[Portal] KeychainAdapter method getEip155Address cannot be called directly. Please extend KeychainAdapter.',
154
214
  )
155
215
  }
156
216
  storeAddress(address: string, isSim?: boolean): Promise<void> {
@@ -158,15 +218,14 @@ export abstract class KeychainAdapter {
158
218
  `[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
159
219
  )
160
220
  }
161
- storeDkgResult(
162
- result: DkgData,
163
- isSim?: boolean,
221
+ storeShares(
222
+ result: Shares,
164
223
  _progress: ProgressCallback = () => {
165
224
  // Noop
166
225
  },
167
226
  ): Promise<void> {
168
227
  throw new Error(
169
- `[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
228
+ `[Portal] KeychainAdapter method storeDkgResult(${result}) cannot be called directly. Please extend KeychainAdapter.`,
170
229
  )
171
230
  }
172
231
  validateOperations(): Promise<boolean> {
@@ -9,6 +9,7 @@ enum Events {
9
9
  GetBackupShareMetadata = 'Get Backup Share Metadata',
10
10
  GetBalances = 'Get Balances',
11
11
  GetClient = 'Get Client',
12
+ GetClientCipherText = 'Get Client Cipher Text',
12
13
  GetEnabledDapps = 'Get Enabled Dapps',
13
14
  GetNFTs = 'Get NFTs',
14
15
  GetNetworks = 'Get Networks',
@@ -16,7 +17,9 @@ enum Events {
16
17
  GetSigningShareMetadata = 'Get Signing Share Metadata',
17
18
  GetSources = 'Get Sources',
18
19
  GetTransactions = 'Get Transactions',
20
+ PrepareClientEject = 'Prepare Client Eject',
19
21
  SimulateTransaction = 'Simulate Transaction',
22
+ StoreClientCipherText = 'Store Client Cipher Text',
20
23
  StoredClientBackupShare = 'Stored Client Backup Share',
21
24
  StoredClientBackupShareKey = 'Stored Client Backup Share Key',
22
25
  StoredClientSigningShare = 'Stored Client Signing Share',
@@ -27,7 +27,7 @@ class HttpRequest {
27
27
  this.prepareRequest()
28
28
 
29
29
  // Sends the request with a formatted request body
30
- if (['POST', 'PUT'].includes(this.method)) {
30
+ if (['POST', 'PUT', 'PATCH'].includes(this.method)) {
31
31
  const body = this.prepareBody()
32
32
  this.request.send(body)
33
33
  } else {
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export { numberToHexString, parseRequest } from './eth-requests'
40
40
 
41
41
  export { default as HttpRequest } from './http-request'
42
42
 
43
+ export { default as PortalRequests } from './PortalRequests'
43
44
  export { HttpRequester } from './requesters'
44
45
 
45
46
  export {
@@ -65,4 +66,5 @@ export {
65
66
  type SigningRequestArguments,
66
67
  type SigningResponse,
67
68
  type Transaction,
69
+ type Shares,
68
70
  } from '../types'
@@ -90,6 +90,26 @@ class HttpRequester {
90
90
 
91
91
  return response
92
92
  }
93
+
94
+ public async patch<T>(path: string, options: HttpOptions): Promise<T> {
95
+ const requestOptions = {
96
+ method: 'PATCH',
97
+ url: `${this.baseUrl}${path}`,
98
+ } as HttpRequestOptions
99
+
100
+ requestOptions.headers = this.buildHeaders(
101
+ options?.headers ? options.headers : {},
102
+ )
103
+
104
+ if (options && options.body) {
105
+ requestOptions.body = options.body
106
+ }
107
+
108
+ const request = new HttpRequest(requestOptions)
109
+ const response = (await request.send()) as T
110
+
111
+ return response
112
+ }
93
113
  }
94
114
 
95
115
  export default HttpRequester
package/types.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { BackupMethods } from '@portal-hq/core'
1
+ import {
2
+ BackupMethods,
3
+ PortalCurve,
4
+ PortalNamespace,
5
+ PortalSharePairStatus,
6
+ } from '@portal-hq/core'
2
7
 
3
8
  import { MpcStatuses } from './src/definitions'
4
9
 
@@ -8,7 +13,12 @@ export type OutgoingRequestData = MessageData | SignableTransactionData
8
13
 
9
14
  export type ProgressCallback = (status: MpcStatus) => void | Promise<void>
10
15
 
11
- export type ValidHttpRequestMethods = 'DELETE' | 'GET' | 'POST' | 'PUT'
16
+ export type ValidHttpRequestMethods =
17
+ | 'DELETE'
18
+ | 'GET'
19
+ | 'POST'
20
+ | 'PUT'
21
+ | 'PATCH'
12
22
 
13
23
  export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901
14
24
 
@@ -17,6 +27,64 @@ export interface Bk {
17
27
  Rank: number
18
28
  }
19
29
 
30
+ interface ClientResponse {
31
+ id: string
32
+ custodian: ClientResponseCustodian
33
+ createdAt: string
34
+ environment?: ClientResponseEnvironment
35
+ ejectedAt?: string
36
+ isAccountAbstracted: boolean
37
+ metadata: ClientResponseMetadata
38
+ wallets: ClientResponseWallet[]
39
+ }
40
+
41
+ interface ClientResponseBackupSharePair {
42
+ backupMethod: BackupMethods
43
+ createdAt: string
44
+ id: string
45
+ status: PortalSharePairStatus
46
+ }
47
+
48
+ interface ClientResponseCustodian {
49
+ id: string
50
+ name: string
51
+ }
52
+
53
+ interface ClientResponseEnvironment {
54
+ id: string
55
+ backupWithPortalEnabled?: boolean
56
+ name: string
57
+ }
58
+
59
+ interface ClientResponseMetadata {
60
+ namespaces: ClientResponseMetadataNamespaces
61
+ }
62
+
63
+ interface ClientResponseMetadataNamespaces {
64
+ eip155?: ClientResponseNamespaceMetadataItem
65
+ solana?: ClientResponseNamespaceMetadataItem
66
+ }
67
+
68
+ interface ClientResponseNamespaceMetadataItem {
69
+ address: string
70
+ curve: PortalCurve
71
+ }
72
+
73
+ interface ClientResponseSharePair {
74
+ id: string
75
+ createdAt: string
76
+ status: PortalSharePairStatus
77
+ }
78
+
79
+ interface ClientResponseWallet {
80
+ id: string
81
+ createdAt: string
82
+ backupSharePairs: ClientResponseBackupSharePair[]
83
+ curve: PortalCurve
84
+ publicKey: string
85
+ signingSharePairs: ClientResponseSharePair[]
86
+ }
87
+
20
88
  export interface ClientWithCustodianData {
21
89
  id: string
22
90
  address: string
@@ -58,6 +126,63 @@ export interface DappImage {
58
126
  data: string
59
127
  }
60
128
 
129
+ export interface GenerateResponse {
130
+ id: string
131
+ share: DkgData
132
+ }
133
+
134
+ export interface Shares {
135
+ ed25519?: GenerateResponse
136
+ secp256k1: GenerateResponse
137
+ }
138
+
139
+ export interface AddressesByNamespace {
140
+ eip155: string
141
+ solana?: string
142
+ }
143
+
144
+ export interface WalletsByCurve {
145
+ [key in PortalCurve]: PortalKeychainClientMetadataWallet
146
+ }
147
+
148
+ export interface PortalKeychainClientMetadata {
149
+ id: string
150
+ addresses?: AddressesByNamespace
151
+ custodian: ClientResponseCustodian
152
+ wallets?: WalletsByCurve
153
+ }
154
+
155
+ export interface PortalKeychainClientMetadataWallet {
156
+ id: string
157
+ curve: PortalCurve
158
+ publicKey: string
159
+ backupShares: PortalKeychainClientMetadataWalletBackupShare[]
160
+ signingShares: PortalKeychainClientMetadataWalletShare[]
161
+ }
162
+
163
+ export interface PortalKeychainClientMetadataWalletBackupShare {
164
+ backupMethod: BackupMethods
165
+ createdAt: string
166
+ id: string
167
+ status: PortalSharePairStatus
168
+ }
169
+
170
+ export interface PortalKeychainClientMetadataWalletShare {
171
+ createdAt: string
172
+ id: string
173
+ status: PortalSharePairStatus
174
+ }
175
+
176
+ export type PortalKeychainClientShares = GenerateResponse
177
+
178
+ export interface CurveByNamespace {
179
+ [namespace: string]: PortalCurve
180
+ }
181
+
182
+ export interface PortalKeychainMetadata {
183
+ namespaces: CurveByNamespace
184
+ }
185
+
61
186
  export interface DkgData {
62
187
  allY: { [key: MpcMember]: Pubkey }
63
188
  bks: { [key: MpcMember]: Bk }
@@ -68,6 +193,7 @@ export interface DkgData {
68
193
  q: string
69
194
  share: string
70
195
  signingSharePairId?: string
196
+ backupSharePairId?: string
71
197
  ssid: string
72
198
  }
73
199
 
@@ -175,9 +301,11 @@ export interface SignableTransactionData {
175
301
  }
176
302
 
177
303
  export interface SigningRequestArguments {
178
- readonly chainId?: number
304
+ readonly chainId: string
305
+ readonly curve: PortalCurve
179
306
  readonly method: string
180
307
  readonly params?: unknown[] | SigningRequestParams
308
+ readonly isRaw?: boolean
181
309
  }
182
310
 
183
311
  export interface SigningResponse {