@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.
- package/lib/commonjs/integrations/security/blockaid/index.js +72 -0
- package/lib/commonjs/integrations/security/blockaid/index.test.js +108 -0
- package/lib/commonjs/integrations/security/index.js +3 -1
- package/lib/commonjs/mpc/index.js +54 -1
- package/lib/commonjs/mpc/index.test.js +328 -0
- package/lib/commonjs/shared/types/blockaid.js +7 -0
- package/lib/commonjs/shared/types/index.js +1 -0
- package/lib/esm/integrations/security/blockaid/index.js +69 -0
- package/lib/esm/integrations/security/blockaid/index.test.js +103 -0
- package/lib/esm/integrations/security/index.js +3 -1
- package/lib/esm/mpc/index.js +54 -1
- package/lib/esm/mpc/index.test.js +329 -1
- package/lib/esm/shared/types/blockaid.js +6 -0
- package/lib/esm/shared/types/index.js +1 -0
- package/package.json +2 -2
- package/src/__mocks/constants.ts +203 -0
- package/src/integrations/security/blockaid/index.test.ts +146 -0
- package/src/integrations/security/blockaid/index.ts +81 -0
- package/src/integrations/security/index.ts +4 -1
- package/src/mpc/index.test.ts +394 -0
- package/src/mpc/index.ts +70 -1
- package/src/shared/types/blockaid.ts +530 -0
- package/src/shared/types/index.ts +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
import Blockaid from '.';
|
|
14
|
+
import Mpc from '../../../mpc';
|
|
15
|
+
import portalMock from '../../../__mocks/portal/portal';
|
|
16
|
+
import { mockHost, mockBlockaidScanEvmTxRequest, mockBlockaidScanEvmTxResponse, mockBlockaidScanSolanaTxRequest, mockBlockaidScanSolanaTxResponse, mockBlockaidScanAddressRequest, mockBlockaidScanAddressResponse, mockBlockaidScanTokensRequest, mockBlockaidScanTokensResponse, mockBlockaidScanUrlRequest, mockBlockaidScanUrlResponse, } from '../../../__mocks/constants';
|
|
17
|
+
describe('Blockaid', () => {
|
|
18
|
+
let blockaid;
|
|
19
|
+
let mpc;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
portalMock.host = mockHost;
|
|
23
|
+
mpc = new Mpc({
|
|
24
|
+
portal: portalMock,
|
|
25
|
+
});
|
|
26
|
+
blockaid = new Blockaid({ mpc });
|
|
27
|
+
});
|
|
28
|
+
describe('scanEVMTx', () => {
|
|
29
|
+
it('should call mpc.blockaidScanEvmTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const spy = jest
|
|
31
|
+
.spyOn(mpc, 'blockaidScanEvmTx')
|
|
32
|
+
.mockResolvedValue(mockBlockaidScanEvmTxResponse);
|
|
33
|
+
const result = yield blockaid.scanEVMTx(mockBlockaidScanEvmTxRequest);
|
|
34
|
+
expect(spy).toHaveBeenCalledWith(mockBlockaidScanEvmTxRequest);
|
|
35
|
+
expect(result).toEqual(mockBlockaidScanEvmTxResponse);
|
|
36
|
+
}));
|
|
37
|
+
it('should propagate errors from mpc.blockaidScanEvmTx', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const error = new Error('Test error');
|
|
39
|
+
jest.spyOn(mpc, 'blockaidScanEvmTx').mockRejectedValue(error);
|
|
40
|
+
yield expect(blockaid.scanEVMTx(mockBlockaidScanEvmTxRequest)).rejects.toThrow('Test error');
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
describe('scanSolanaTx', () => {
|
|
44
|
+
it('should call mpc.blockaidScanSolanaTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const spy = jest
|
|
46
|
+
.spyOn(mpc, 'blockaidScanSolanaTx')
|
|
47
|
+
.mockResolvedValue(mockBlockaidScanSolanaTxResponse);
|
|
48
|
+
const result = yield blockaid.scanSolanaTx(mockBlockaidScanSolanaTxRequest);
|
|
49
|
+
expect(spy).toHaveBeenCalledWith(mockBlockaidScanSolanaTxRequest);
|
|
50
|
+
expect(result).toEqual(mockBlockaidScanSolanaTxResponse);
|
|
51
|
+
}));
|
|
52
|
+
it('should propagate errors from mpc.blockaidScanSolanaTx', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const error = new Error('Test error');
|
|
54
|
+
jest.spyOn(mpc, 'blockaidScanSolanaTx').mockRejectedValue(error);
|
|
55
|
+
yield expect(blockaid.scanSolanaTx(mockBlockaidScanSolanaTxRequest)).rejects.toThrow('Test error');
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
describe('scanAddress', () => {
|
|
59
|
+
it('should call mpc.blockaidScanAddress with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const spy = jest
|
|
61
|
+
.spyOn(mpc, 'blockaidScanAddress')
|
|
62
|
+
.mockResolvedValue(mockBlockaidScanAddressResponse);
|
|
63
|
+
const result = yield blockaid.scanAddress(mockBlockaidScanAddressRequest);
|
|
64
|
+
expect(spy).toHaveBeenCalledWith(mockBlockaidScanAddressRequest);
|
|
65
|
+
expect(result).toEqual(mockBlockaidScanAddressResponse);
|
|
66
|
+
}));
|
|
67
|
+
it('should propagate errors from mpc.blockaidScanAddress', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const error = new Error('Test error');
|
|
69
|
+
jest.spyOn(mpc, 'blockaidScanAddress').mockRejectedValue(error);
|
|
70
|
+
yield expect(blockaid.scanAddress(mockBlockaidScanAddressRequest)).rejects.toThrow('Test error');
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
describe('scanTokens', () => {
|
|
74
|
+
it('should call mpc.blockaidScanTokens with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const spy = jest
|
|
76
|
+
.spyOn(mpc, 'blockaidScanTokens')
|
|
77
|
+
.mockResolvedValue(mockBlockaidScanTokensResponse);
|
|
78
|
+
const result = yield blockaid.scanTokens(mockBlockaidScanTokensRequest);
|
|
79
|
+
expect(spy).toHaveBeenCalledWith(mockBlockaidScanTokensRequest);
|
|
80
|
+
expect(result).toEqual(mockBlockaidScanTokensResponse);
|
|
81
|
+
}));
|
|
82
|
+
it('should propagate errors from mpc.blockaidScanTokens', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const error = new Error('Test error');
|
|
84
|
+
jest.spyOn(mpc, 'blockaidScanTokens').mockRejectedValue(error);
|
|
85
|
+
yield expect(blockaid.scanTokens(mockBlockaidScanTokensRequest)).rejects.toThrow('Test error');
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
describe('scanURL', () => {
|
|
89
|
+
it('should call mpc.blockaidScanUrl with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const spy = jest
|
|
91
|
+
.spyOn(mpc, 'blockaidScanUrl')
|
|
92
|
+
.mockResolvedValue(mockBlockaidScanUrlResponse);
|
|
93
|
+
const result = yield blockaid.scanURL(mockBlockaidScanUrlRequest);
|
|
94
|
+
expect(spy).toHaveBeenCalledWith(mockBlockaidScanUrlRequest);
|
|
95
|
+
expect(result).toEqual(mockBlockaidScanUrlResponse);
|
|
96
|
+
}));
|
|
97
|
+
it('should propagate errors from mpc.blockaidScanUrl', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const error = new Error('Test error');
|
|
99
|
+
jest.spyOn(mpc, 'blockaidScanUrl').mockRejectedValue(error);
|
|
100
|
+
yield expect(blockaid.scanURL(mockBlockaidScanUrlRequest)).rejects.toThrow('Test error');
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import Blockaid from './blockaid';
|
|
1
2
|
import Hypernative from './hypernative';
|
|
2
3
|
/**
|
|
3
|
-
* This class is a container for the Hypernative
|
|
4
|
+
* This class is a container for the Hypernative and Blockaid classes.
|
|
4
5
|
* In the future, Security domain logic should be here.
|
|
5
6
|
*/
|
|
6
7
|
export default class Security {
|
|
7
8
|
constructor({ mpc }) {
|
|
9
|
+
this.blockaid = new Blockaid({ mpc });
|
|
8
10
|
this.hypernative = new Hypernative({ mpc });
|
|
9
11
|
}
|
|
10
12
|
}
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PortalMpcError } from './errors';
|
|
11
11
|
import { BackupMethods, } from '../index';
|
|
12
|
-
const WEB_SDK_VERSION = '3.
|
|
12
|
+
const WEB_SDK_VERSION = '3.9.0';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -594,6 +594,59 @@ class Mpc {
|
|
|
594
594
|
});
|
|
595
595
|
});
|
|
596
596
|
}
|
|
597
|
+
/*******************************
|
|
598
|
+
* Blockaid Security Methods
|
|
599
|
+
*******************************/
|
|
600
|
+
blockaidScanEvmTx(data) {
|
|
601
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
602
|
+
return this.handleRequestToIframeAndPost({
|
|
603
|
+
methodMessage: 'portal:blockaid:scanEvmTx',
|
|
604
|
+
errorMessage: 'portal:blockaid:scanEvmTxError',
|
|
605
|
+
resultMessage: 'portal:blockaid:scanEvmTxResult',
|
|
606
|
+
data,
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
blockaidScanSolanaTx(data) {
|
|
611
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
612
|
+
return this.handleRequestToIframeAndPost({
|
|
613
|
+
methodMessage: 'portal:blockaid:scanSolanaTx',
|
|
614
|
+
errorMessage: 'portal:blockaid:scanSolanaTxError',
|
|
615
|
+
resultMessage: 'portal:blockaid:scanSolanaTxResult',
|
|
616
|
+
data,
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
blockaidScanAddress(data) {
|
|
621
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
622
|
+
return this.handleRequestToIframeAndPost({
|
|
623
|
+
methodMessage: 'portal:blockaid:scanAddress',
|
|
624
|
+
errorMessage: 'portal:blockaid:scanAddressError',
|
|
625
|
+
resultMessage: 'portal:blockaid:scanAddressResult',
|
|
626
|
+
data,
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
blockaidScanTokens(data) {
|
|
631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
632
|
+
return this.handleRequestToIframeAndPost({
|
|
633
|
+
methodMessage: 'portal:blockaid:scanTokens',
|
|
634
|
+
errorMessage: 'portal:blockaid:scanTokensError',
|
|
635
|
+
resultMessage: 'portal:blockaid:scanTokensResult',
|
|
636
|
+
data,
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
blockaidScanUrl(data) {
|
|
641
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
642
|
+
return this.handleRequestToIframeAndPost({
|
|
643
|
+
methodMessage: 'portal:blockaid:scanUrl',
|
|
644
|
+
errorMessage: 'portal:blockaid:scanUrlError',
|
|
645
|
+
resultMessage: 'portal:blockaid:scanUrlResult',
|
|
646
|
+
data,
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
}
|
|
597
650
|
/***************************
|
|
598
651
|
* Private Methods
|
|
599
652
|
***************************/
|
|
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
};
|
|
13
13
|
import { BackupMethods, MpcStatuses, PortalCurve } from '../index';
|
|
14
14
|
import Mpc from '.';
|
|
15
|
-
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, mockZeroExQuoteV2Request, mockZeroExQuoteV2Response, mockZeroExSourcesV2Request, mockZeroExSourcesV2Response, mockZeroExPriceRequest, mockZeroExPriceResponse, mockZeroExOptions, mockScanAddressesRequest, mockScanAddressesResponse, mockScanEVMTxRequest, mockScanEVMTxResponse, mockScanEip712TxRequest, mockScanEip712TxResponse, mockScanSolanaTxRequest, mockScanSolanaTxResponse, mockScanNftRequest, mockScanNftResponse, mockScanTokenRequest, mockScanTokenResponse, mockScanUrlRequest, mockScanUrlResponse, } from '../__mocks/constants';
|
|
15
|
+
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, mockZeroExQuoteV2Request, mockZeroExQuoteV2Response, mockZeroExSourcesV2Request, mockZeroExSourcesV2Response, mockZeroExPriceRequest, mockZeroExPriceResponse, mockZeroExOptions, mockScanAddressesRequest, mockScanAddressesResponse, mockScanEVMTxRequest, mockScanEVMTxResponse, mockScanEip712TxRequest, mockScanEip712TxResponse, mockScanSolanaTxRequest, mockScanSolanaTxResponse, mockScanNftRequest, mockScanNftResponse, mockScanTokenRequest, mockScanTokenResponse, mockScanUrlRequest, mockScanUrlResponse, mockBlockaidScanEvmTxRequest, mockBlockaidScanEvmTxResponse, mockBlockaidScanSolanaTxRequest, mockBlockaidScanSolanaTxResponse, mockBlockaidScanAddressRequest, mockBlockaidScanAddressResponse, mockBlockaidScanTokensRequest, mockBlockaidScanTokensResponse, mockBlockaidScanUrlRequest, mockBlockaidScanUrlResponse, } from '../__mocks/constants';
|
|
16
16
|
import portalMock from '../__mocks/portal/portal';
|
|
17
17
|
import { PortalMpcError } from './errors';
|
|
18
18
|
describe('Mpc', () => {
|
|
@@ -3282,4 +3282,332 @@ describe('Mpc', () => {
|
|
|
3282
3282
|
});
|
|
3283
3283
|
});
|
|
3284
3284
|
});
|
|
3285
|
+
/*******************************
|
|
3286
|
+
* Blockaid Security Methods Tests
|
|
3287
|
+
*******************************/
|
|
3288
|
+
describe('blockaidScanEvmTx', () => {
|
|
3289
|
+
const args = mockBlockaidScanEvmTxRequest;
|
|
3290
|
+
const res = mockBlockaidScanEvmTxResponse;
|
|
3291
|
+
it('should successfully scan EVM transaction with Blockaid', (done) => {
|
|
3292
|
+
var _a;
|
|
3293
|
+
jest
|
|
3294
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3295
|
+
.mockImplementation((message, origin) => {
|
|
3296
|
+
const { type, data } = message;
|
|
3297
|
+
expect(type).toEqual('portal:blockaid:scanEvmTx');
|
|
3298
|
+
expect(data).toEqual(args);
|
|
3299
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3300
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3301
|
+
origin: mockHostOrigin,
|
|
3302
|
+
data: {
|
|
3303
|
+
type: 'portal:blockaid:scanEvmTxResult',
|
|
3304
|
+
data: res,
|
|
3305
|
+
},
|
|
3306
|
+
}));
|
|
3307
|
+
});
|
|
3308
|
+
mpc
|
|
3309
|
+
.blockaidScanEvmTx(args)
|
|
3310
|
+
.then((data) => {
|
|
3311
|
+
expect(data).toEqual(res);
|
|
3312
|
+
done();
|
|
3313
|
+
})
|
|
3314
|
+
.catch((_) => {
|
|
3315
|
+
expect(0).toEqual(1);
|
|
3316
|
+
done();
|
|
3317
|
+
});
|
|
3318
|
+
});
|
|
3319
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3320
|
+
var _a;
|
|
3321
|
+
jest
|
|
3322
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3323
|
+
.mockImplementationOnce((message, origin) => {
|
|
3324
|
+
const { type, data } = message;
|
|
3325
|
+
expect(type).toEqual('portal:blockaid:scanEvmTx');
|
|
3326
|
+
expect(data).toEqual(args);
|
|
3327
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3328
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3329
|
+
origin: mockHostOrigin,
|
|
3330
|
+
data: {
|
|
3331
|
+
type: 'portal:blockaid:scanEvmTxError',
|
|
3332
|
+
data: {
|
|
3333
|
+
code: 1,
|
|
3334
|
+
message: 'test',
|
|
3335
|
+
},
|
|
3336
|
+
},
|
|
3337
|
+
}));
|
|
3338
|
+
});
|
|
3339
|
+
mpc
|
|
3340
|
+
.blockaidScanEvmTx(args)
|
|
3341
|
+
.then(() => {
|
|
3342
|
+
expect(0).toEqual(1);
|
|
3343
|
+
done();
|
|
3344
|
+
})
|
|
3345
|
+
.catch((e) => {
|
|
3346
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3347
|
+
expect(e.message).toEqual('test');
|
|
3348
|
+
expect(e.code).toEqual(1);
|
|
3349
|
+
done();
|
|
3350
|
+
});
|
|
3351
|
+
});
|
|
3352
|
+
});
|
|
3353
|
+
describe('blockaidScanSolanaTx', () => {
|
|
3354
|
+
const args = mockBlockaidScanSolanaTxRequest;
|
|
3355
|
+
const res = mockBlockaidScanSolanaTxResponse;
|
|
3356
|
+
it('should successfully scan Solana transaction with Blockaid', (done) => {
|
|
3357
|
+
var _a;
|
|
3358
|
+
jest
|
|
3359
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3360
|
+
.mockImplementation((message, origin) => {
|
|
3361
|
+
const { type, data } = message;
|
|
3362
|
+
expect(type).toEqual('portal:blockaid:scanSolanaTx');
|
|
3363
|
+
expect(data).toEqual(args);
|
|
3364
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3365
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3366
|
+
origin: mockHostOrigin,
|
|
3367
|
+
data: {
|
|
3368
|
+
type: 'portal:blockaid:scanSolanaTxResult',
|
|
3369
|
+
data: res,
|
|
3370
|
+
},
|
|
3371
|
+
}));
|
|
3372
|
+
});
|
|
3373
|
+
mpc
|
|
3374
|
+
.blockaidScanSolanaTx(args)
|
|
3375
|
+
.then((data) => {
|
|
3376
|
+
expect(data).toEqual(res);
|
|
3377
|
+
done();
|
|
3378
|
+
})
|
|
3379
|
+
.catch((_) => {
|
|
3380
|
+
expect(0).toEqual(1);
|
|
3381
|
+
done();
|
|
3382
|
+
});
|
|
3383
|
+
});
|
|
3384
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3385
|
+
var _a;
|
|
3386
|
+
jest
|
|
3387
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3388
|
+
.mockImplementationOnce((message, origin) => {
|
|
3389
|
+
const { type, data } = message;
|
|
3390
|
+
expect(type).toEqual('portal:blockaid:scanSolanaTx');
|
|
3391
|
+
expect(data).toEqual(args);
|
|
3392
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3393
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3394
|
+
origin: mockHostOrigin,
|
|
3395
|
+
data: {
|
|
3396
|
+
type: 'portal:blockaid:scanSolanaTxError',
|
|
3397
|
+
data: {
|
|
3398
|
+
code: 1,
|
|
3399
|
+
message: 'test',
|
|
3400
|
+
},
|
|
3401
|
+
},
|
|
3402
|
+
}));
|
|
3403
|
+
});
|
|
3404
|
+
mpc
|
|
3405
|
+
.blockaidScanSolanaTx(args)
|
|
3406
|
+
.then(() => {
|
|
3407
|
+
expect(0).toEqual(1);
|
|
3408
|
+
done();
|
|
3409
|
+
})
|
|
3410
|
+
.catch((e) => {
|
|
3411
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3412
|
+
expect(e.message).toEqual('test');
|
|
3413
|
+
expect(e.code).toEqual(1);
|
|
3414
|
+
done();
|
|
3415
|
+
});
|
|
3416
|
+
});
|
|
3417
|
+
});
|
|
3418
|
+
describe('blockaidScanAddress', () => {
|
|
3419
|
+
const args = mockBlockaidScanAddressRequest;
|
|
3420
|
+
const res = mockBlockaidScanAddressResponse;
|
|
3421
|
+
it('should successfully scan address with Blockaid', (done) => {
|
|
3422
|
+
var _a;
|
|
3423
|
+
jest
|
|
3424
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3425
|
+
.mockImplementation((message, origin) => {
|
|
3426
|
+
const { type, data } = message;
|
|
3427
|
+
expect(type).toEqual('portal:blockaid:scanAddress');
|
|
3428
|
+
expect(data).toEqual(args);
|
|
3429
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3430
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3431
|
+
origin: mockHostOrigin,
|
|
3432
|
+
data: {
|
|
3433
|
+
type: 'portal:blockaid:scanAddressResult',
|
|
3434
|
+
data: res,
|
|
3435
|
+
},
|
|
3436
|
+
}));
|
|
3437
|
+
});
|
|
3438
|
+
mpc
|
|
3439
|
+
.blockaidScanAddress(args)
|
|
3440
|
+
.then((data) => {
|
|
3441
|
+
expect(data).toEqual(res);
|
|
3442
|
+
done();
|
|
3443
|
+
})
|
|
3444
|
+
.catch((_) => {
|
|
3445
|
+
expect(0).toEqual(1);
|
|
3446
|
+
done();
|
|
3447
|
+
});
|
|
3448
|
+
});
|
|
3449
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3450
|
+
var _a;
|
|
3451
|
+
jest
|
|
3452
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3453
|
+
.mockImplementationOnce((message, origin) => {
|
|
3454
|
+
const { type, data } = message;
|
|
3455
|
+
expect(type).toEqual('portal:blockaid:scanAddress');
|
|
3456
|
+
expect(data).toEqual(args);
|
|
3457
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3458
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3459
|
+
origin: mockHostOrigin,
|
|
3460
|
+
data: {
|
|
3461
|
+
type: 'portal:blockaid:scanAddressError',
|
|
3462
|
+
data: {
|
|
3463
|
+
code: 1,
|
|
3464
|
+
message: 'test',
|
|
3465
|
+
},
|
|
3466
|
+
},
|
|
3467
|
+
}));
|
|
3468
|
+
});
|
|
3469
|
+
mpc
|
|
3470
|
+
.blockaidScanAddress(args)
|
|
3471
|
+
.then(() => {
|
|
3472
|
+
expect(0).toEqual(1);
|
|
3473
|
+
done();
|
|
3474
|
+
})
|
|
3475
|
+
.catch((e) => {
|
|
3476
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3477
|
+
expect(e.message).toEqual('test');
|
|
3478
|
+
expect(e.code).toEqual(1);
|
|
3479
|
+
done();
|
|
3480
|
+
});
|
|
3481
|
+
});
|
|
3482
|
+
});
|
|
3483
|
+
describe('blockaidScanTokens', () => {
|
|
3484
|
+
const args = mockBlockaidScanTokensRequest;
|
|
3485
|
+
const res = mockBlockaidScanTokensResponse;
|
|
3486
|
+
it('should successfully scan tokens with Blockaid', (done) => {
|
|
3487
|
+
var _a;
|
|
3488
|
+
jest
|
|
3489
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3490
|
+
.mockImplementation((message, origin) => {
|
|
3491
|
+
const { type, data } = message;
|
|
3492
|
+
expect(type).toEqual('portal:blockaid:scanTokens');
|
|
3493
|
+
expect(data).toEqual(args);
|
|
3494
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3495
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3496
|
+
origin: mockHostOrigin,
|
|
3497
|
+
data: {
|
|
3498
|
+
type: 'portal:blockaid:scanTokensResult',
|
|
3499
|
+
data: res,
|
|
3500
|
+
},
|
|
3501
|
+
}));
|
|
3502
|
+
});
|
|
3503
|
+
mpc
|
|
3504
|
+
.blockaidScanTokens(args)
|
|
3505
|
+
.then((data) => {
|
|
3506
|
+
expect(data).toEqual(res);
|
|
3507
|
+
done();
|
|
3508
|
+
})
|
|
3509
|
+
.catch((_) => {
|
|
3510
|
+
expect(0).toEqual(1);
|
|
3511
|
+
done();
|
|
3512
|
+
});
|
|
3513
|
+
});
|
|
3514
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3515
|
+
var _a;
|
|
3516
|
+
jest
|
|
3517
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3518
|
+
.mockImplementationOnce((message, origin) => {
|
|
3519
|
+
const { type, data } = message;
|
|
3520
|
+
expect(type).toEqual('portal:blockaid:scanTokens');
|
|
3521
|
+
expect(data).toEqual(args);
|
|
3522
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3523
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3524
|
+
origin: mockHostOrigin,
|
|
3525
|
+
data: {
|
|
3526
|
+
type: 'portal:blockaid:scanTokensError',
|
|
3527
|
+
data: {
|
|
3528
|
+
code: 1,
|
|
3529
|
+
message: 'test',
|
|
3530
|
+
},
|
|
3531
|
+
},
|
|
3532
|
+
}));
|
|
3533
|
+
});
|
|
3534
|
+
mpc
|
|
3535
|
+
.blockaidScanTokens(args)
|
|
3536
|
+
.then(() => {
|
|
3537
|
+
expect(0).toEqual(1);
|
|
3538
|
+
done();
|
|
3539
|
+
})
|
|
3540
|
+
.catch((e) => {
|
|
3541
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3542
|
+
expect(e.message).toEqual('test');
|
|
3543
|
+
expect(e.code).toEqual(1);
|
|
3544
|
+
done();
|
|
3545
|
+
});
|
|
3546
|
+
});
|
|
3547
|
+
});
|
|
3548
|
+
describe('blockaidScanUrl', () => {
|
|
3549
|
+
const args = mockBlockaidScanUrlRequest;
|
|
3550
|
+
const res = mockBlockaidScanUrlResponse;
|
|
3551
|
+
it('should successfully scan URL with Blockaid', (done) => {
|
|
3552
|
+
var _a;
|
|
3553
|
+
jest
|
|
3554
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3555
|
+
.mockImplementation((message, origin) => {
|
|
3556
|
+
const { type, data } = message;
|
|
3557
|
+
expect(type).toEqual('portal:blockaid:scanUrl');
|
|
3558
|
+
expect(data).toEqual(args);
|
|
3559
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3560
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3561
|
+
origin: mockHostOrigin,
|
|
3562
|
+
data: {
|
|
3563
|
+
type: 'portal:blockaid:scanUrlResult',
|
|
3564
|
+
data: res,
|
|
3565
|
+
},
|
|
3566
|
+
}));
|
|
3567
|
+
});
|
|
3568
|
+
mpc
|
|
3569
|
+
.blockaidScanUrl(args)
|
|
3570
|
+
.then((data) => {
|
|
3571
|
+
expect(data).toEqual(res);
|
|
3572
|
+
done();
|
|
3573
|
+
})
|
|
3574
|
+
.catch((_) => {
|
|
3575
|
+
expect(0).toEqual(1);
|
|
3576
|
+
done();
|
|
3577
|
+
});
|
|
3578
|
+
});
|
|
3579
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
3580
|
+
var _a;
|
|
3581
|
+
jest
|
|
3582
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
3583
|
+
.mockImplementationOnce((message, origin) => {
|
|
3584
|
+
const { type, data } = message;
|
|
3585
|
+
expect(type).toEqual('portal:blockaid:scanUrl');
|
|
3586
|
+
expect(data).toEqual(args);
|
|
3587
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
3588
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
3589
|
+
origin: mockHostOrigin,
|
|
3590
|
+
data: {
|
|
3591
|
+
type: 'portal:blockaid:scanUrlError',
|
|
3592
|
+
data: {
|
|
3593
|
+
code: 1,
|
|
3594
|
+
message: 'test',
|
|
3595
|
+
},
|
|
3596
|
+
},
|
|
3597
|
+
}));
|
|
3598
|
+
});
|
|
3599
|
+
mpc
|
|
3600
|
+
.blockaidScanUrl(args)
|
|
3601
|
+
.then(() => {
|
|
3602
|
+
expect(0).toEqual(1);
|
|
3603
|
+
done();
|
|
3604
|
+
})
|
|
3605
|
+
.catch((e) => {
|
|
3606
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
3607
|
+
expect(e.message).toEqual('test');
|
|
3608
|
+
expect(e.code).toEqual(1);
|
|
3609
|
+
done();
|
|
3610
|
+
});
|
|
3611
|
+
});
|
|
3612
|
+
});
|
|
3285
3613
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Portal MPC Support for Web",
|
|
4
4
|
"author": "Portal Labs, Inc.",
|
|
5
5
|
"homepage": "https://portalhq.io/",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.9.0",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "lib/commonjs/index",
|
|
9
9
|
"module": "lib/esm/index",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"terser-webpack-plugin": "^5.3.9",
|
|
51
51
|
"ts-jest": "^29.2.4",
|
|
52
52
|
"ts-loader": "^9.4.3",
|
|
53
|
-
"ts-node": "^10.9.
|
|
53
|
+
"ts-node": "^10.9.2",
|
|
54
54
|
"typescript": "^4.8.4",
|
|
55
55
|
"webpack": "^5.94.0",
|
|
56
56
|
"webpack-cli": "^5.1.4"
|