@portal-hq/utils 0.2.8 → 0.2.10

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 (47) hide show
  1. package/package.json +1 -1
  2. package/src/currency/countries/currency-codes.ts +0 -1
  3. package/src/definitions/index.ts +41 -9
  4. package/src/errors/provider-rpc-error.ts +1 -1
  5. package/src/eth-requests/index.ts +14 -9
  6. package/src/index.ts +2 -0
  7. package/types.d.ts +12 -0
  8. package/lib/commonjs/currency/countries/country-codes.js +0 -250
  9. package/lib/commonjs/currency/countries/currency-codes.js +0 -248
  10. package/lib/commonjs/currency/countries/index.js +0 -10
  11. package/lib/commonjs/currency/index.js +0 -29
  12. package/lib/commonjs/definitions/index.js +0 -9
  13. package/lib/commonjs/errors/http-error.js +0 -10
  14. package/lib/commonjs/errors/index.js +0 -23
  15. package/lib/commonjs/errors/invalid-api-key-error.js +0 -10
  16. package/lib/commonjs/errors/invalid-chain-id-error.js +0 -10
  17. package/lib/commonjs/errors/invalid-gateway-config-error.js +0 -10
  18. package/lib/commonjs/errors/invalid-rpc-config-error.js +0 -10
  19. package/lib/commonjs/errors/missing-option-error.js +0 -10
  20. package/lib/commonjs/errors/mpc-signing-error.js +0 -10
  21. package/lib/commonjs/errors/no-address-error.js +0 -10
  22. package/lib/commonjs/errors/provider-rpc-error.js +0 -52
  23. package/lib/commonjs/eth-requests/index.js +0 -87
  24. package/lib/commonjs/http-request/index.js +0 -72
  25. package/lib/commonjs/index.js +0 -28
  26. package/lib/commonjs/requesters/http.js +0 -52
  27. package/lib/commonjs/requesters/index.js +0 -8
  28. package/lib/esm/errors/invalid-rpc-config-error.js +0 -26
  29. /package/lib/{esm/currency → currency}/countries/country-codes.js +0 -0
  30. /package/lib/{esm/currency → currency}/countries/currency-codes.js +0 -0
  31. /package/lib/{esm/currency → currency}/countries/index.js +0 -0
  32. /package/lib/{esm/currency → currency}/index.js +0 -0
  33. /package/lib/{esm/definitions → definitions}/index.js +0 -0
  34. /package/lib/{esm/errors → errors}/http-error.js +0 -0
  35. /package/lib/{esm/errors → errors}/index.js +0 -0
  36. /package/lib/{esm/errors → errors}/invalid-api-key-error.js +0 -0
  37. /package/lib/{esm/errors → errors}/invalid-chain-id-error.js +0 -0
  38. /package/lib/{esm/errors → errors}/invalid-gateway-config-error.js +0 -0
  39. /package/lib/{esm/errors → errors}/missing-option-error.js +0 -0
  40. /package/lib/{esm/errors → errors}/mpc-signing-error.js +0 -0
  41. /package/lib/{esm/errors → errors}/no-address-error.js +0 -0
  42. /package/lib/{esm/errors → errors}/provider-rpc-error.js +0 -0
  43. /package/lib/{esm/eth-requests → eth-requests}/index.js +0 -0
  44. /package/lib/{esm/http-request → http-request}/index.js +0 -0
  45. /package/lib/{esm/index.js → index.js} +0 -0
  46. /package/lib/{esm/requesters → requesters}/http.js +0 -0
  47. /package/lib/{esm/requesters → requesters}/index.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "main": "lib/commonjs/index",
5
5
  "module": "lib/esm/index",
6
6
  "source": "src/index",
