@portal-hq/utils 2.0.4 → 2.0.7

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.
@@ -39,7 +39,7 @@ const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awaiter(voi
39
39
  const url = `https://min-api.cryptocompare.com/data/price?fsym=${from}&tsyms=${to}`;
40
40
  const response = yield fetch(url);
41
41
  const data = yield response.json();
42
- const convertedValue = Math.round((value * data[to]) * 10000) / 10000;
42
+ const convertedValue = Math.round(value * data[to] * 10000) / 10000;
43
43
  return convertedValue;
44
44
  });
45
45
  exports.convertCryptoToLocal = convertCryptoToLocal;
@@ -11,13 +11,17 @@ class KeychainAdapter {
11
11
  getAddress(isSim) {
12
12
  throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
13
13
  }
14
- getDkgResult(isSim, _progress = () => { }) {
14
+ getDkgResult(isSim, _progress = () => {
15
+ // Noop
16
+ }) {
15
17
  throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
16
18
  }
17
19
  storeAddress(address, isSim) {
18
20
  throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
19
21
  }
20
- storeDkgResult(result, isSim, _progress = () => { }) {
22
+ storeDkgResult(result, isSim, _progress = () => {
23
+ // Noop
24
+ }) {
21
25
  throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
22
26
  }
23
27
  validateOperations() {
@@ -62,7 +62,7 @@ const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, funct
62
62
  const txParam0 = Array.isArray(params) ? params[0] : params;
63
63
  switch (method) {
64
64
  case 'eth_sendTransaction':
65
- case 'eth_signTransaction':
65
+ case 'eth_signTransaction': {
66
66
  const payload = txParam0;
67
67
  const value = (0, exports.hexStringToNumber)(payload.value);
68
68
  requestData = {
@@ -76,10 +76,11 @@ const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, funct
76
76
  method,
77
77
  data: requestData,
78
78
  };
79
+ }
79
80
  case 'eth_sign':
80
81
  case 'personal_sign':
81
82
  case 'eth_signTypedData_v3':
82
- case 'eth_signTypedData_v4':
83
+ case 'eth_signTypedData_v4': {
83
84
  requestData = {
84
85
  message: (0, exports.hexStringToString)(txParam0),
85
86
  };
@@ -87,6 +88,7 @@ const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0, funct
87
88
  method,
88
89
  data: requestData,
89
90
  };
91
+ }
90
92
  default:
91
93
  return {
92
94
  method,
@@ -35,7 +35,7 @@ export const convertCryptoToLocal = (value, from = 'ETH', countryCode) => __awai
35
35
  const url = `https://min-api.cryptocompare.com/data/price?fsym=${from}&tsyms=${to}`;
36
36
  const response = yield fetch(url);
37
37
  const data = yield response.json();
38
- const convertedValue = Math.round((value * data[to]) * 10000) / 10000;
38
+ const convertedValue = Math.round(value * data[to] * 10000) / 10000;
39
39
  return convertedValue;
40
40
  });
41
41
  export const convertLocalToCrypto = (value, to = 'ETH', countryCode) => __awaiter(void 0, void 0, void 0, function* () {
@@ -8,13 +8,17 @@ export class KeychainAdapter {
8
8
  getAddress(isSim) {
9
9
  throw new Error(`[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
10
10
  }
11
- getDkgResult(isSim, _progress = () => { }) {
11
+ getDkgResult(isSim, _progress = () => {
12
+ // Noop
13
+ }) {
12
14
  throw new Error(`[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
13
15
  }
14
16
  storeAddress(address, isSim) {
15
17
  throw new Error(`[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
16
18
  }
17
- storeDkgResult(result, isSim, _progress = () => { }) {
19
+ storeDkgResult(result, isSim, _progress = () => {
20
+ // Noop
21
+ }) {
18
22
  throw new Error(`[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`);
19
23
  }
20
24
  validateOperations() {
@@ -55,7 +55,7 @@ export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0
55
55
  const txParam0 = Array.isArray(params) ? params[0] : params;
56
56
  switch (method) {
57
57
  case 'eth_sendTransaction':
58
- case 'eth_signTransaction':
58
+ case 'eth_signTransaction': {
59
59
  const payload = txParam0;
60
60
  const value = hexStringToNumber(payload.value);
61
61
  requestData = {
@@ -69,10 +69,11 @@ export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0
69
69
  method,
70
70
  data: requestData,
71
71
  };
72
+ }
72
73
  case 'eth_sign':
73
74
  case 'personal_sign':
74
75
  case 'eth_signTypedData_v3':
75
- case 'eth_signTypedData_v4':
76
+ case 'eth_signTypedData_v4': {
76
77
  requestData = {
77
78
  message: hexStringToString(txParam0),
78
79
  };
@@ -80,6 +81,7 @@ export const parseRequest = (method, params) => __awaiter(void 0, void 0, void 0
80
81
  method,
81
82
  data: requestData,
82
83
  };
84
+ }
83
85
  default:
84
86
  return {
85
87
  method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portal-hq/utils",
3
- "version": "2.0.4",
3
+ "version": "2.0.7",
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": "2d2f1ef628bc8788fa4a9cd32cc44795e547b3a7"
29
+ "gitHead": "fdd0c978b9d62ff729189eae6664dafb039dc1fa"
30
30
  }
@@ -2,7 +2,7 @@ import { countryCodes, currencyCodes } from './countries'
2
2
 
3
3
  export const convert = async (
4
4
  value: number,
5
- from: string = 'ETH',
5
+ from = 'ETH',
6
6
  countryCode?: string
7
7
  ): Promise<number> => {
8
8
  const country = countryCodes[countryCode || 'US']
@@ -29,10 +29,9 @@ export const convert = async (
29
29
 
30
30
  export const convertCryptoToLocal = async (
31
31
  value: number,
32
- from: string = 'ETH',
32
+ from = 'ETH',
33
33
  countryCode?: string
34
34
  ): Promise<number> => {
35
-
36
35
  const country = countryCodes[countryCode || 'US']
37
36
  if (!country) {
38
37
  throw new Error(
@@ -49,19 +48,16 @@ export const convertCryptoToLocal = async (
49
48
  const response = await fetch(url)
50
49
  const data = await response.json()
51
50
 
52
- const convertedValue =
53
- Math.round((value * data[to]) * 10000) / 10000
51
+ const convertedValue = Math.round(value * data[to] * 10000) / 10000
54
52
 
55
53
  return convertedValue
56
54
  }
57
55
 
58
-
59
56
  export const convertLocalToCrypto = async (
60
57
  value: number,
61
- to: string = 'ETH',
58
+ to = 'ETH',
62
59
  countryCode: string
63
60
  ): Promise<number> => {
64
-
65
61
  const country = countryCodes[countryCode || 'US']
66
62
  if (!country) {
67
63
  throw new Error(
@@ -51,7 +51,7 @@ export interface IPortalApi {
51
51
  getTransactions(): Promise<Transaction[]>
52
52
  getBalances(): Promise<Balance[]>
53
53
  simulateTransaction(
54
- params: SimulateTransactionParam,
54
+ params: SimulateTransactionParam
55
55
  ): Promise<SimulatedTransaction>
56
56
  getQuote(apiKey: string, args: QuoteArgs): Promise<QuoteResponse>
57
57
  getSources(apiKey: string): Promise<Record<string, string>>
@@ -61,12 +61,12 @@ export interface IPortalApi {
61
61
  storedClientBackupShareKey(backupMethod?: string): Promise<void>
62
62
  storedClientBackupShare(
63
63
  success: boolean,
64
- backupMethod?: string,
64
+ backupMethod?: string
65
65
  ): Promise<void>
66
66
  identify(traits?: Record<string, any>): Promise<{ success: boolean }>
67
67
  track(
68
68
  event: string,
69
- properties?: Record<string, any>,
69
+ properties?: Record<string, any>
70
70
  ): Promise<{ success: boolean }>
71
71
  }
72
72
 
@@ -106,44 +106,48 @@ export abstract class KeychainAdapter {
106
106
 
107
107
  deleteAddress(): Promise<boolean> {
108
108
  throw new Error(
109
- '[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.',
109
+ '[Portal] KeychainAdapter method deleteAddress cannot be called directly. Please extend KeychainAdapter.'
110
110
  )
111
111
  }
112
112
  deleteDkgResult(): Promise<boolean> {
113
113
  throw new Error(
114
- '[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.',
114
+ '[Portal] KeychainAdapter method deleteDkgResult cannot be called directly. Please extend KeychainAdapter.'
115
115
  )
116
116
  }
117
117
  getAddress(isSim?: boolean): Promise<string> {
118
118
  throw new Error(
119
- `[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
119
+ `[Portal] KeychainAdapter method getAddress(${isSim}) cannot be called directly. Please extend KeychainAdapter.`
120
120
  )
121
121
  }
122
122
  getDkgResult(
123
123
  isSim?: boolean,
124
- _progress: ProgressCallback = () => {},
124
+ _progress: ProgressCallback = () => {
125
+ // Noop
126
+ }
125
127
  ): Promise<string> {
126
128
  throw new Error(
127
- `[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
129
+ `[Portal] KeychainAdapter method getDkgResult(${isSim}) cannot be called directly. Please extend KeychainAdapter.`
128
130
  )
129
131
  }
130
132
  storeAddress(address: string, isSim?: boolean): Promise<void> {
131
133
  throw new Error(
132
- `[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
134
+ `[Portal] KeychainAdapter method storeAddress(${address}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`
133
135
  )
134
136
  }
135
137
  storeDkgResult(
136
138
  result: DkgData,
137
139
  isSim?: boolean,
138
- _progress: ProgressCallback = () => {},
140
+ _progress: ProgressCallback = () => {
141
+ // Noop
142
+ }
139
143
  ): Promise<void> {
140
144
  throw new Error(
141
- `[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`,
145
+ `[Portal] KeychainAdapter method storeDkgResult(${result}, ${isSim}) cannot be called directly. Please extend KeychainAdapter.`
142
146
  )
143
147
  }
144
148
  validateOperations(): Promise<boolean> {
145
149
  throw new Error(
146
- `[Portal] KeychainAdapter method validateOperations() cannot be called directly. Please extend KeychainAdapter.`,
150
+ `[Portal] KeychainAdapter method validateOperations() cannot be called directly. Please extend KeychainAdapter.`
147
151
  )
148
152
  }
149
153
  }
@@ -165,25 +169,25 @@ export abstract class Storage {
165
169
 
166
170
  delete(): Promise<boolean> {
167
171
  throw new Error(
168
- '[Portal] Storage method delete cannot be called directly. Please extend Storage.',
172
+ '[Portal] Storage method delete cannot be called directly. Please extend Storage.'
169
173
  )
170
174
  }
171
175
 
172
176
  read(): Promise<string> {
173
177
  throw new Error(
174
- '[Portal] Storage method read cannot be called directly. Please extend Storage.',
178
+ '[Portal] Storage method read cannot be called directly. Please extend Storage.'
175
179
  )
176
180
  }
177
181
 
178
182
  write(privateKey: string): Promise<string> {
179
183
  throw new Error(
180
- `[Portal] Storage method write(${privateKey}) cannot be called directly. Please extend Storage.`,
184
+ `[Portal] Storage method write(${privateKey}) cannot be called directly. Please extend Storage.`
181
185
  )
182
186
  }
183
187
 
184
188
  validateOperations(): Promise<boolean> {
185
189
  throw new Error(
186
- `[Portal] Storage method validateOperations() cannot be called directly. Please extend Storage.`,
190
+ `[Portal] Storage method validateOperations() cannot be called directly. Please extend Storage.`
187
191
  )
188
192
  }
189
193
  }
@@ -3,7 +3,7 @@ import { type MissingOptionErrorOptions } from '../../types'
3
3
  class MissingOptionError extends Error {
4
4
  constructor({ className, option }: MissingOptionErrorOptions) {
5
5
  super(
6
- `[Portal] Instance option '${option}' is required when instantiating ${className}.`,
6
+ `[Portal] Instance option '${option}' is required when instantiating ${className}.`
7
7
  )
8
8
 
9
9
  // Set the prototype explicitly.
@@ -47,7 +47,7 @@ class ProviderRpcError extends Error {
47
47
 
48
48
  if (!definition) {
49
49
  log.warn(
50
- `[Portal] ProviderRpcError instantiated with unknown error code ${code}. Attempting to continue with limited context.`,
50
+ `[Portal] ProviderRpcError instantiated with unknown error code ${code}. Attempting to continue with limited context.`
51
51
  )
52
52
  }
53
53
 
@@ -11,7 +11,7 @@ export const hexStringToByteArray = (hexString: string): Uint8Array => {
11
11
  // Verify the length of the string
12
12
  if (hexString.length % 2 !== 0) {
13
13
  throw Error(
14
- '[Portal] hexStringToByteArray() detected invalid input lenth for hexString.',
14
+ '[Portal] hexStringToByteArray() detected invalid input lenth for hexString.'
15
15
  )
16
16
  }
17
17
 
@@ -55,7 +55,7 @@ export const hexStringToString = (hexInput: string): string => {
55
55
  // Return the accumulator
56
56
  return acc
57
57
  },
58
- [] as string[],
58
+ [] as string[]
59
59
  )
60
60
 
61
61
  // Join the array of characters
@@ -71,7 +71,7 @@ export const numberToHexString = (value: number): string => {
71
71
 
72
72
  export const parseRequest = async (
73
73
  method: string,
74
- params: any,
74
+ params: any
75
75
  ): Promise<OutgoingRequest> => {
76
76
  let requestData: OutgoingRequestData
77
77
 
@@ -79,9 +79,9 @@ export const parseRequest = async (
79
79
 
80
80
  switch (method) {
81
81
  case 'eth_sendTransaction':
82
- case 'eth_signTransaction':
82
+ case 'eth_signTransaction': {
83
83
  const payload = txParam0
84
- const value = hexStringToNumber(payload.value)
84
+ const value = hexStringToNumber(payload.value as string)
85
85
 
86
86
  requestData = {
87
87
  data: payload.data,
@@ -95,17 +95,19 @@ export const parseRequest = async (
95
95
  method,
96
96
  data: requestData,
97
97
  }
98
+ }
98
99
  case 'eth_sign':
99
100
  case 'personal_sign':
100
101
  case 'eth_signTypedData_v3':
101
- case 'eth_signTypedData_v4':
102
+ case 'eth_signTypedData_v4': {
102
103
  requestData = {
103
- message: hexStringToString(txParam0),
104
+ message: hexStringToString(txParam0 as string),
104
105
  } as MessageData
105
106
  return {
106
107
  method,
107
108
  data: requestData,
108
109
  }
110
+ }
109
111
  default:
110
112
  return {
111
113
  method,
@@ -45,7 +45,7 @@ class HttpRequest {
45
45
  message: this.request.responseText,
46
46
  status: this.request.status,
47
47
  statusText: this.request.statusText,
48
- }),
48
+ })
49
49
  )
50
50
  } else {
51
51
  // Otherwise, resolve a parsed response object
@@ -64,7 +64,7 @@ class HttpRequest {
64
64
 
65
65
  try {
66
66
  // Try parsing the response body into a JSON object
67
- const response = JSON.parse(this.request.response) as T
67
+ const response = JSON.parse(this.request.response as string) as T
68
68
  return response
69
69
  } catch {
70
70
  // If JSON parsing doesn't work, just return the response body however it came back
@@ -93,7 +93,7 @@ class HttpRequest {
93
93
  private prepareRequest(): void {
94
94
  // Add all of the defined headers to the request
95
95
  for (const [key, value] of Object.entries(this.headers)) {
96
- this.request.setRequestHeader(key, value)
96
+ this.request.setRequestHeader(key, value as string)
97
97
  }
98
98
  }
99
99
  }
@@ -27,7 +27,7 @@ class HttpRequester {
27
27
  } as HttpRequestOptions
28
28
 
29
29
  requestOptions.headers = this.buildHeaders(
30
- options && options.headers ? options.headers : {},
30
+ options && options.headers ? options.headers : {}
31
31
  )
32
32
 
33
33
  const request = new HttpRequest(requestOptions)
@@ -43,7 +43,7 @@ class HttpRequester {
43
43
  } as HttpRequestOptions
44
44
 
45
45
  requestOptions.headers = this.buildHeaders(
46
- options && options.headers ? options.headers : {},
46
+ options && options.headers ? options.headers : {}
47
47
  )
48
48
 
49
49
  const request = new HttpRequest(requestOptions)
@@ -59,7 +59,7 @@ class HttpRequester {
59
59
  } as HttpRequestOptions
60
60
 
61
61
  requestOptions.headers = this.buildHeaders(
62
- options && options.headers ? options.headers : {},
62
+ options && options.headers ? options.headers : {}
63
63
  )
64
64
 
65
65
  if (options && options.body) {
@@ -79,7 +79,7 @@ class HttpRequester {
79
79
  } as HttpRequestOptions
80
80
 
81
81
  requestOptions.headers = this.buildHeaders(
82
- options && options.headers ? options.headers : {},
82
+ options && options.headers ? options.headers : {}
83
83
  )
84
84
 
85
85
  if (options && options.body) {
package/types.d.ts CHANGED
@@ -18,11 +18,12 @@ export interface Bk {
18
18
  export interface ClientWithCustodianData {
19
19
  id: string
20
20
  address: string
21
- clientApiKey: string
21
+ backupStatus?: string | null
22
22
  custodian: {
23
23
  id: string
24
24
  name: string
25
25
  }
26
+ signingStatus?: string | null
26
27
  }
27
28
 
28
29
  export interface Address {