@portal-hq/utils 0.2.7 → 0.2.9

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 (46) hide show
  1. package/lib/definitions/index.js +4 -0
  2. package/lib/{esm/index.js → index.js} +1 -1
  3. package/package.json +1 -1
  4. package/src/currency/countries/currency-codes.ts +0 -1
  5. package/src/definitions/index.ts +55 -0
  6. package/src/errors/provider-rpc-error.ts +1 -1
  7. package/src/eth-requests/index.ts +14 -9
  8. package/src/index.ts +10 -2
  9. package/types.d.ts +60 -14
  10. package/lib/commonjs/currency/countries/country-codes.js +0 -250
  11. package/lib/commonjs/currency/countries/currency-codes.js +0 -248
  12. package/lib/commonjs/currency/countries/index.js +0 -10
  13. package/lib/commonjs/currency/index.js +0 -29
  14. package/lib/commonjs/errors/http-error.js +0 -10
  15. package/lib/commonjs/errors/index.js +0 -23
  16. package/lib/commonjs/errors/invalid-api-key-error.js +0 -10
  17. package/lib/commonjs/errors/invalid-chain-id-error.js +0 -10
  18. package/lib/commonjs/errors/invalid-gateway-config-error.js +0 -10
  19. package/lib/commonjs/errors/invalid-rpc-config-error.js +0 -10
  20. package/lib/commonjs/errors/missing-option-error.js +0 -10
  21. package/lib/commonjs/errors/mpc-signing-error.js +0 -10
  22. package/lib/commonjs/errors/no-address-error.js +0 -10
  23. package/lib/commonjs/errors/provider-rpc-error.js +0 -52
  24. package/lib/commonjs/eth-requests/index.js +0 -87
  25. package/lib/commonjs/http-request/index.js +0 -72
  26. package/lib/commonjs/index.js +0 -27
  27. package/lib/commonjs/requesters/http.js +0 -52
  28. package/lib/commonjs/requesters/index.js +0 -8
  29. package/lib/esm/errors/invalid-rpc-config-error.js +0 -26
  30. /package/lib/{esm/currency → currency}/countries/country-codes.js +0 -0
  31. /package/lib/{esm/currency → currency}/countries/currency-codes.js +0 -0
  32. /package/lib/{esm/currency → currency}/countries/index.js +0 -0
  33. /package/lib/{esm/currency → currency}/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/requesters → requesters}/http.js +0 -0
  46. /package/lib/{esm/requesters → requesters}/index.js +0 -0
@@ -0,0 +1,4 @@
1
+ export class KeychainAdapter {
2
+ }
3
+ export class Storage {
4
+ }
@@ -1,6 +1,6 @@
1
1
  export { convert } from './currency';
2
+ export { KeychainAdapter, PortalApi, Storage } from './definitions';
2
3
  export { HttpError, InvalidApiKeyError, InvalidChainIdError, InvalidGatewayConfigError, MissingOptionError, MpcSigningError, NoAddressError, ProviderRpcError, RpcErrorCodes, } from './errors';
3
4
  export { parseRequest } from './eth-requests';
4
5
  export { default as HttpRequest } from './http-request';
5
6
  export { HttpRequester } from './requesters';
6
- export { KeychainAdapter, Storage, } from '../types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
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',
@@ -0,0 +1,55 @@
1
+ import { ClientWithCustodianData, Dapp, DkgData, Network } from '../../types'
2
+
3
+ export abstract class KeychainAdapter {
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
+ }
34
+ }
35
+
36
+ export declare class PortalApi {
37
+ getClient(): Promise<ClientWithCustodianData>
38
+ getEnabledDapps(): Promise<Dapp[]>
39
+ getNetworks(): Promise<Network[]>
40
+ }
41
+
42
+ export abstract class Storage {
43
+ public api?: PortalApi
44
+
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
+ }
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
@@ -1,5 +1,7 @@
1
1
  export { convert } from './currency'
2
2
 
3
+ export { KeychainAdapter, PortalApi, Storage } from './definitions'
4
+
3
5
  export {
4
6
  HttpError,
5
7
  InvalidApiKeyError,
@@ -19,13 +21,19 @@ export { default as HttpRequest } from './http-request'
19
21
  export { HttpRequester } from './requesters'
20
22
 
21
23
  export {
22
- KeychainAdapter,
23
- Storage,
24
+ type ClientWithCustodianData,
25
+ type Contract,
26
+ type Dapp,
27
+ type DappImage,
28
+ type DkgData,
24
29
  type HttpOptions,
25
30
  type HttpRequesterOptions,
26
31
  type HttpRequestOptions,
27
32
  type MessageData,
33
+ type Network,
28
34
  type OutgoingRequest,
29
35
  type OutgoingRequestData,
30
36
  type SignableTransactionData,
37
+ type SigningRequestArguments,
38
+ type SigningResponse,
31
39
  } from '../types'
package/types.d.ts CHANGED
@@ -4,6 +4,47 @@ export type ValidHttpRequestMethods = 'DELETE' | 'GET' | 'POST' | 'PUT'
4
4
 
5
5
  export type ValidRpcErrorCodes = 4001 | 4100 | 4200 | 4900 | 4901
6
6
 
7
+ export interface Bk {
8
+ X: string
9
+ Rank: number
10
+ }
11
+
12
+ export interface ClientWithCustodianData {
13
+ id: string
14
+ address: string
15
+ clientApiKey: string
16
+ custodian: {
17
+ id: string
18
+ name: string
19
+ }
20
+ }
21
+
22
+ export interface Contract {
23
+ id: string
24
+ contractAddress: string
25
+ clientUrl: string
26
+ network: Network
27
+ }
28
+
29
+ export interface Dapp {
30
+ id: string
31
+ contracts: Contract[]
32
+ name: string
33
+ image: DappImage
34
+ }
35
+
36
+ export interface DappImage {
37
+ id: string
38
+ filename: string
39
+ data: string
40
+ }
41
+
42
+ export interface DkgData {
43
+ share: string
44
+ pubkey: Pubkey
45
+ bks: Bk[]
46
+ }
47
+
7
48
  export interface HttpErrorOptions {
8
49
  message: string
9
50
  status: number
@@ -35,11 +76,22 @@ export interface MissingOptionErrorOptions {
35
76
  option: string
36
77
  }
37
78
 
79
+ export interface Network {
80
+ id: string
81
+ chainId: string
82
+ name: string
83
+ }
84
+
38
85
  export interface OutgoingRequest {
39
86
  method: string
40
87
  data: OutgoingRequestData
41
88
  }
42
89
 
90
+ export interface Pubkey {
91
+ X: string
92
+ Y: string
93
+ }
94
+
43
95
  export interface RequesterOptions {}
44
96
 
45
97
  export interface RpcErrorDefinition {
@@ -60,20 +112,14 @@ export interface SignableTransactionData {
60
112
  valueConverted: number
61
113
  }
62
114
 
63
- // Classes
64
-
65
- export declare class KeychainAdapter {
66
- deleteAddress: () => Promise<boolean>
67
- deleteDkgResult: () => Promise<boolean>
68
- getAddress: (isSim?: boolean) => Promise<string>
69
- getDkgResult: (isSim?: boolean) => Promise<string>
70
- storeAddress: (address: string, isSim?: boolean) => Promise<void>
71
- storeDkgResult: (result: DkgData, isSim?: boolean) => Promise<void>
115
+ export interface SigningRequestArguments {
116
+ readonly chainId?: number
117
+ readonly method: string
118
+ readonly params?: unknown[] | SigningRequestParams
72
119
  }
73
120
 
74
- export declare class Storage {
75
- public api: PortalApi
76
-
77
- read(): Promise<string>
78
- write(privateKey: string): Promise<string>
121
+ export interface SigningResponse {
122
+ method: string
123
+ params?: unknown[] | SigningRequestParams
124
+ signature?: any
79
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;