@@ -163,7 +163,6 @@ const currencyCodes: Record<string, string> = {
163
163
  Oman: 'OMR',
164
164
  Pakistan: 'PKR',
165
165
  Palau: 'USD',
166
- Palestine: null,
167
166
  Panama: 'PAB',
168
167
  'Papua New Guinea': 'PGK',
169
168
  Paraguay: 'PYG',
@@ -1,12 +1,36 @@
1
1
  import { ClientWithCustodianData, Dapp, DkgData, Network } from '../../types'
2
2
 
3
3
  export abstract class KeychainAdapter {
4
- deleteAddress: () => Promise<boolean>
5
- deleteDkgResult: () => Promise<boolean>
6
- getAddress: (isSim?: boolean) => Promise<string>
7
- getDkgResult: (isSim?: boolean) => Promise<string>
8
- storeAddress: (address: string, isSim?: boolean) => Promise<void>
9
- storeDkgResult: (result: DkgData, isSim?: boolean) => Promise<void>
4
+ deleteAddress(): Promise<boolean> {
5
+ throw new Error(
6
+ '[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.',
7
+ )
8
+ }
9
+ deleteDkgResult(): Promise<boolean> {
10
+ throw new Error(
11
+ '[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.',
12
+ )
13
+ }
14
+ getAddress(isSim?: boolean): Promise<string> {
15
+ throw new Error(
16
+ `[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
17
+ )
18
+ }
19
+ getDkgResult(isSim?: boolean): Promise<string> {
20
+ throw new Error(
21
+ `[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
22
+ )
23
+ }
24
+ storeAddress(address: string, isSim?: boolean): Promise<void> {
25
+ throw new Error(
26
+ `[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
27
+ )
28
+ }
29
+ storeDkgResult(result: DkgData, isSim?: boolean): Promise<void> {
30
+ throw new Error(
31
+ `[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
32
+ )
33
+ }
10
34
  }
11
35
 
12
36
  export declare class PortalApi {
@@ -16,8 +40,16 @@ export declare class PortalApi {
16
40
  }
17
41
 
18
42
  export abstract class Storage {
19
- public api: PortalApi
43
+ public api?: PortalApi
20
44
 
21
- read: () => Promise<string>
22
- write: (privateKey: string) => Promise<string>
45
+ read(): Promise<string> {
46
+ throw new Error(
47
+ '[Portal] Storage method read cannot be called directly. Please extend Storage.',
48
+ )
49
+ }
50
+ write(privateKey: string): Promise<string> {
51
+ throw new Error(
52
+ `[Portal] Storage method write(${privateKey}) cannot be called directly. Please extend Storage.`,
53
+ )
54
+ }
23
55
  }
@@ -43,7 +43,7 @@ class ProviderRpcError extends Error {
43
43
 
44
44
  constructor({ code, data }: RpcErrorOptions) {
45
45
  const log = console
46
- const definition = providerErrors[code]
46
+ const definition = providerErrors[code as ValidRpcErrorCodes]
47
47
 
48
48
  if (!definition) {
49
49
  log.warn(
@@ -74,7 +74,6 @@ export const parseRequest = async (
74
74
  console.log(`Request: `, JSON.stringify({ method, params }))
75
75
 
76
76
  const txParam0 = Array.isArray(params) ? params[0] : params
77
- const txParam1 = Array.isArray(params) ? params[1] : null
78
77
 
79
78
  switch (method) {
80
79
  case 'eth_sendTransaction':
@@ -90,20 +89,26 @@ export const parseRequest = async (
90
89
  valueConverted: await convert(value),
91
90
  } as SignableTransactionData
92
91
 
93
- console.log(`requestData: `, requestData)
94
- break
92
+ return {
93
+ method,
94
+ data: requestData,
95
+ }
95
96
  case 'eth_sign':
96
97
  case 'personal_sign':
97
98
  requestData = {
98
99
  message: hexStringToString(txParam0),
99
100
  } as MessageData
100
- break
101
+ return {
102
+ method,
103
+ data: requestData,
104
+ }
101
105
  default:
106
+ return {
107
+ method,
108
+ data: {
109
+ message: 'NO_DATA_PROVIDED',
110
+ },
111
+ }
102
112
  break
103
113
  }
104
-
105
- return {
106
- method,
107
- data: requestData,
108
- }
109
114
  }
package/src/index.ts CHANGED
@@ -34,4 +34,6 @@ export {
34
34
  type OutgoingRequest,
35
35
  type OutgoingRequestData,
36
36
  type SignableTransactionData,
37
+ type SigningRequestArguments,
38
+ type SigningResponse,
37
39
  } from '../types'
package/types.d.ts CHANGED
@@ -111,3 +111,15 @@ export interface SignableTransactionData {
111
111
  value: number
112
112
  valueConverted: number
113
113
  }
114
+
115
+ export interface SigningRequestArguments {
116
+ readonly chainId?: number
117
+ readonly method: string
118
+ readonly params?: unknown[] | SigningRequestParams
119
+ }
120
+
121
+ export interface SigningResponse {
122
+ method: string
123
+ params?: unknown[] | SigningRequestParams
124
+ signature?: any
125
+ }
@@ -1,250 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const countryCodes = {
4
- AD: 'Andorra',
5
- AE: 'United Arab Emirates',
6
- AF: 'Afghanistan',
7
- AG: 'Antigua and Barbuda',
8
- AI: 'Anguilla',
9
- AL: 'Albania',
10
- AM: 'Armenia',
11
- AN: 'Netherlands Antilles',
12
- AO: 'Angola',
13
- AQ: 'Antarctica',
14
- AR: 'Argentina',
15
- AS: 'American Samoa',
16
- AT: 'Austria',
17
- AU: 'Australia',
18
- AW: 'Aruba',
19
- AZ: 'Azerbaijan',
20
- BA: 'Bosnia and Herzegovina',
21
- BB: 'Barbados',
22
- BD: 'Bangladesh',
23
- BE: 'Belgium',
24
- BF: 'Burkina Faso',
25
- BG: 'Bulgaria',
26
- BH: 'Bahrain',
27
- BI: 'Burundi',
28
- BJ: 'Benin',
29
- BM: 'Bermuda',
30
- BN: 'Brunei',
31
- BO: 'Bolivia',
32
- BR: 'Brazil',
33
- BS: 'Bahamas',
34
- BT: 'Bhutan',
35
- BV: 'Bouvet Island',
36
- BW: 'Botswana',
37
- BY: 'Belarus',
38
- BZ: 'Belize',
39
- CA: 'Canada',
40
- CC: 'Cocos (Keeling) Islands',
41
- CD: 'The Democratic Republic of Congo',
42
- CF: 'Central African Republic',
43
- CG: 'Congo',
44
- CH: 'Switzerland',
45
- CI: 'Ivory Coast',
46
- CK: 'Cook Islands',
47
- CL: 'Chile',
48
- CM: 'Cameroon',
49
- CN: 'China',
50
- CO: 'Colombia',
51
- CR: 'Costa Rica',
52
- CU: 'Cuba',
53
- CV: 'Cape Verde',
54
- CX: 'Christmas Island',
55
- CY: 'Cyprus',
56
- CZ: 'Czech Republic',
57
- DE: 'Germany',
58
- DJ: 'Djibouti',
59
- DK: 'Denmark',
60
- DM: 'Dominica',
61
- DO: 'Dominican Republic',
62
- DZ: 'Algeria',
63
- EC: 'Ecuador',
64
- EE: 'Estonia',
65
- EG: 'Egypt',
66
- EH: 'Western Sahara',
67
- ER: 'Eritrea',
68
- ES: 'Spain',
69
- ET: 'Ethiopia',
70
- FI: 'Finland',
71
- FJ: 'Fiji Islands',
72
- FK: 'Falkland Islands',
73
- FM: 'Micronesia, Federated States of',
74
- FO: 'Faroe Islands',
75
- FR: 'France',
76
- GA: 'Gabon',
77
- GB: 'Northern Ireland',
78
- GD: 'Grenada',
79
- GE: 'Georgia',
80
- GF: 'French Guiana',
81
- GG: 'Guernsey',
82
- GH: 'Ghana',
83
- GI: 'Gibraltar',
84
- GL: 'Greenland',
85
- GM: 'Gambia',
86
- GN: 'Guinea',
87
- GP: 'Guadeloupe',
88
- GQ: 'Equatorial Guinea',
89
- GR: 'Greece',
90
- GS: 'South Georgia and the South Sandwich Islands',
91
- GT: 'Guatemala',
92
- GU: 'Guam',
93
- GW: 'Guinea-Bissau',
94
- GY: 'Guyana',
95
- HK: 'Hong Kong',
96
- HM: 'Heard Island and McDonald Islands',
97
- HN: 'Honduras',
98
- HR: 'Croatia',
99
- HT: 'Haiti',
100
- HU: 'Hungary',
101
- ID: 'Indonesia',
102
- IE: 'Ireland',
103
- IL: 'Israel',
104
- IM: 'Isle of Man',
105
- IN: 'India',
106
- IO: 'British Indian Ocean Territory',
107
- IQ: 'Iraq',
108
- IR: 'Iran',
109
- IS: 'Iceland',
110
- IT: 'Italy',
111
- JE: 'Jersey',
112
- JM: 'Jamaica',
113
- JO: 'Jordan',
114
- JP: 'Japan',
115
- KE: 'Kenya',
116
- KG: 'Kyrgyzstan',
117
- KH: 'Cambodia',
118
- KI: 'Kiribati',
119
- KM: 'Comoros',
120
- KN: 'Saint Kitts and Nevis',
121
- KP: 'North Korea',
122
- KR: 'South Korea',
123
- KW: 'Kuwait',
124
- KY: 'Cayman Islands',
125
- KZ: 'Kazakhstan',
126
- LA: 'Laos',
127
- LB: 'Lebanon',
128
- LC: 'Saint Lucia',
129
- LI: 'Liechtenstein',
130
- LK: 'Sri Lanka',
131
- LR: 'Liberia',
132
- LS: 'Lesotho',
133
- LT: 'Lithuania',
134
- LU: 'Luxembourg',
135
- LV: 'Latvia',
136
- LY: 'Libyan Arab Jamahiriya',
137
- MA: 'Morocco',
138
- MC: 'Monaco',
139
- MD: 'Moldova',
140
- ME: 'Montenegro',
141
- MG: 'Madagascar',
142
- MH: 'Marshall Islands',
143
- MK: 'North Macedonia',
144
- ML: 'Mali',
145
- MM: 'Myanmar',
146
- MN: 'Mongolia',
147
- MO: 'Macao',
148
- MP: 'Northern Mariana Islands',
149
- MQ: 'Martinique',
150
- MR: 'Mauritania',
151
- MS: 'Montserrat',
152
- MT: 'Malta',
153
- MU: 'Mauritius',
154
- MV: 'Maldives',
155
- MW: 'Malawi',
156
- MX: 'Mexico',
157
- MY: 'Malaysia',
158
- MZ: 'Mozambique',
159
- NA: 'Namibia',
160
- NC: 'New Caledonia',
161
- NE: 'Niger',
162
- NF: 'Norfolk Island',
163
- NG: 'Nigeria',
164
- NI: 'Nicaragua',
165
- NL: 'Netherlands',
166
- NO: 'Norway',
167
- NP: 'Nepal',
168
- NR: 'Nauru',
169
- NU: 'Niue',
170
- NZ: 'New Zealand',
171
- OM: 'Oman',
172
- PA: 'Panama',
173
- PE: 'Peru',
174
- PF: 'French Polynesia',
175
- PG: 'Papua New Guinea',
176
- PH: 'Philippines',
177
- PK: 'Pakistan',
178
- PL: 'Poland',
179
- PM: 'Saint Pierre and Miquelon',
180
- PN: 'Pitcairn',
181
- PR: 'Puerto Rico',
182
- PS: 'Palestine',
183
- PT: 'Portugal',
184
- PW: 'Palau',
185
- PY: 'Paraguay',
186
- QA: 'Qatar',
187
- RE: 'Reunion',
188
- RO: 'Romania',
189
- RS: 'Serbia',
190
- RU: 'Russian Federation',
191
- RW: 'Rwanda',
192
- SA: 'Saudi Arabia',
193
- SB: 'Solomon Islands',
194
- SC: 'Seychelles',
195
- SD: 'Sudan',
196
- SE: 'Sweden',
197
- SG: 'Singapore',
198
- SH: 'Saint Helena',
199
- SI: 'Slovenia',
200
- SJ: 'Svalbard and Jan Mayen',
201
- SK: 'Slovakia',
202
- SL: 'Sierra Leone',
203
- SM: 'San Marino',
204
- SN: 'Senegal',
205
- SO: 'Somalia',
206
- SR: 'Suriname',
207
- SS: 'South Sudan',
208
- ST: 'Sao Tome and Principe',
209
- SV: 'El Salvador',
210
- SY: 'Syria',
211
- SZ: 'Swaziland',
212
- TC: 'Turks and Caicos Islands',
213
- TD: 'Chad',
214
- TF: 'French Southern territories',
215
- TG: 'Togo',
216
- TH: 'Thailand',
217
- TJ: 'Tajikistan',
218
- TK: 'Tokelau',
219
- TL: 'Timor-Leste',
220
- TM: 'Turkmenistan',
221
- TN: 'Tunisia',
222
- TO: 'Tonga',
223
- TP: 'East Timor',
224
- TR: 'Turkey',
225
- TT: 'Trinidad and Tobago',
226
- TV: 'Tuvalu',
227
- TZ: 'Tanzania',
228
- UA: 'Ukraine',
229
- UG: 'Uganda',
230
- UK: 'United Kingdom',
231
- UM: 'United States Minor Outlying Islands',
232
- US: 'United States',
233
- UY: 'Uruguay',
234
- UZ: 'Uzbekistan',
235
- VA: 'Holy See (Vatican City State)',
236
- VC: 'Saint Vincent and the Grenadines',
237
- VE: 'Venezuela',
238
- VG: 'Virgin Islands, British',
239
- VI: 'Virgin Islands, U.S.',
240
- VN: 'Vietnam',
241
- VU: 'Vanuatu',
242
- WF: 'Wallis and Futuna',
243
- WS: 'Samoa',
244
- YE: 'Yemen',
245
- YT: 'Mayotte',
246
- ZA: 'South Africa',
247
- ZM: 'Zambia',
248
- ZW: 'Zimbabwe',
249
- };
250
- exports.default = countryCodes;
@@ -1,248 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const currencyCodes = {
4
- Afghanistan: 'AFN',
5
- Albania: 'ALL',
6
- Algeria: 'DZD',
7
- 'American Samoa': 'USD',
8
- Andorra: 'EUR',
9
- Angola: 'AOA',
10
- Anguilla: 'XCD',
11
- Antarctica: 'XCD',
12
- 'Antigua and Barbuda': 'XCD',
13
- Argentina: 'ARS',
14
- Armenia: 'AMD',
15
- Aruba: 'AWG',
16
- Australia: 'AUD',
17
- Austria: 'EUR',
18
- Azerbaijan: 'AZN',
19
- Bahamas: 'BSD',
20
- Bahrain: 'BHD',
21
- Bangladesh: 'BDT',
22
- Barbados: 'BBD',
23
- Belarus: 'BYR',
24
- Belgium: 'EUR',
25
- Belize: 'BZD',
26
- Benin: 'XOF',
27
- Bermuda: 'BMD',
28
- Bhutan: 'BTN',
29
- Bolivia: 'BOB',
30
- 'Bosnia and Herzegovina': 'BAM',
31
- Botswana: 'BWP',
32
- 'Bouvet Island': 'NOK',
33
- Brazil: 'BRL',
34
- 'British Indian Ocean Territory': 'USD',
35
- Brunei: 'BND',
36
- Bulgaria: 'BGN',
37
- 'Burkina Faso': 'XOF',
38
- Burundi: 'BIF',
39
- Cambodia: 'KHR',
40
- Cameroon: 'XAF',
41
- Canada: 'CAD',
42
- 'Cape Verde': 'CVE',
43
- 'Cayman Islands': 'KYD',
44
- 'Central African Republic': 'XAF',
45
- Chad: 'XAF',
46
- Chile: 'CLP',
47
- China: 'CNY',
48
- 'Christmas Island': 'AUD',
49
- 'Cocos (Keeling) Islands': 'AUD',
50
- Colombia: 'COP',
51
- Comoros: 'KMF',
52
- Congo: 'XAF',
53
- 'Cook Islands': 'NZD',
54
- 'Costa Rica': 'CRC',
55
- Croatia: 'HRK',
56
- Cuba: 'CUP',
57
- Cyprus: 'EUR',
58
- 'Czech Republic': 'CZK',
59
- Denmark: 'DKK',
60
- Djibouti: 'DJF',
61
- Dominica: 'XCD',
62
- 'Dominican Republic': 'DOP',
63
- 'East Timor': 'USD',
64
- Ecuador: 'ECS',
65
- Egypt: 'EGP',
66
- 'El Salvador': 'SVC',
67
- England: 'GBP',
68
- 'Equatorial Guinea': 'XAF',
69
- Eritrea: 'ERN',
70
- Estonia: 'EUR',
71
- Ethiopia: 'ETB',
72
- 'Falkland Islands': 'FKP',
73
- 'Faroe Islands': 'DKK',
74
- 'Fiji Islands': 'FJD',
75
- Finland: 'EUR',
76
- France: 'EUR',
77
- 'French Guiana': 'EUR',
78
- 'French Polynesia': 'XPF',
79
- 'French Southern territories': 'EUR',
80
- Gabon: 'XAF',
81
- Gambia: 'GMD',
82
- Georgia: 'GEL',
83
- Germany: 'EUR',
84
- Ghana: 'GHS',
85
- Gibraltar: 'GIP',
86
- Greece: 'EUR',
87
- Greenland: 'DKK',
88
- Grenada: 'XCD',
89
- Guadeloupe: 'EUR',
90
- Guam: 'USD',
91
- Guatemala: 'QTQ',
92
- Guinea: 'GNF',
93
- 'Guinea-Bissau': 'CFA',
94
- Guyana: 'GYD',
95
- Haiti: 'HTG',
96
- 'Heard Island and McDonald Islands': 'AUD',
97
- 'Holy See (Vatican City State)': 'EUR',
98
- Honduras: 'HNL',
99
- 'Hong Kong': 'HKD',
100
- Hungary: 'HUF',
101
- Iceland: 'ISK',
102
- India: 'INR',
103
- Indonesia: 'IDR',
104
- Iran: 'IRR',
105
- Iraq: 'IQD',
106
- Ireland: 'EUR',
107
- Israel: 'ILS',
108
- Italy: 'EUR',
109
- 'Ivory Coast': 'XOF',
110
- Jamaica: 'JMD',
111
- Japan: 'JPY',
112
- Jordan: 'JOD',
113
- Kazakhstan: 'KZT',
114
- Kenya: 'KES',
115
- Kiribati: 'AUD',
116
- Kuwait: 'KWD',
117
- Kyrgyzstan: 'KGS',
118
- Laos: 'LAK',
119
- Latvia: 'LVL',
120
- Lebanon: 'LBP',
121
- Lesotho: 'LSL',
122
- Liberia: 'LRD',
123
- 'Libyan Arab Jamahiriya': 'LYD',
124
- Liechtenstein: 'CHF',
125
- Lithuania: 'LTL',
126
- Luxembourg: 'EUR',
127
- Macao: 'MOP',
128
- 'North Macedonia': 'MKD',
129
- Madagascar: 'MGF',
130
- Malawi: 'MWK',
131
- Malaysia: 'MYR',
132
- Maldives: 'MVR',
133
- Mali: 'XOF',
134
- Malta: 'EUR',
135
- 'Marshall Islands': 'USD',
136
- Martinique: 'EUR',
137
- Mauritania: 'MRO',
138
- Mauritius: 'MUR',
139
- Mayotte: 'EUR',
140
- Mexico: 'MXN',
141
- 'Micronesia, Federated States of': 'USD',
142
- Moldova: 'MDL',
143
- Monaco: 'EUR',
144
- Mongolia: 'MNT',
145
- Montserrat: 'XCD',
146
- Morocco: 'MAD',
147
- Mozambique: 'MZN',
148
- Myanmar: 'MMR',
149
- Namibia: 'NAD',
150
- Nauru: 'AUD',
151
- Nepal: 'NPR',
152
- Netherlands: 'EUR',
153
- 'Netherlands Antilles': 'ANG',
154
- 'New Caledonia': 'XPF',
155
- 'New Zealand': 'NZD',
156
- Nicaragua: 'NIO',
157
- Niger: 'XOF',
158
- Nigeria: 'NGN',
159
- Niue: 'NZD',
160
- 'Norfolk Island': 'AUD',
161
- 'North Korea': 'KPW',
162
- 'Northern Ireland': 'GBP',
163
- 'Northern Mariana Islands': 'USD',
164
- Norway: 'NOK',
165
- Oman: 'OMR',
166
- Pakistan: 'PKR',
167
- Palau: 'USD',
168
- Palestine: null,
169
- Panama: 'PAB',
170
- 'Papua New Guinea': 'PGK',
171
- Paraguay: 'PYG',
172
- Peru: 'PEN',
173
- Philippines: 'PHP',
174
- Pitcairn: 'NZD',
175
- Poland: 'PLN',
176
- Portugal: 'EUR',
177
- 'Puerto Rico': 'USD',
178
- Qatar: 'QAR',
179
- Reunion: 'EUR',
180
- Romania: 'RON',
181
- 'Russian Federation': 'RUB',
182
- Rwanda: 'RWF',
183
- 'Saint Helena': 'SHP',
184
- 'Saint Kitts and Nevis': 'XCD',
185
- 'Saint Lucia': 'XCD',
186
- 'Saint Pierre and Miquelon': 'EUR',
187
- 'Saint Vincent and the Grenadines': 'XCD',
188
- Samoa: 'WST',
189
- 'San Marino': 'EUR',
190
- 'Sao Tome and Principe': 'STD',
191
- 'Saudi Arabia': 'SAR',
192
- Scotland: 'GBP',
193
- Senegal: 'XOF',
194
- Serbia: 'RSD',
195
- Seychelles: 'SCR',
196
- 'Sierra Leone': 'SLL',
197
- Singapore: 'SGD',
198
- Slovakia: 'EUR',
199
- Slovenia: 'EUR',
200
- 'Solomon Islands': 'SBD',
201
- Somalia: 'SOS',
202
- 'South Africa': 'ZAR',
203
- 'South Georgia and the South Sandwich Islands': 'GBP',
204
- 'South Korea': 'KRW',
205
- 'South Sudan': 'SSP',
206
- Spain: 'EUR',
207
- 'Sri Lanka': 'LKR',
208
- Sudan: 'SDG',
209
- Suriname: 'SRD',
210
- 'Svalbard and Jan Mayen': 'NOK',
211
- Swaziland: 'SZL',
212
- Sweden: 'SEK',
213
- Switzerland: 'CHF',
214
- Syria: 'SYP',
215
- Tajikistan: 'TJS',
216
- Tanzania: 'TZS',
217
- Thailand: 'THB',
218
- 'The Democratic Republic of Congo': 'CDF',
219
- Togo: 'XOF',
220
- Tokelau: 'NZD',
221
- Tonga: 'TOP',
222
- 'Trinidad and Tobago': 'TTD',
223
- Tunisia: 'TND',
224
- Turkey: 'TRY',
225
- Turkmenistan: 'TMT',
226
- 'Turks and Caicos Islands': 'USD',
227
- Tuvalu: 'AUD',
228
- Uganda: 'UGX',
229
- Ukraine: 'UAH',
230
- 'United Arab Emirates': 'AED',
231
- 'United Kingdom': 'GBP',
232
- 'United States': 'USD',
233
- 'United States Minor Outlying Islands': 'USD',
234
- Uruguay: 'UYU',
235
- Uzbekistan: 'UZS',
236
- Vanuatu: 'VUV',
237
- Venezuela: 'VEF',
238
- Vietnam: 'VND',
239
- 'Virgin Islands, British': 'USD',
240
- 'Virgin Islands, U.S.': 'USD',
241
- Wales: 'GBP',
242
- 'Wallis and Futuna': 'XPF',
243
- 'Western Sahara': 'MAD',
244
- Yemen: 'YER',
245
- Zambia: 'ZMW',
246
- Zimbabwe: 'ZWD',
247
- };
248
- exports.default = currencyCodes;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.currencyCodes = exports.countryCodes = void 0;
7
- var country_codes_1 = require("./country-codes");
8
- Object.defineProperty(exports, "countryCodes", { enumerable: true, get: function () { return __importDefault(country_codes_1).default; } });
9
- var currency_codes_1 = require("./currency-codes");
10
- Object.defineProperty(exports, "currencyCodes", { enumerable: true, get: function () { return __importDefault(currency_codes_1).default; } });
@@ -1,29 +0,0 @@
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.convert = void 0;
13
- const countries_1 = require("./countries");
14
- const convert = (value, from = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () {
15
- const country = countries_1.countryCodes[countryCode || 'US'];
16
- if (!country) {
17
- throw new Error(`Unable to find country name for country code: ${countryCode}.`);
18
- }
19
- const to = countries_1.currencyCodes[country];
20
- if (!to) {
21
- throw new Error(`Unable to find currency code for country: ${country}.`);
22
- }
23
- const url = `https://min-api.cryptocompare.com/data/price?fsym=${from}&tsyms=${from},${to}`;
24
- const response = yield fetch(url);
25
- const data = yield response.json();
26
- const convertedValue = Math.round((value / (1 / data[to]) + Number.EPSILON) * 100) / 100;
27
- return convertedValue;
28
- });
29
- exports.convert = convert;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Storage = exports.KeychainAdapter = void 0;
4
- class KeychainAdapter {
5
- }
6
- exports.KeychainAdapter = KeychainAdapter;
7
- class Storage {
8
- }
9
- exports.Storage = Storage;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class HttpError extends Error {
4
- constructor({ message, status, statusText }) {
5
- super(`${status} - ${statusText}: ${message}`);
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, HttpError.prototype);
8
- }
9
- }
10
- exports.default = HttpError;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RpcErrorCodes = exports.ProviderRpcError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = void 0;
7
- var http_error_1 = require("./http-error");
8
- Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return __importDefault(http_error_1).default; } });
9
- var invalid_api_key_error_1 = require("./invalid-api-key-error");
10
- Object.defineProperty(exports, "InvalidApiKeyError", { enumerable: true, get: function () { return __importDefault(invalid_api_key_error_1).default; } });
11
- var invalid_chain_id_error_1 = require("./invalid-chain-id-error");
12
- Object.defineProperty(exports, "InvalidChainIdError", { enumerable: true, get: function () { return __importDefault(invalid_chain_id_error_1).default; } });
13
- var invalid_gateway_config_error_1 = require("./invalid-gateway-config-error");
14
- Object.defineProperty(exports, "InvalidGatewayConfigError", { enumerable: true, get: function () { return __importDefault(invalid_gateway_config_error_1).default; } });
15
- var missing_option_error_1 = require("./missing-option-error");
16
- Object.defineProperty(exports, "MissingOptionError", { enumerable: true, get: function () { return __importDefault(missing_option_error_1).default; } });
17
- var mpc_signing_error_1 = require("./mpc-signing-error");
18
- Object.defineProperty(exports, "MpcSigningError", { enumerable: true, get: function () { return __importDefault(mpc_signing_error_1).default; } });
19
- var no_address_error_1 = require("./no-address-error");
20
- Object.defineProperty(exports, "NoAddressError", { enumerable: true, get: function () { return __importDefault(no_address_error_1).default; } });
21
- var provider_rpc_error_1 = require("./provider-rpc-error");
22
- Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return __importDefault(provider_rpc_error_1).default; } });
23
- Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return provider_rpc_error_1.RpcErrorCodes; } });
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class InvalidApiKeyError extends Error {
4
- constructor() {
5
- super('[Portal] A valid Portal Client API Key was not provided.');
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, InvalidApiKeyError.prototype);
8
- }
9
- }
10
- exports.default = InvalidApiKeyError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class InvalidChainIdError extends Error {
4
- constructor() {
5
- super('[Portal] A valid Ethereum Chain ID was not provided.');
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, InvalidChainIdError.prototype);
8
- }
9
- }
10
- exports.default = InvalidChainIdError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class InvalidGatewayConfigError extends Error {
4
- constructor() {
5
- super('[Portal] A valid Gateway configuration was not provided.');
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, InvalidGatewayConfigError.prototype);
8
- }
9
- }
10
- exports.default = InvalidGatewayConfigError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class InvalidRpcConfigError extends Error {
4
- constructor() {
5
- super('[Portal] A valid RPC configuration was not provided.');
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, InvalidRpcConfigError.prototype);
8
- }
9
- }
10
- exports.default = InvalidRpcConfigError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class MissingOptionError extends Error {
4
- constructor({ className, option }) {
5
- super(`[Portal] Instance option '${option}' is required when instantiating ${className}.`);
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, MissingOptionError.prototype);
8
- }
9
- }
10
- exports.default = MissingOptionError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class MpcSigningError extends Error {
4
- constructor(message) {
5
- super(`[Portal] An error occurred in the MPC signing process: ${message}`);
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, MpcSigningError.prototype);
8
- }
9
- }
10
- exports.default = MpcSigningError;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NoAddressError extends Error {
4
- constructor() {
5
- super('[Portal] A valid wallet address was not provided.');
6
- // Set the prototype explicitly.
7
- Object.setPrototypeOf(this, NoAddressError.prototype);
8
- }
9
- }
10
- exports.default = NoAddressError;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RpcErrorCodes = void 0;
4
- var RpcErrorCodes;
5
- (function (RpcErrorCodes) {
6
- RpcErrorCodes[RpcErrorCodes["UserRejectedRequest"] = 4001] = "UserRejectedRequest";
7
- RpcErrorCodes[RpcErrorCodes["Unauthorized"] = 4100] = "Unauthorized";
8
- RpcErrorCodes[RpcErrorCodes["UnsupportedMethod"] = 4200] = "UnsupportedMethod";
9
- RpcErrorCodes[RpcErrorCodes["Disconnected"] = 4900] = "Disconnected";
10
- RpcErrorCodes[RpcErrorCodes["ChainDisconnected"] = 4901] = "ChainDisconnected";
11
- })(RpcErrorCodes = exports.RpcErrorCodes || (exports.RpcErrorCodes = {}));
12
- const providerErrors = {
13
- 4001: {
14
- name: 'User Rejected Request',
15
- description: 'The user rejected the request.',
16
- },
17
- 4100: {
18
- name: 'Unauthorized',
19
- description: 'The requested method and/or account has not been authorized by the user.',
20
- },
21
- 4200: {
22
- name: 'Unsupported Method',
23
- description: 'The Provider does not support the requested method.',
24
- },
25
- 4900: {
26
- name: 'Disconnected',
27
- description: 'The Provider is disconnected from all chains.',
28
- },
29
- 4901: {
30
- name: 'Chain Disconnected',
31
- description: 'The Provider is not connected to the requested chain.',
32
- },
33
- };
34
- class ProviderRpcError extends Error {
35
- constructor({ code, data }) {
36
- const log = console;
37
- const definition = providerErrors[code];
38
- if (!definition) {
39
- log.warn(`[Portal] ProviderRpcError instantiated with unknown error code ${code}. Attempting to continue with limited context.`);
40
- }
41
- const message = definition
42
- ? `${definition.name} - ${definition.description}`
43
- : '';
44
- super(`[Portal] RPC Error: ${code} ${message}`);
45
- // Set the prototype explicitly.
46
- Object.setPrototypeOf(this, ProviderRpcError.prototype);
47
- this.code = code;
48
- this.data = data;
49
- this.definition = definition;
50
- }
51
- }
52
- exports.default = ProviderRpcError;
@@ -1,87 +0,0 @@
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.parseRequest = void 0;
13
- const currency_1 = require("../currency");
14
- const hexStringToString = (hexInput) => {
15
- // Get the proper hex string
16
- const byteArray = Array.from(hexStringToByteArray(hexInput.replace('0x', '')));
17
- // Create an array of characters
18
- const stringArray = byteArray.reduce((acc, charCode) => {
19
- // Add the character matching the charCode
20
- acc.push(String.fromCharCode(charCode));
21
- // Return the accumulator
22
- return acc;
23
- }, []);
24
- // Join the array of characters
25
- const string = stringArray.join('');
26
- // Return the final string
27
- return string;
28
- };
29
- const hexStringToByteArray = (hexString) => {
30
- // Verify the length of the string
31
- if (hexString.length % 2 !== 0) {
32
- throw Error('[Portal] hexStringToByteArray() detected invalid input lenth for hexString.');
33
- }
34
- // Get the total bytes
35
- const totalBytes = hexString.length / 2;
36
- // Initialize a Uint8Array with a length matching totalBytes
37
- const byteArray = new Uint8Array(totalBytes);
38
- // Loop of the resulting array
39
- for (let i = 0; i < totalBytes; i++) {
40
- // Get the byte at the current index
41
- const substring = hexString.substring(i * 2, i * 2 + 2).toLowerCase();
42
- // Get the integer matching the current byte and push to the array
43
- byteArray[i] = parseInt(substring, 16);
44
- }
45
- // Return a byte array
46
- return byteArray;
47
- };
48
- const hexStringToNumber = (hexBalance) => {
49
- const balanceNumber = Number(hexBalance);
50
- console.log(`balanceNumber`, balanceNumber);
51
- const balance = Math.round((balanceNumber / 1e18) * 1000000) / 1000000;
52
- return balance;
53
- };
54
- const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () {
55
- let requestData;
56
- console.log(`Request: `, JSON.stringify({ method, params }));
57
- const txParam0 = Array.isArray(params) ? params[0] : params;
58
- const txParam1 = Array.isArray(params) ? params[1] : null;
59
- switch (method) {
60
- case 'eth_sendTransaction':
61
- case 'eth_signTransaction':
62
- const payload = txParam0;
63
- const value = hexStringToNumber(payload.value);
64
- requestData = {
65
- data: payload.data,
66
- from: payload.from,
67
- to: payload.to,
68
- value,
69
- valueConverted: yield (0, currency_1.convert)(value),
70
- };
71
- console.log(`requestData: `, requestData);
72
- break;
73
- case 'eth_sign':
74
- case 'personal_sign':
75
- requestData = {
76
- message: hexStringToString(txParam0),
77
- };
78
- break;
79
- default:
80
- break;
81
- }
82
- return {
83
- method,
84
- data: requestData,
85
- };
86
- });
87
- exports.parseRequest = parseRequest;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../errors");
4
- class HttpRequest {
5
- constructor({ body = {}, headers = {}, method, url }) {
6
- this.body = body;
7
- this.headers = headers;
8
- this.method = method;
9
- this.url = url;
10
- this.request = new XMLHttpRequest();
11
- this.request.open(this.method, this.url, true);
12
- }
13
- send() {
14
- return new Promise((resolve, reject) => {
15
- // Sets headers on the request
16
- this.prepareRequest();
17
- // Sends the request with a formatted request body
18
- const body = this.prepareBody();
19
- this.request.send(body);
20
- // Adds an event listener for when the request state changes
21
- this.request.onreadystatechange = () => {
22
- if (this.request.readyState === 4) {
23
- // readyState 4 means the request has completed
24
- if (this.request.status !== 200) {
25
- // If we didn't get an 'OK' status, error out
26
- reject(new errors_1.HttpError({
27
- message: this.request.responseText,
28
- status: this.request.status,
29
- statusText: this.request.statusText,
30
- }));
31
- }
32
- else {
33
- // Otherwise, resolve a parsed response object
34
- resolve(this.buildResponse());
35
- }
36
- }
37
- };
38
- });
39
- }
40
- buildResponse() {
41
- try {
42
- // Try parsing the response body into a JSON object
43
- const response = JSON.parse(this.request.response);
44
- return response;
45
- }
46
- catch (_a) {
47
- // If JSON parsing doesn't work, just return the response body however it came back
48
- return this.request.response;
49
- }
50
- }
51
- prepareBody() {
52
- if (this.headers['Content-Type'] === 'application/json') {
53
- // Stringify if we're declaring this request to be a JSON request
54
- return JSON.stringify(this.body);
55
- }
56
- else {
57
- // Otherwise, build a serialized string
58
- const params = [];
59
- for (const [key, value] of Object.entries(this.body)) {
60
- params.push(`${key}=${value}`);
61
- }
62
- return params.join('&');
63
- }
64
- }
65
- prepareRequest() {
66
- // Add all of the defined headers to the request
67
- for (const [key, value] of Object.entries(this.headers)) {
68
- this.request.setRequestHeader(key, value);
69
- }
70
- }
71
- }
72
- exports.default = HttpRequest;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HttpRequester = exports.HttpRequest = exports.parseRequest = exports.RpcErrorCodes = exports.ProviderRpcError = exports.NoAddressError = exports.MpcSigningError = exports.MissingOptionError = exports.InvalidGatewayConfigError = exports.InvalidChainIdError = exports.InvalidApiKeyError = exports.HttpError = exports.Storage = exports.PortalApi = exports.KeychainAdapter = exports.convert = void 0;
7
- var currency_1 = require("./currency");
8
- Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return currency_1.convert; } });
9
- var definitions_1 = require("./definitions");
10
- Object.defineProperty(exports, "KeychainAdapter", { enumerable: true, get: function () { return definitions_1.KeychainAdapter; } });
11
- Object.defineProperty(exports, "PortalApi", { enumerable: true, get: function () { return definitions_1.PortalApi; } });
12
- Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return definitions_1.Storage; } });
13
- var errors_1 = require("./errors");
14
- Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return errors_1.HttpError; } });
15
- Object.defineProperty(exports, "InvalidApiKeyError", { enumerable: true, get: function () { return errors_1.InvalidApiKeyError; } });
16
- Object.defineProperty(exports, "InvalidChainIdError", { enumerable: true, get: function () { return errors_1.InvalidChainIdError; } });
17
- Object.defineProperty(exports, "InvalidGatewayConfigError", { enumerable: true, get: function () { return errors_1.InvalidGatewayConfigError; } });
18
- Object.defineProperty(exports, "MissingOptionError", { enumerable: true, get: function () { return errors_1.MissingOptionError; } });
19
- Object.defineProperty(exports, "MpcSigningError", { enumerable: true, get: function () { return errors_1.MpcSigningError; } });
20
- Object.defineProperty(exports, "NoAddressError", { enumerable: true, get: function () { return errors_1.NoAddressError; } });
21
- Object.defineProperty(exports, "ProviderRpcError", { enumerable: true, get: function () { return errors_1.ProviderRpcError; } });
22
- Object.defineProperty(exports, "RpcErrorCodes", { enumerable: true, get: function () { return errors_1.RpcErrorCodes; } });
23
- var eth_requests_1 = require("./eth-requests");
24
- Object.defineProperty(exports, "parseRequest", { enumerable: true, get: function () { return eth_requests_1.parseRequest; } });
25
- var http_request_1 = require("./http-request");
26
- Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return __importDefault(http_request_1).default; } });
27
- var requesters_1 = require("./requesters");
28
- Object.defineProperty(exports, "HttpRequester", { enumerable: true, get: function () { return requesters_1.HttpRequester; } });
@@ -1,52 +0,0 @@
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 HttpRequester {
14
- constructor({ baseUrl }) {
15
- this.baseUrl = baseUrl.startsWith('https://')
16
- ? baseUrl
17
- : `https://${baseUrl}`;
18
- }
19
- get(path, options) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const requestOptions = {
22
- method: 'GET',
23
- url: `${this.baseUrl}${path}`,
24
- };
25
- if (options && options.headers) {
26
- requestOptions.headers = this.buildHeaders(options.headers);
27
- }
28
- const request = new index_1.HttpRequest(requestOptions);
29
- const response = (yield request.send());
30
- return response;
31
- });
32
- }
33
- post(path, options) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const requestOptions = {
36
- method: 'POST',
37
- url: `${this.baseUrl}${path}`,
38
- };
39
- requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
40
- if (options && options.body) {
41
- requestOptions.body = options.body;
42
- }
43
- const request = new index_1.HttpRequest(requestOptions);
44
- const response = (yield request.send());
45
- return response;
46
- });
47
- }
48
- buildHeaders(headers) {
49
- return Object.assign({ 'Content-Type': 'application/json' }, headers);
50
- }
51
- }
52
- exports.default = HttpRequester;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HttpRequester = void 0;
7
- var http_1 = require("./http");
8
- Object.defineProperty(exports, "HttpRequester", { enumerable: true, get: function () { return __importDefault(http_1).default; } });
@@ -1,26 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var InvalidRpcConfigError = /** @class */ (function (_super) {
17
- __extends(InvalidRpcConfigError, _super);
18
- function InvalidRpcConfigError() {
19
- var _this = _super.call(this, '[Portal] A valid RPC configuration was not provided.') || this;
20
- // Set the prototype explicitly.
21
- Object.setPrototypeOf(_this, InvalidRpcConfigError.prototype);
22
- return _this;
23
- }
24
- return InvalidRpcConfigError;
25
- }(Error));
26
- export default InvalidRpcConfigError;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes