@avalabs/evm-module 0.0.17 → 0.0.18

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.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@avalabs/evm-module",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "dependencies": {
9
- "@avalabs/vm-module-types": "0.0.17",
9
+ "@avalabs/vm-module-types": "0.0.18",
10
10
  "@zodios/core": "10.9.6",
11
11
  "@avalabs/coingecko-sdk": "v2.8.0-alpha.193",
12
12
  "@avalabs/utils-sdk": "2.8.0-alpha.193",
@@ -32,7 +32,7 @@
32
32
  "ethers": "6.8.1",
33
33
  "@internal/tsup-config": "0.0.1",
34
34
  "eslint-config-custom": "0.0.1",
35
- "@internal/utils": "0.0.3"
35
+ "@internal/utils": "0.0.4"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "ethers": "^6.8.1"
@@ -223,6 +223,44 @@ describe('ethSign', () => {
223
223
  testWithValidationResultType('Malicious');
224
224
  });
225
225
 
226
+ it('should add alert object with Warning type to displayData when schema validation error occurs in jsonRpc scan', async () => {
227
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
+ (Blockaid as any).mockImplementation(() => ({
229
+ evm: {
230
+ jsonRpc: {
231
+ scan: jest.fn().mockRejectedValue({ message: 'schema validation error' }),
232
+ },
233
+ },
234
+ }));
235
+
236
+ mockParseRequestParams.mockReturnValueOnce({
237
+ success: true,
238
+ data: { method: RpcMethod.ETH_SIGN, data: 'data', address: '0xabc' },
239
+ });
240
+
241
+ const result = await ethSign({
242
+ request: mockRequest,
243
+ network: mockNetwork,
244
+ approvalController: mockApprovalController,
245
+ proxyApiUrl: PROXY_API_URL,
246
+ });
247
+
248
+ expect(result).toEqual({ result: '0x1234' });
249
+ expect(mockApprovalController.requestApproval).toHaveBeenCalledWith(
250
+ expect.objectContaining({
251
+ displayData: expect.objectContaining({
252
+ alert: {
253
+ type: AlertType.WARNING,
254
+ details: {
255
+ title: 'Suspicious Transaction',
256
+ description: 'Use caution, this transaction may be malicious.',
257
+ },
258
+ },
259
+ }),
260
+ }),
261
+ );
262
+ });
263
+
226
264
  it('should handle success case for approvalController.requestApproval', async () => {
227
265
  mockParseRequestParams.mockReturnValueOnce({
228
266
  success: true,
@@ -31,42 +31,31 @@ export const processTransactionSimulation = async ({
31
31
  chainId: number;
32
32
  proxyApiUrl: string;
33
33
  }) => {
34
- const { validation, simulation } = await scanTransaction({
35
- proxyApiUrl,
36
- chainId,
37
- params,
38
- domain: dAppUrl,
39
- });
40
-
41
34
  let alert: Alert | undefined;
42
- if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
43
- alert = {
44
- type: AlertType.WARNING,
45
- details: {
46
- title: 'Suspicious Transaction',
47
- description: 'Use caution, this transaction may be malicious.',
48
- },
49
- };
50
- } else if (validation.result_type === 'Malicious') {
51
- alert = {
52
- type: AlertType.DANGER,
53
- details: {
54
- title: 'Scam Transaction',
55
- description: 'This transaction is malicious, do not proceed.',
56
- actionTitles: {
57
- reject: 'Reject Transaction',
58
- proceed: 'Proceed Anyway',
59
- },
60
- },
61
- };
62
- }
63
-
64
35
  let balanceChange: BalanceChange | undefined;
65
36
  let tokenApprovals: TokenApprovals | undefined;
66
37
 
67
- if (simulation?.status === 'Success') {
68
- tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
69
- balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
38
+ try {
39
+ const { validation, simulation } = await scanTransaction({
40
+ proxyApiUrl,
41
+ chainId,
42
+ params,
43
+ domain: dAppUrl,
44
+ });
45
+
46
+ if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
47
+ alert = transactionAlerts[AlertType.WARNING];
48
+ } else if (validation.result_type === 'Malicious') {
49
+ alert = transactionAlerts[AlertType.DANGER];
50
+ }
51
+
52
+ if (simulation?.status === 'Success') {
53
+ tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
54
+ balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
55
+ }
56
+ } catch (error) {
57
+ console.error('processTransactionSimulation error', error);
58
+ alert = transactionAlerts[AlertType.WARNING];
70
59
  }
71
60
 
72
61
  return { alert, balanceChange, tokenApprovals };
@@ -251,44 +240,54 @@ export const processJsonRpcSimulation = async ({
251
240
  chainId: number;
252
241
  proxyApiUrl: string;
253
242
  }) => {
254
- const { validation, simulation } = await scanJsonRpc({
255
- proxyApiUrl,
256
- chainId,
257
- accountAddress,
258
- data: data as Blockaid.Evm.JsonRpcScanParams.Data,
259
- domain: dAppUrl,
260
- });
261
-
262
243
  let alert: Alert | undefined;
263
- if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
264
- alert = {
265
- type: AlertType.WARNING,
266
- details: {
267
- title: 'Suspicious Transaction',
268
- description: 'Use caution, this transaction may be malicious.',
269
- },
270
- };
271
- } else if (validation.result_type === 'Malicious') {
272
- alert = {
273
- type: AlertType.DANGER,
274
- details: {
275
- title: 'Scam Transaction',
276
- description: 'This transaction is malicious, do not proceed.',
277
- actionTitles: {
278
- reject: 'Reject Transaction',
279
- proceed: 'Proceed Anyway',
280
- },
281
- },
282
- };
283
- }
284
-
285
244
  let balanceChange: BalanceChange | undefined;
286
245
  let tokenApprovals: TokenApprovals | undefined;
287
246
 
288
- if (simulation?.status === 'Success') {
289
- tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
290
- balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
247
+ try {
248
+ const { validation, simulation } = await scanJsonRpc({
249
+ proxyApiUrl,
250
+ chainId,
251
+ accountAddress,
252
+ data: data as Blockaid.Evm.JsonRpcScanParams.Data,
253
+ domain: dAppUrl,
254
+ });
255
+
256
+ if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
257
+ alert = transactionAlerts[AlertType.WARNING];
258
+ } else if (validation.result_type === 'Malicious') {
259
+ alert = transactionAlerts[AlertType.DANGER];
260
+ }
261
+
262
+ if (simulation?.status === 'Success') {
263
+ tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
264
+ balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
265
+ }
266
+ } catch (error) {
267
+ console.error('processJsonRpcSimulation error', error);
268
+ alert = transactionAlerts[AlertType.WARNING];
291
269
  }
292
270
 
293
271
  return { alert, balanceChange, tokenApprovals };
294
272
  };
273
+
274
+ const transactionAlerts = {
275
+ [AlertType.WARNING]: {
276
+ type: AlertType.WARNING,
277
+ details: {
278
+ title: 'Suspicious Transaction',
279
+ description: 'Use caution, this transaction may be malicious.',
280
+ },
281
+ },
282
+ [AlertType.DANGER]: {
283
+ type: AlertType.DANGER,
284
+ details: {
285
+ title: 'Scam Transaction',
286
+ description: 'This transaction is malicious, do not proceed.',
287
+ actionTitles: {
288
+ reject: 'Reject Transaction',
289
+ proceed: 'Proceed Anyway',
290
+ },
291
+ },
292
+ },
293
+ };