@portal-hq/web 3.8.0 → 3.9.0

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,72 @@
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
+ class Blockaid {
13
+ constructor({ mpc }) {
14
+ this.mpc = mpc;
15
+ }
16
+ /**
17
+ * Scans an EVM transaction for security risks using Blockaid.
18
+ * @param params - The parameters for the EVM transaction scan request.
19
+ * @returns A `BlockaidScanEvmTxResponse` promise.
20
+ * @throws An error if the operation fails.
21
+ */
22
+ scanEVMTx(params) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ return this.mpc.blockaidScanEvmTx(params);
25
+ });
26
+ }
27
+ /**
28
+ * Scans a Solana transaction for security risks using Blockaid.
29
+ * @param params - The parameters for the Solana transaction scan request.
30
+ * @returns A `BlockaidScanSolanaTxResponse` promise.
31
+ * @throws An error if the operation fails.
32
+ */
33
+ scanSolanaTx(params) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return this.mpc.blockaidScanSolanaTx(params);
36
+ });
37
+ }
38
+ /**
39
+ * Scans an address for security risks using Blockaid.
40
+ * @param params - The parameters for the address scan request.
41
+ * @returns A `BlockaidAddressScanResponse` promise.
42
+ * @throws An error if the operation fails.
43
+ */
44
+ scanAddress(params) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.mpc.blockaidScanAddress(params);
47
+ });
48
+ }
49
+ /**
50
+ * Scans tokens for security risks using Blockaid.
51
+ * @param params - The parameters for the token scan request.
52
+ * @returns A `BlockaidBulkTokenScanResponse` promise.
53
+ * @throws An error if the operation fails.
54
+ */
55
+ scanTokens(params) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return this.mpc.blockaidScanTokens(params);
58
+ });
59
+ }
60
+ /**
61
+ * Scans a URL for malicious content using Blockaid.
62
+ * @param params - The parameters for the URL scan request.
63
+ * @returns A `BlockaidSiteScanResponse` promise.
64
+ * @throws An error if the operation fails.
65
+ */
66
+ scanURL(params) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ return this.mpc.blockaidScanUrl(params);
69
+ });
70
+ }
71
+ }
72
+ exports.default = Blockaid;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * @jest-environment jsdom
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const _1 = __importDefault(require("."));
19
+ const mpc_1 = __importDefault(require("../../../mpc"));
20
+ const portal_1 = __importDefault(require("../../../__mocks/portal/portal"));
21
+ const constants_1 = require("../../../__mocks/constants");
22
+ describe('Blockaid', () => {
23
+ let blockaid;
24
+ let mpc;
25
+ beforeEach(() => {
26
+ jest.clearAllMocks();
27
+ portal_1.default.host = constants_1.mockHost;
28
+ mpc = new mpc_1.default({
29
+ portal: portal_1.default,
30
+ });
31
+ blockaid = new _1.default({ mpc });
32
+ });
33
+ describe('scanEVMTx', () => {
34
+ it('should call mpc.blockaidScanEvmTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
35
+ const spy = jest
36
+ .spyOn(mpc, 'blockaidScanEvmTx')
37
+ .mockResolvedValue(constants_1.mockBlockaidScanEvmTxResponse);
38
+ const result = yield blockaid.scanEVMTx(constants_1.mockBlockaidScanEvmTxRequest);
39
+ expect(spy).toHaveBeenCalledWith(constants_1.mockBlockaidScanEvmTxRequest);
40
+ expect(result).toEqual(constants_1.mockBlockaidScanEvmTxResponse);
41
+ }));
42
+ it('should propagate errors from mpc.blockaidScanEvmTx', () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const error = new Error('Test error');
44
+ jest.spyOn(mpc, 'blockaidScanEvmTx').mockRejectedValue(error);
45
+ yield expect(blockaid.scanEVMTx(constants_1.mockBlockaidScanEvmTxRequest)).rejects.toThrow('Test error');
46
+ }));
47
+ });
48
+ describe('scanSolanaTx', () => {
49
+ it('should call mpc.blockaidScanSolanaTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const spy = jest
51
+ .spyOn(mpc, 'blockaidScanSolanaTx')
52
+ .mockResolvedValue(constants_1.mockBlockaidScanSolanaTxResponse);
53
+ const result = yield blockaid.scanSolanaTx(constants_1.mockBlockaidScanSolanaTxRequest);
54
+ expect(spy).toHaveBeenCalledWith(constants_1.mockBlockaidScanSolanaTxRequest);
55
+ expect(result).toEqual(constants_1.mockBlockaidScanSolanaTxResponse);
56
+ }));
57
+ it('should propagate errors from mpc.blockaidScanSolanaTx', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ const error = new Error('Test error');
59
+ jest.spyOn(mpc, 'blockaidScanSolanaTx').mockRejectedValue(error);
60
+ yield expect(blockaid.scanSolanaTx(constants_1.mockBlockaidScanSolanaTxRequest)).rejects.toThrow('Test error');
61
+ }));
62
+ });
63
+ describe('scanAddress', () => {
64
+ it('should call mpc.blockaidScanAddress with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
65
+ const spy = jest
66
+ .spyOn(mpc, 'blockaidScanAddress')
67
+ .mockResolvedValue(constants_1.mockBlockaidScanAddressResponse);
68
+ const result = yield blockaid.scanAddress(constants_1.mockBlockaidScanAddressRequest);
69
+ expect(spy).toHaveBeenCalledWith(constants_1.mockBlockaidScanAddressRequest);
70
+ expect(result).toEqual(constants_1.mockBlockaidScanAddressResponse);
71
+ }));
72
+ it('should propagate errors from mpc.blockaidScanAddress', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const error = new Error('Test error');
74
+ jest.spyOn(mpc, 'blockaidScanAddress').mockRejectedValue(error);
75
+ yield expect(blockaid.scanAddress(constants_1.mockBlockaidScanAddressRequest)).rejects.toThrow('Test error');
76
+ }));
77
+ });
78
+ describe('scanTokens', () => {
79
+ it('should call mpc.blockaidScanTokens with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
80
+ const spy = jest
81
+ .spyOn(mpc, 'blockaidScanTokens')
82
+ .mockResolvedValue(constants_1.mockBlockaidScanTokensResponse);
83
+ const result = yield blockaid.scanTokens(constants_1.mockBlockaidScanTokensRequest);
84
+ expect(spy).toHaveBeenCalledWith(constants_1.mockBlockaidScanTokensRequest);
85
+ expect(result).toEqual(constants_1.mockBlockaidScanTokensResponse);
86
+ }));
87
+ it('should propagate errors from mpc.blockaidScanTokens', () => __awaiter(void 0, void 0, void 0, function* () {
88
+ const error = new Error('Test error');
89
+ jest.spyOn(mpc, 'blockaidScanTokens').mockRejectedValue(error);
90
+ yield expect(blockaid.scanTokens(constants_1.mockBlockaidScanTokensRequest)).rejects.toThrow('Test error');
91
+ }));
92
+ });
93
+ describe('scanURL', () => {
94
+ it('should call mpc.blockaidScanUrl with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
95
+ const spy = jest
96
+ .spyOn(mpc, 'blockaidScanUrl')
97
+ .mockResolvedValue(constants_1.mockBlockaidScanUrlResponse);
98
+ const result = yield blockaid.scanURL(constants_1.mockBlockaidScanUrlRequest);
99
+ expect(spy).toHaveBeenCalledWith(constants_1.mockBlockaidScanUrlRequest);
100
+ expect(result).toEqual(constants_1.mockBlockaidScanUrlResponse);
101
+ }));
102
+ it('should propagate errors from mpc.blockaidScanUrl', () => __awaiter(void 0, void 0, void 0, function* () {
103
+ const error = new Error('Test error');
104
+ jest.spyOn(mpc, 'blockaidScanUrl').mockRejectedValue(error);
105
+ yield expect(blockaid.scanURL(constants_1.mockBlockaidScanUrlRequest)).rejects.toThrow('Test error');
106
+ }));
107
+ });
108
+ });
@@ -3,13 +3,15 @@ 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
+ const blockaid_1 = __importDefault(require("./blockaid"));
6
7
  const hypernative_1 = __importDefault(require("./hypernative"));
7
8
  /**
8
- * This class is a container for the Hypernative class.
9
+ * This class is a container for the Hypernative and Blockaid classes.
9
10
  * In the future, Security domain logic should be here.
10
11
  */
11
12
  class Security {
12
13
  constructor({ mpc }) {
14
+ this.blockaid = new blockaid_1.default({ mpc });
13
15
  this.hypernative = new hypernative_1.default({ mpc });
14
16
  }
15
17
  }
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MpcErrorCodes = exports.MpcError = void 0;
13
13
  const errors_1 = require("./errors");
14
14
  const index_1 = require("../index");
15
- const WEB_SDK_VERSION = '3.8.0';
15
+ const WEB_SDK_VERSION = '3.9.0';
16
16
  class Mpc {
17
17
  get ready() {
18
18
  return this._ready;
@@ -597,6 +597,59 @@ class Mpc {
597
597
  });
598
598
  });
599
599
  }
600
+ /*******************************
601
+ * Blockaid Security Methods
602
+ *******************************/
603
+ blockaidScanEvmTx(data) {
604
+ return __awaiter(this, void 0, void 0, function* () {
605
+ return this.handleRequestToIframeAndPost({
606
+ methodMessage: 'portal:blockaid:scanEvmTx',
607
+ errorMessage: 'portal:blockaid:scanEvmTxError',
608
+ resultMessage: 'portal:blockaid:scanEvmTxResult',
609
+ data,
610
+ });
611
+ });
612
+ }
613
+ blockaidScanSolanaTx(data) {
614
+ return __awaiter(this, void 0, void 0, function* () {
615
+ return this.handleRequestToIframeAndPost({
616
+ methodMessage: 'portal:blockaid:scanSolanaTx',
617
+ errorMessage: 'portal:blockaid:scanSolanaTxError',
618
+ resultMessage: 'portal:blockaid:scanSolanaTxResult',
619
+ data,
620
+ });
621
+ });
622
+ }
623
+ blockaidScanAddress(data) {
624
+ return __awaiter(this, void 0, void 0, function* () {
625
+ return this.handleRequestToIframeAndPost({
626
+ methodMessage: 'portal:blockaid:scanAddress',
627
+ errorMessage: 'portal:blockaid:scanAddressError',
628
+ resultMessage: 'portal:blockaid:scanAddressResult',
629
+ data,
630
+ });
631
+ });
632
+ }
633
+ blockaidScanTokens(data) {
634
+ return __awaiter(this, void 0, void 0, function* () {
635
+ return this.handleRequestToIframeAndPost({
636
+ methodMessage: 'portal:blockaid:scanTokens',
637
+ errorMessage: 'portal:blockaid:scanTokensError',
638
+ resultMessage: 'portal:blockaid:scanTokensResult',
639
+ data,
640
+ });
641
+ });
642
+ }
643
+ blockaidScanUrl(data) {
644
+ return __awaiter(this, void 0, void 0, function* () {
645
+ return this.handleRequestToIframeAndPost({
646
+ methodMessage: 'portal:blockaid:scanUrl',
647
+ errorMessage: 'portal:blockaid:scanUrlError',
648
+ resultMessage: 'portal:blockaid:scanUrlResult',
649
+ data,
650
+ });
651
+ });
652
+ }
600
653
  /***************************
601
654
  * Private Methods
602
655
  ***************************/
@@ -3287,4 +3287,332 @@ describe('Mpc', () => {
3287
3287
  });
3288
3288
  });
3289
3289
  });
3290
+ /*******************************
3291
+ * Blockaid Security Methods Tests
3292
+ *******************************/
3293
+ describe('blockaidScanEvmTx', () => {
3294
+ const args = constants_1.mockBlockaidScanEvmTxRequest;
3295
+ const res = constants_1.mockBlockaidScanEvmTxResponse;
3296
+ it('should successfully scan EVM transaction with Blockaid', (done) => {
3297
+ var _a;
3298
+ jest
3299
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3300
+ .mockImplementation((message, origin) => {
3301
+ const { type, data } = message;
3302
+ expect(type).toEqual('portal:blockaid:scanEvmTx');
3303
+ expect(data).toEqual(args);
3304
+ expect(origin).toEqual(mockHostOrigin);
3305
+ window.dispatchEvent(new MessageEvent('message', {
3306
+ origin: mockHostOrigin,
3307
+ data: {
3308
+ type: 'portal:blockaid:scanEvmTxResult',
3309
+ data: res,
3310
+ },
3311
+ }));
3312
+ });
3313
+ mpc
3314
+ .blockaidScanEvmTx(args)
3315
+ .then((data) => {
3316
+ expect(data).toEqual(res);
3317
+ done();
3318
+ })
3319
+ .catch((_) => {
3320
+ expect(0).toEqual(1);
3321
+ done();
3322
+ });
3323
+ });
3324
+ it('should error out if the iframe sends an error message', (done) => {
3325
+ var _a;
3326
+ jest
3327
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3328
+ .mockImplementationOnce((message, origin) => {
3329
+ const { type, data } = message;
3330
+ expect(type).toEqual('portal:blockaid:scanEvmTx');
3331
+ expect(data).toEqual(args);
3332
+ expect(origin).toEqual(mockHostOrigin);
3333
+ window.dispatchEvent(new MessageEvent('message', {
3334
+ origin: mockHostOrigin,
3335
+ data: {
3336
+ type: 'portal:blockaid:scanEvmTxError',
3337
+ data: {
3338
+ code: 1,
3339
+ message: 'test',
3340
+ },
3341
+ },
3342
+ }));
3343
+ });
3344
+ mpc
3345
+ .blockaidScanEvmTx(args)
3346
+ .then(() => {
3347
+ expect(0).toEqual(1);
3348
+ done();
3349
+ })
3350
+ .catch((e) => {
3351
+ expect(e).toBeInstanceOf(errors_1.PortalMpcError);
3352
+ expect(e.message).toEqual('test');
3353
+ expect(e.code).toEqual(1);
3354
+ done();
3355
+ });
3356
+ });
3357
+ });
3358
+ describe('blockaidScanSolanaTx', () => {
3359
+ const args = constants_1.mockBlockaidScanSolanaTxRequest;
3360
+ const res = constants_1.mockBlockaidScanSolanaTxResponse;
3361
+ it('should successfully scan Solana transaction with Blockaid', (done) => {
3362
+ var _a;
3363
+ jest
3364
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3365
+ .mockImplementation((message, origin) => {
3366
+ const { type, data } = message;
3367
+ expect(type).toEqual('portal:blockaid:scanSolanaTx');
3368
+ expect(data).toEqual(args);
3369
+ expect(origin).toEqual(mockHostOrigin);
3370
+ window.dispatchEvent(new MessageEvent('message', {
3371
+ origin: mockHostOrigin,
3372
+ data: {
3373
+ type: 'portal:blockaid:scanSolanaTxResult',
3374
+ data: res,
3375
+ },
3376
+ }));
3377
+ });
3378
+ mpc
3379
+ .blockaidScanSolanaTx(args)
3380
+ .then((data) => {
3381
+ expect(data).toEqual(res);
3382
+ done();
3383
+ })
3384
+ .catch((_) => {
3385
+ expect(0).toEqual(1);
3386
+ done();
3387
+ });
3388
+ });
3389
+ it('should error out if the iframe sends an error message', (done) => {
3390
+ var _a;
3391
+ jest
3392
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3393
+ .mockImplementationOnce((message, origin) => {
3394
+ const { type, data } = message;
3395
+ expect(type).toEqual('portal:blockaid:scanSolanaTx');
3396
+ expect(data).toEqual(args);
3397
+ expect(origin).toEqual(mockHostOrigin);
3398
+ window.dispatchEvent(new MessageEvent('message', {
3399
+ origin: mockHostOrigin,
3400
+ data: {
3401
+ type: 'portal:blockaid:scanSolanaTxError',
3402
+ data: {
3403
+ code: 1,
3404
+ message: 'test',
3405
+ },
3406
+ },
3407
+ }));
3408
+ });
3409
+ mpc
3410
+ .blockaidScanSolanaTx(args)
3411
+ .then(() => {
3412
+ expect(0).toEqual(1);
3413
+ done();
3414
+ })
3415
+ .catch((e) => {
3416
+ expect(e).toBeInstanceOf(errors_1.PortalMpcError);
3417
+ expect(e.message).toEqual('test');
3418
+ expect(e.code).toEqual(1);
3419
+ done();
3420
+ });
3421
+ });
3422
+ });
3423
+ describe('blockaidScanAddress', () => {
3424
+ const args = constants_1.mockBlockaidScanAddressRequest;
3425
+ const res = constants_1.mockBlockaidScanAddressResponse;
3426
+ it('should successfully scan address with Blockaid', (done) => {
3427
+ var _a;
3428
+ jest
3429
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3430
+ .mockImplementation((message, origin) => {
3431
+ const { type, data } = message;
3432
+ expect(type).toEqual('portal:blockaid:scanAddress');
3433
+ expect(data).toEqual(args);
3434
+ expect(origin).toEqual(mockHostOrigin);
3435
+ window.dispatchEvent(new MessageEvent('message', {
3436
+ origin: mockHostOrigin,
3437
+ data: {
3438
+ type: 'portal:blockaid:scanAddressResult',
3439
+ data: res,
3440
+ },
3441
+ }));
3442
+ });
3443
+ mpc
3444
+ .blockaidScanAddress(args)
3445
+ .then((data) => {
3446
+ expect(data).toEqual(res);
3447
+ done();
3448
+ })
3449
+ .catch((_) => {
3450
+ expect(0).toEqual(1);
3451
+ done();
3452
+ });
3453
+ });
3454
+ it('should error out if the iframe sends an error message', (done) => {
3455
+ var _a;
3456
+ jest
3457
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3458
+ .mockImplementationOnce((message, origin) => {
3459
+ const { type, data } = message;
3460
+ expect(type).toEqual('portal:blockaid:scanAddress');
3461
+ expect(data).toEqual(args);
3462
+ expect(origin).toEqual(mockHostOrigin);
3463
+ window.dispatchEvent(new MessageEvent('message', {
3464
+ origin: mockHostOrigin,
3465
+ data: {
3466
+ type: 'portal:blockaid:scanAddressError',
3467
+ data: {
3468
+ code: 1,
3469
+ message: 'test',
3470
+ },
3471
+ },
3472
+ }));
3473
+ });
3474
+ mpc
3475
+ .blockaidScanAddress(args)
3476
+ .then(() => {
3477
+ expect(0).toEqual(1);
3478
+ done();
3479
+ })
3480
+ .catch((e) => {
3481
+ expect(e).toBeInstanceOf(errors_1.PortalMpcError);
3482
+ expect(e.message).toEqual('test');
3483
+ expect(e.code).toEqual(1);
3484
+ done();
3485
+ });
3486
+ });
3487
+ });
3488
+ describe('blockaidScanTokens', () => {
3489
+ const args = constants_1.mockBlockaidScanTokensRequest;
3490
+ const res = constants_1.mockBlockaidScanTokensResponse;
3491
+ it('should successfully scan tokens with Blockaid', (done) => {
3492
+ var _a;
3493
+ jest
3494
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3495
+ .mockImplementation((message, origin) => {
3496
+ const { type, data } = message;
3497
+ expect(type).toEqual('portal:blockaid:scanTokens');
3498
+ expect(data).toEqual(args);
3499
+ expect(origin).toEqual(mockHostOrigin);
3500
+ window.dispatchEvent(new MessageEvent('message', {
3501
+ origin: mockHostOrigin,
3502
+ data: {
3503
+ type: 'portal:blockaid:scanTokensResult',
3504
+ data: res,
3505
+ },
3506
+ }));
3507
+ });
3508
+ mpc
3509
+ .blockaidScanTokens(args)
3510
+ .then((data) => {
3511
+ expect(data).toEqual(res);
3512
+ done();
3513
+ })
3514
+ .catch((_) => {
3515
+ expect(0).toEqual(1);
3516
+ done();
3517
+ });
3518
+ });
3519
+ it('should error out if the iframe sends an error message', (done) => {
3520
+ var _a;
3521
+ jest
3522
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3523
+ .mockImplementationOnce((message, origin) => {
3524
+ const { type, data } = message;
3525
+ expect(type).toEqual('portal:blockaid:scanTokens');
3526
+ expect(data).toEqual(args);
3527
+ expect(origin).toEqual(mockHostOrigin);
3528
+ window.dispatchEvent(new MessageEvent('message', {
3529
+ origin: mockHostOrigin,
3530
+ data: {
3531
+ type: 'portal:blockaid:scanTokensError',
3532
+ data: {
3533
+ code: 1,
3534
+ message: 'test',
3535
+ },
3536
+ },
3537
+ }));
3538
+ });
3539
+ mpc
3540
+ .blockaidScanTokens(args)
3541
+ .then(() => {
3542
+ expect(0).toEqual(1);
3543
+ done();
3544
+ })
3545
+ .catch((e) => {
3546
+ expect(e).toBeInstanceOf(errors_1.PortalMpcError);
3547
+ expect(e.message).toEqual('test');
3548
+ expect(e.code).toEqual(1);
3549
+ done();
3550
+ });
3551
+ });
3552
+ });
3553
+ describe('blockaidScanUrl', () => {
3554
+ const args = constants_1.mockBlockaidScanUrlRequest;
3555
+ const res = constants_1.mockBlockaidScanUrlResponse;
3556
+ it('should successfully scan URL with Blockaid', (done) => {
3557
+ var _a;
3558
+ jest
3559
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3560
+ .mockImplementation((message, origin) => {
3561
+ const { type, data } = message;
3562
+ expect(type).toEqual('portal:blockaid:scanUrl');
3563
+ expect(data).toEqual(args);
3564
+ expect(origin).toEqual(mockHostOrigin);
3565
+ window.dispatchEvent(new MessageEvent('message', {
3566
+ origin: mockHostOrigin,
3567
+ data: {
3568
+ type: 'portal:blockaid:scanUrlResult',
3569
+ data: res,
3570
+ },
3571
+ }));
3572
+ });
3573
+ mpc
3574
+ .blockaidScanUrl(args)
3575
+ .then((data) => {
3576
+ expect(data).toEqual(res);
3577
+ done();
3578
+ })
3579
+ .catch((_) => {
3580
+ expect(0).toEqual(1);
3581
+ done();
3582
+ });
3583
+ });
3584
+ it('should error out if the iframe sends an error message', (done) => {
3585
+ var _a;
3586
+ jest
3587
+ .spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
3588
+ .mockImplementationOnce((message, origin) => {
3589
+ const { type, data } = message;
3590
+ expect(type).toEqual('portal:blockaid:scanUrl');
3591
+ expect(data).toEqual(args);
3592
+ expect(origin).toEqual(mockHostOrigin);
3593
+ window.dispatchEvent(new MessageEvent('message', {
3594
+ origin: mockHostOrigin,
3595
+ data: {
3596
+ type: 'portal:blockaid:scanUrlError',
3597
+ data: {
3598
+ code: 1,
3599
+ message: 'test',
3600
+ },
3601
+ },
3602
+ }));
3603
+ });
3604
+ mpc
3605
+ .blockaidScanUrl(args)
3606
+ .then(() => {
3607
+ expect(0).toEqual(1);
3608
+ done();
3609
+ })
3610
+ .catch((e) => {
3611
+ expect(e).toBeInstanceOf(errors_1.PortalMpcError);
3612
+ expect(e.message).toEqual('test');
3613
+ expect(e.code).toEqual(1);
3614
+ done();
3615
+ });
3616
+ });
3617
+ });
3290
3618
  });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Blockaid integration types
4
+ *
5
+ * Types for Blockaid security scanning and validation services
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -28,3 +28,4 @@ __exportStar(require("./yieldxyz"), exports);
28
28
  __exportStar(require("./zero-x"), exports);
29
29
  __exportStar(require("./lifi"), exports);
30
30
  __exportStar(require("./hypernative"), exports);
31
+ __exportStar(require("./blockaid"), exports);
@@ -0,0 +1,69 @@
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
+ export default class Blockaid {
11
+ constructor({ mpc }) {
12
+ this.mpc = mpc;
13
+ }
14
+ /**
15
+ * Scans an EVM transaction for security risks using Blockaid.
16
+ * @param params - The parameters for the EVM transaction scan request.
17
+ * @returns A `BlockaidScanEvmTxResponse` promise.
18
+ * @throws An error if the operation fails.
19
+ */
20
+ scanEVMTx(params) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.mpc.blockaidScanEvmTx(params);
23
+ });
24
+ }
25
+ /**
26
+ * Scans a Solana transaction for security risks using Blockaid.
27
+ * @param params - The parameters for the Solana transaction scan request.
28
+ * @returns A `BlockaidScanSolanaTxResponse` promise.
29
+ * @throws An error if the operation fails.
30
+ */
31
+ scanSolanaTx(params) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this.mpc.blockaidScanSolanaTx(params);
34
+ });
35
+ }
36
+ /**
37
+ * Scans an address for security risks using Blockaid.
38
+ * @param params - The parameters for the address scan request.
39
+ * @returns A `BlockaidAddressScanResponse` promise.
40
+ * @throws An error if the operation fails.
41
+ */
42
+ scanAddress(params) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return this.mpc.blockaidScanAddress(params);
45
+ });
46
+ }
47
+ /**
48
+ * Scans tokens for security risks using Blockaid.
49
+ * @param params - The parameters for the token scan request.
50
+ * @returns A `BlockaidBulkTokenScanResponse` promise.
51
+ * @throws An error if the operation fails.
52
+ */
53
+ scanTokens(params) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return this.mpc.blockaidScanTokens(params);
56
+ });
57
+ }
58
+ /**
59
+ * Scans a URL for malicious content using Blockaid.
60
+ * @param params - The parameters for the URL scan request.
61
+ * @returns A `BlockaidSiteScanResponse` promise.
62
+ * @throws An error if the operation fails.
63
+ */
64
+ scanURL(params) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ return this.mpc.blockaidScanUrl(params);
67
+ });
68
+ }
69
+ }