@portal-hq/web 3.6.2-alpha → 3.7.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/hypernative.d.ts +346 -0
- package/lib/commonjs/index.js +144 -2
- package/lib/commonjs/index.test.js +119 -2
- package/lib/commonjs/integrations/security/hypernative/index.js +101 -0
- package/lib/commonjs/integrations/security/hypernative/index.test.js +151 -0
- package/lib/commonjs/integrations/security/index.js +16 -0
- package/lib/commonjs/integrations/trading/zero-x/index.js +17 -4
- package/lib/commonjs/integrations/trading/zero-x/index.test.js +61 -15
- package/lib/commonjs/mpc/index.js +156 -5
- package/lib/commonjs/mpc/index.test.js +794 -5
- package/lib/commonjs/passkeys/index.js +394 -0
- package/lib/commonjs/passkeys/types.js +2 -0
- package/lib/commonjs/provider/index.js +5 -2
- package/lib/esm/index.js +144 -2
- package/lib/esm/index.test.js +119 -2
- package/lib/esm/integrations/security/hypernative/index.js +98 -0
- package/lib/esm/integrations/security/hypernative/index.test.js +146 -0
- package/lib/esm/integrations/security/index.js +10 -0
- package/lib/esm/integrations/trading/zero-x/index.js +17 -4
- package/lib/esm/integrations/trading/zero-x/index.test.js +62 -16
- package/lib/esm/mpc/index.js +156 -5
- package/lib/esm/mpc/index.test.js +795 -6
- package/lib/esm/passkeys/index.js +390 -0
- package/lib/esm/passkeys/types.js +1 -0
- package/lib/esm/provider/index.js +5 -2
- package/lifi-types.d.ts +1236 -0
- package/package.json +6 -3
- package/src/__mocks/constants.ts +422 -5
- package/src/__mocks/portal/mpc.ts +1 -0
- package/src/index.test.ts +179 -3
- package/src/index.ts +212 -4
- package/src/integrations/security/hypernative/index.test.ts +196 -0
- package/src/integrations/security/hypernative/index.ts +106 -0
- package/src/integrations/security/index.ts +14 -0
- package/src/integrations/trading/zero-x/index.test.ts +98 -19
- package/src/integrations/trading/zero-x/index.ts +29 -9
- package/src/mpc/index.test.ts +944 -7
- package/src/mpc/index.ts +200 -10
- package/src/passkeys/index.ts +536 -0
- package/src/passkeys/types.ts +78 -0
- package/src/provider/index.ts +5 -0
- package/tsconfig.json +7 -1
- package/types.d.ts +45 -12
- package/yieldxyz-types.d.ts +778 -0
- package/zero-x.d.ts +204 -0
|
@@ -0,0 +1,101 @@
|
|
|
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 Hypernative {
|
|
13
|
+
constructor({ mpc }) {
|
|
14
|
+
this.mpc = mpc;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Scans an EIP-155 transaction for security risks.
|
|
18
|
+
* @param data - The parameters for the EIP-155 transaction scan request.
|
|
19
|
+
* @returns A `ScanEVMResponse` promise.
|
|
20
|
+
* @throws An error if the operation fails.
|
|
21
|
+
*/
|
|
22
|
+
scanEVMTx(data) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanEVMTx(data);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Scans an EIP-712 typed message for security risks.
|
|
30
|
+
* @param data - The parameters for the EIP-712 message scan request.
|
|
31
|
+
* @returns A `ScanEip712Response` promise.
|
|
32
|
+
* @throws An error if the operation fails.
|
|
33
|
+
*/
|
|
34
|
+
scanEip712Tx(data) {
|
|
35
|
+
var _a;
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanEip712Tx(data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Scans a Solana transaction for security risks.
|
|
42
|
+
* @param data - The parameters for the Solana transaction scan request.
|
|
43
|
+
* @returns A `ScanSolanaResponse` promise.
|
|
44
|
+
* @throws An error if the operation fails.
|
|
45
|
+
*/
|
|
46
|
+
scanSolanaTx(data) {
|
|
47
|
+
var _a;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanSolanaTx(data);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Scans addresses for security risks and flags.
|
|
54
|
+
* @param data - The parameters for the address scan request.
|
|
55
|
+
* @returns A `ScreenAddressApiResponse` promise.
|
|
56
|
+
* @throws An error if the operation fails.
|
|
57
|
+
*/
|
|
58
|
+
scanAddresses(addresses, options) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanAddresses(Object.assign({ addresses }, options));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Scans NFTs for security risks.
|
|
66
|
+
* @param data - The parameters for the NFT scan request.
|
|
67
|
+
* @returns A `ScanNftResponse` promise.
|
|
68
|
+
* @throws An error if the operation fails.
|
|
69
|
+
*/
|
|
70
|
+
scanNFTs(nfts) {
|
|
71
|
+
var _a;
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanNFTs(nfts);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Scans tokens for security risks.
|
|
78
|
+
* @param data - The parameters for the token scan request.
|
|
79
|
+
* @returns A `ScanTokenResponse` promise.
|
|
80
|
+
* @throws An error if the operation fails.
|
|
81
|
+
*/
|
|
82
|
+
scanTokens(tokens) {
|
|
83
|
+
var _a;
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanTokens(tokens);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Scans a URL for malicious content.
|
|
90
|
+
* @param data - The parameters for the URL scan request.
|
|
91
|
+
* @returns A `ScanUrlResponse` promise.
|
|
92
|
+
* @throws An error if the operation fails.
|
|
93
|
+
*/
|
|
94
|
+
scanURL(url) {
|
|
95
|
+
var _a;
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.scanUrl(url);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.default = Hypernative;
|
|
@@ -0,0 +1,151 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
15
|
+
var t = {};
|
|
16
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
17
|
+
t[p] = s[p];
|
|
18
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
19
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
20
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
21
|
+
t[p[i]] = s[p[i]];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const _1 = __importDefault(require("."));
|
|
30
|
+
const mpc_1 = __importDefault(require("../../../mpc"));
|
|
31
|
+
const portal_1 = __importDefault(require("../../../__mocks/portal/portal"));
|
|
32
|
+
const constants_1 = require("../../../__mocks/constants");
|
|
33
|
+
describe('Hypernative', () => {
|
|
34
|
+
let hypernative;
|
|
35
|
+
let mpc;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
jest.clearAllMocks();
|
|
38
|
+
portal_1.default.host = constants_1.mockHost;
|
|
39
|
+
mpc = new mpc_1.default({
|
|
40
|
+
portal: portal_1.default,
|
|
41
|
+
});
|
|
42
|
+
hypernative = new _1.default({ mpc });
|
|
43
|
+
});
|
|
44
|
+
describe('scanEVMTx', () => {
|
|
45
|
+
it('should call mpc.scanEVMTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const spy = jest
|
|
47
|
+
.spyOn(mpc, 'scanEVMTx')
|
|
48
|
+
.mockResolvedValue(constants_1.mockScanEVMTxResponse);
|
|
49
|
+
const result = yield hypernative.scanEVMTx(constants_1.mockScanEVMTxRequest);
|
|
50
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanEVMTxRequest);
|
|
51
|
+
expect(result).toEqual(constants_1.mockScanEVMTxResponse);
|
|
52
|
+
}));
|
|
53
|
+
it('should propagate errors from mpc.scanEVMTx', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const error = new Error('Test error');
|
|
55
|
+
jest.spyOn(mpc, 'scanEVMTx').mockRejectedValue(error);
|
|
56
|
+
yield expect(hypernative.scanEVMTx(constants_1.mockScanEVMTxRequest)).rejects.toThrow('Test error');
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
describe('scanEip712Tx', () => {
|
|
60
|
+
it('should call mpc.scanEip712Tx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const spy = jest
|
|
62
|
+
.spyOn(mpc, 'scanEip712Tx')
|
|
63
|
+
.mockResolvedValue(constants_1.mockScanEip712TxResponse);
|
|
64
|
+
const result = yield hypernative.scanEip712Tx(constants_1.mockScanEip712TxRequest);
|
|
65
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanEip712TxRequest);
|
|
66
|
+
expect(result).toEqual(constants_1.mockScanEip712TxResponse);
|
|
67
|
+
}));
|
|
68
|
+
it('should propagate errors from mpc.scanEip712Tx', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const error = new Error('Test error');
|
|
70
|
+
jest.spyOn(mpc, 'scanEip712Tx').mockRejectedValue(error);
|
|
71
|
+
yield expect(hypernative.scanEip712Tx(constants_1.mockScanEip712TxRequest)).rejects.toThrow('Test error');
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
describe('scanSolanaTx', () => {
|
|
75
|
+
it('should call mpc.scanSolanaTx with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const spy = jest
|
|
77
|
+
.spyOn(mpc, 'scanSolanaTx')
|
|
78
|
+
.mockResolvedValue(constants_1.mockScanSolanaTxResponse);
|
|
79
|
+
const result = yield hypernative.scanSolanaTx(constants_1.mockScanSolanaTxRequest);
|
|
80
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanSolanaTxRequest);
|
|
81
|
+
expect(result).toEqual(constants_1.mockScanSolanaTxResponse);
|
|
82
|
+
}));
|
|
83
|
+
it('should propagate errors from mpc.scanSolanaTx', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
const error = new Error('Test error');
|
|
85
|
+
jest.spyOn(mpc, 'scanSolanaTx').mockRejectedValue(error);
|
|
86
|
+
yield expect(hypernative.scanSolanaTx(constants_1.mockScanSolanaTxRequest)).rejects.toThrow('Test error');
|
|
87
|
+
}));
|
|
88
|
+
});
|
|
89
|
+
describe('scanAddresses', () => {
|
|
90
|
+
it('should call mpc.scanAddresses with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const spy = jest
|
|
92
|
+
.spyOn(mpc, 'scanAddresses')
|
|
93
|
+
.mockResolvedValue(constants_1.mockScanAddressesResponse);
|
|
94
|
+
const { addresses } = constants_1.mockScanAddressesRequest, options = __rest(constants_1.mockScanAddressesRequest, ["addresses"]);
|
|
95
|
+
const result = yield hypernative.scanAddresses(addresses, options);
|
|
96
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanAddressesRequest);
|
|
97
|
+
expect(result).toEqual(constants_1.mockScanAddressesResponse);
|
|
98
|
+
}));
|
|
99
|
+
it('should propagate errors from mpc.scanAddresses', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const error = new Error('Test error');
|
|
101
|
+
jest.spyOn(mpc, 'scanAddresses').mockRejectedValue(error);
|
|
102
|
+
const { addresses } = constants_1.mockScanAddressesRequest, options = __rest(constants_1.mockScanAddressesRequest, ["addresses"]);
|
|
103
|
+
yield expect(hypernative.scanAddresses(addresses, options)).rejects.toThrow('Test error');
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
describe('scanNFTs', () => {
|
|
107
|
+
it('should call mpc.scanNFTs with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const spy = jest
|
|
109
|
+
.spyOn(mpc, 'scanNFTs')
|
|
110
|
+
.mockResolvedValue(constants_1.mockScanNftResponse);
|
|
111
|
+
const result = yield hypernative.scanNFTs(constants_1.mockScanNftRequest);
|
|
112
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanNftRequest);
|
|
113
|
+
expect(result).toEqual(constants_1.mockScanNftResponse);
|
|
114
|
+
}));
|
|
115
|
+
it('should propagate errors from mpc.scanNFTs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
const error = new Error('Test error');
|
|
117
|
+
jest.spyOn(mpc, 'scanNFTs').mockRejectedValue(error);
|
|
118
|
+
yield expect(hypernative.scanNFTs(constants_1.mockScanNftRequest)).rejects.toThrow('Test error');
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
describe('scanTokens', () => {
|
|
122
|
+
it('should call mpc.scanTokens with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
const spy = jest
|
|
124
|
+
.spyOn(mpc, 'scanTokens')
|
|
125
|
+
.mockResolvedValue(constants_1.mockScanTokenResponse);
|
|
126
|
+
const result = yield hypernative.scanTokens(constants_1.mockScanTokenRequest);
|
|
127
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanTokenRequest);
|
|
128
|
+
expect(result).toEqual(constants_1.mockScanTokenResponse);
|
|
129
|
+
}));
|
|
130
|
+
it('should propagate errors from mpc.scanTokens', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const error = new Error('Test error');
|
|
132
|
+
jest.spyOn(mpc, 'scanTokens').mockRejectedValue(error);
|
|
133
|
+
yield expect(hypernative.scanTokens(constants_1.mockScanTokenRequest)).rejects.toThrow('Test error');
|
|
134
|
+
}));
|
|
135
|
+
});
|
|
136
|
+
describe('scanURL', () => {
|
|
137
|
+
it('should call mpc.scanUrl with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
+
const spy = jest
|
|
139
|
+
.spyOn(mpc, 'scanUrl')
|
|
140
|
+
.mockResolvedValue(constants_1.mockScanUrlResponse);
|
|
141
|
+
const result = yield hypernative.scanURL(constants_1.mockScanUrlRequest);
|
|
142
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockScanUrlRequest);
|
|
143
|
+
expect(result).toEqual(constants_1.mockScanUrlResponse);
|
|
144
|
+
}));
|
|
145
|
+
it('should propagate errors from mpc.scanUrl', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
const error = new Error('Test error');
|
|
147
|
+
jest.spyOn(mpc, 'scanUrl').mockRejectedValue(error);
|
|
148
|
+
yield expect(hypernative.scanURL(constants_1.mockScanUrlRequest)).rejects.toThrow('Test error');
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const hypernative_1 = __importDefault(require("./hypernative"));
|
|
7
|
+
/**
|
|
8
|
+
* This class is a container for the Hypernative class.
|
|
9
|
+
* In the future, Security domain logic should be here.
|
|
10
|
+
*/
|
|
11
|
+
class Security {
|
|
12
|
+
constructor({ mpc }) {
|
|
13
|
+
this.hypernative = new hypernative_1.default({ mpc });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = Security;
|
|
@@ -21,10 +21,10 @@ class ZeroX {
|
|
|
21
21
|
* @param chainId - The chain ID for the quote.
|
|
22
22
|
* @returns The quote response.
|
|
23
23
|
*/
|
|
24
|
-
getQuote(
|
|
24
|
+
getQuote(args, options) {
|
|
25
25
|
var _a;
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
27
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsQuoteV2(args, options);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -34,10 +34,23 @@ class ZeroX {
|
|
|
34
34
|
* @param chainId - The chain ID for the sources.
|
|
35
35
|
* @returns The sources response.
|
|
36
36
|
*/
|
|
37
|
-
getSources(
|
|
37
|
+
getSources(chainId, options) {
|
|
38
38
|
var _a;
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
40
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsSourcesV2({ chainId }, options);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the price of a token from the Swaps API.
|
|
45
|
+
*
|
|
46
|
+
* @param args - The arguments for the price.
|
|
47
|
+
* @param options - The options for the price.
|
|
48
|
+
* @returns The price response.
|
|
49
|
+
*/
|
|
50
|
+
getPrice(args, options) {
|
|
51
|
+
var _a;
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSwapsPrice(args, options);
|
|
41
54
|
});
|
|
42
55
|
}
|
|
43
56
|
}
|
|
@@ -31,35 +31,81 @@ describe('ZeroX', () => {
|
|
|
31
31
|
zeroX = new _1.default({ mpc });
|
|
32
32
|
});
|
|
33
33
|
describe('getQuote', () => {
|
|
34
|
-
it('should correctly call mpc.
|
|
34
|
+
it('should correctly call mpc.getSwapsQuoteV2 with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
const spy = jest
|
|
36
|
-
.spyOn(mpc, '
|
|
37
|
-
.mockResolvedValue(constants_1.
|
|
38
|
-
const result = yield zeroX.getQuote(
|
|
36
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
37
|
+
.mockResolvedValue(constants_1.mockZeroExQuoteV2Response);
|
|
38
|
+
const result = yield zeroX.getQuote(constants_1.mockZeroExQuoteV2Request, constants_1.mockZeroExOptions);
|
|
39
39
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(spy).toHaveBeenCalledWith(
|
|
41
|
-
expect(result).toEqual(constants_1.
|
|
40
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExQuoteV2Request, constants_1.mockZeroExOptions);
|
|
41
|
+
expect(result).toEqual(constants_1.mockZeroExQuoteV2Response);
|
|
42
42
|
}));
|
|
43
|
-
it('should
|
|
43
|
+
it('should correctly call mpc.getSwapsQuoteV2 without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const spy = jest
|
|
45
|
+
.spyOn(mpc, 'getSwapsQuoteV2')
|
|
46
|
+
.mockResolvedValue(constants_1.mockZeroExQuoteV2Response);
|
|
47
|
+
const result = yield zeroX.getQuote(constants_1.mockZeroExQuoteV2Request);
|
|
48
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExQuoteV2Request, undefined);
|
|
50
|
+
expect(result).toEqual(constants_1.mockZeroExQuoteV2Response);
|
|
51
|
+
}));
|
|
52
|
+
it('should propagate errors from mpc.getSwapsQuoteV2', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
53
|
const error = new Error('Test error');
|
|
45
|
-
jest.spyOn(mpc, '
|
|
46
|
-
yield expect(zeroX.getQuote(
|
|
54
|
+
jest.spyOn(mpc, 'getSwapsQuoteV2').mockRejectedValue(error);
|
|
55
|
+
yield expect(zeroX.getQuote(constants_1.mockZeroExQuoteV2Request)).rejects.toThrow('Test error');
|
|
47
56
|
}));
|
|
48
57
|
});
|
|
49
58
|
describe('getSources', () => {
|
|
50
|
-
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
it('should correctly call mpc.getSources with chainId and apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
60
|
const spy = jest
|
|
52
|
-
.spyOn(mpc, '
|
|
61
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
53
62
|
.mockResolvedValue(constants_1.mockSourcesRes);
|
|
54
|
-
const result = yield zeroX.getSources('
|
|
63
|
+
const result = yield zeroX.getSources('eip155:1', {
|
|
64
|
+
zeroXApiKey: 'test-api-key',
|
|
65
|
+
});
|
|
66
|
+
console.log(`Result:`, result);
|
|
55
67
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
56
|
-
expect(spy).toHaveBeenCalledWith(
|
|
68
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, { zeroXApiKey: 'test-api-key' });
|
|
69
|
+
expect(result).toEqual(constants_1.mockSourcesRes);
|
|
70
|
+
}));
|
|
71
|
+
it('should correctly call mpc.getSources without apiKey', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const spy = jest
|
|
73
|
+
.spyOn(mpc, 'getSwapsSourcesV2')
|
|
74
|
+
.mockResolvedValue(constants_1.mockSourcesRes);
|
|
75
|
+
const result = yield zeroX.getSources('eip155:1');
|
|
76
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(spy).toHaveBeenCalledWith({ chainId: 'eip155:1' }, undefined);
|
|
57
78
|
expect(result).toEqual(constants_1.mockSourcesRes);
|
|
58
79
|
}));
|
|
59
80
|
it('should propagate errors from mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
81
|
const error = new Error('Test error');
|
|
61
|
-
jest.spyOn(mpc, '
|
|
62
|
-
yield expect(zeroX.getSources('
|
|
82
|
+
jest.spyOn(mpc, 'getSwapsSourcesV2').mockRejectedValue(error);
|
|
83
|
+
yield expect(zeroX.getSources('eip155:1')).rejects.toThrow('Test error');
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
86
|
+
describe('getPrice', () => {
|
|
87
|
+
it('should correctly call mpc.getSwapsPrice with args and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const spy = jest
|
|
89
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
90
|
+
.mockResolvedValue(constants_1.mockZeroExPriceResponse);
|
|
91
|
+
const result = yield zeroX.getPrice(constants_1.mockZeroExPriceRequest, constants_1.mockZeroExOptions);
|
|
92
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExPriceRequest, constants_1.mockZeroExOptions);
|
|
94
|
+
expect(result).toEqual(constants_1.mockZeroExPriceResponse);
|
|
95
|
+
}));
|
|
96
|
+
it('should correctly call mpc.getSwapsPrice without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const spy = jest
|
|
98
|
+
.spyOn(mpc, 'getSwapsPrice')
|
|
99
|
+
.mockResolvedValue(constants_1.mockZeroExPriceResponse);
|
|
100
|
+
const result = yield zeroX.getPrice(constants_1.mockZeroExPriceRequest);
|
|
101
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
102
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockZeroExPriceRequest, undefined);
|
|
103
|
+
expect(result).toEqual(constants_1.mockZeroExPriceResponse);
|
|
104
|
+
}));
|
|
105
|
+
it('should propagate errors from mpc.getSwapsPrice', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
const error = new Error('Test error');
|
|
107
|
+
jest.spyOn(mpc, 'getSwapsPrice').mockRejectedValue(error);
|
|
108
|
+
yield expect(zeroX.getPrice(constants_1.mockZeroExPriceRequest)).rejects.toThrow('Test error');
|
|
63
109
|
}));
|
|
64
110
|
});
|
|
65
111
|
});
|
|
@@ -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.
|
|
15
|
+
const WEB_SDK_VERSION = '3.7.0';
|
|
16
16
|
class Mpc {
|
|
17
17
|
get ready() {
|
|
18
18
|
return this._ready;
|
|
@@ -81,12 +81,19 @@ class Mpc {
|
|
|
81
81
|
// Remove the event listeners
|
|
82
82
|
window.removeEventListener('message', handleBackup);
|
|
83
83
|
window.removeEventListener('message', handleProgress);
|
|
84
|
+
const resultData = result;
|
|
85
|
+
const backupIds = Array.isArray(resultData.backupIds)
|
|
86
|
+
? resultData.backupIds
|
|
87
|
+
: [];
|
|
84
88
|
const storageCallback = () => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE',
|
|
89
|
+
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', backupIds);
|
|
86
90
|
});
|
|
87
91
|
// Resolve the promise with the result
|
|
88
92
|
resolve({
|
|
89
|
-
cipherText:
|
|
93
|
+
cipherText: resultData.cipherText,
|
|
94
|
+
encryptionKey: typeof resultData.encryptionKey === 'string'
|
|
95
|
+
? resultData.encryptionKey
|
|
96
|
+
: undefined,
|
|
90
97
|
storageCallback,
|
|
91
98
|
});
|
|
92
99
|
}
|
|
@@ -673,7 +680,7 @@ class Mpc {
|
|
|
673
680
|
});
|
|
674
681
|
});
|
|
675
682
|
}
|
|
676
|
-
getQuote(
|
|
683
|
+
getQuote(chainId, args, apiKey) {
|
|
677
684
|
return __awaiter(this, void 0, void 0, function* () {
|
|
678
685
|
return new Promise((resolve, reject) => {
|
|
679
686
|
const handleGetQuote = (event) => {
|
|
@@ -710,7 +717,7 @@ class Mpc {
|
|
|
710
717
|
});
|
|
711
718
|
});
|
|
712
719
|
}
|
|
713
|
-
getSources(
|
|
720
|
+
getSources(chainId, apiKey) {
|
|
714
721
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715
722
|
return new Promise((resolve, reject) => {
|
|
716
723
|
const handleGetSources = (event) => {
|
|
@@ -1112,6 +1119,109 @@ class Mpc {
|
|
|
1112
1119
|
});
|
|
1113
1120
|
});
|
|
1114
1121
|
}
|
|
1122
|
+
getSwapsQuoteV2(data, options) {
|
|
1123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1124
|
+
return this.handleRequestToIframeAndPost({
|
|
1125
|
+
methodMessage: 'portal:swaps:getQuoteV2',
|
|
1126
|
+
errorMessage: 'portal:swaps:getQuoteV2Error',
|
|
1127
|
+
resultMessage: 'portal:swaps:getQuoteV2Result',
|
|
1128
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
getSwapsSourcesV2(data, options) {
|
|
1133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1134
|
+
return this.handleRequestToIframeAndPost({
|
|
1135
|
+
methodMessage: 'portal:swaps:getSourcesV2',
|
|
1136
|
+
errorMessage: 'portal:swaps:getSourcesV2Error',
|
|
1137
|
+
resultMessage: 'portal:swaps:getSourcesV2Result',
|
|
1138
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1139
|
+
});
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
getSwapsPrice(data, options) {
|
|
1143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1144
|
+
return this.handleRequestToIframeAndPost({
|
|
1145
|
+
methodMessage: 'portal:swaps:getPrice',
|
|
1146
|
+
errorMessage: 'portal:swaps:getPriceError',
|
|
1147
|
+
resultMessage: 'portal:swaps:getPriceResult',
|
|
1148
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1149
|
+
});
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
/*******************************
|
|
1153
|
+
* Security Methods
|
|
1154
|
+
*******************************/
|
|
1155
|
+
scanAddresses(data) {
|
|
1156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1157
|
+
return this.handleRequestToIframeAndPost({
|
|
1158
|
+
methodMessage: 'portal:security:scanAddresses',
|
|
1159
|
+
errorMessage: 'portal:security:scanAddressesError',
|
|
1160
|
+
resultMessage: 'portal:security:scanAddressesResult',
|
|
1161
|
+
data,
|
|
1162
|
+
});
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
scanEVMTx(data) {
|
|
1166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1167
|
+
return this.handleRequestToIframeAndPost({
|
|
1168
|
+
methodMessage: 'portal:security:scanEVMTx',
|
|
1169
|
+
errorMessage: 'portal:security:scanEVMTxError',
|
|
1170
|
+
resultMessage: 'portal:security:scanEVMTxResult',
|
|
1171
|
+
data,
|
|
1172
|
+
});
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
scanEip712Tx(data) {
|
|
1176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
+
return this.handleRequestToIframeAndPost({
|
|
1178
|
+
methodMessage: 'portal:security:scanEip712Tx',
|
|
1179
|
+
errorMessage: 'portal:security:scanEip712TxError',
|
|
1180
|
+
resultMessage: 'portal:security:scanEip712TxResult',
|
|
1181
|
+
data,
|
|
1182
|
+
});
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
scanSolanaTx(data) {
|
|
1186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1187
|
+
return this.handleRequestToIframeAndPost({
|
|
1188
|
+
methodMessage: 'portal:security:scanSolanaTx',
|
|
1189
|
+
errorMessage: 'portal:security:scanSolanaTxError',
|
|
1190
|
+
resultMessage: 'portal:security:scanSolanaTxResult',
|
|
1191
|
+
data,
|
|
1192
|
+
});
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
scanNFTs(nfts) {
|
|
1196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1197
|
+
return this.handleRequestToIframeAndPost({
|
|
1198
|
+
methodMessage: 'portal:security:scanNfts',
|
|
1199
|
+
errorMessage: 'portal:security:scanNftsError',
|
|
1200
|
+
resultMessage: 'portal:security:scanNftsResult',
|
|
1201
|
+
data: nfts,
|
|
1202
|
+
});
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
scanTokens(tokens) {
|
|
1206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1207
|
+
return this.handleRequestToIframeAndPost({
|
|
1208
|
+
methodMessage: 'portal:security:scanTokens',
|
|
1209
|
+
errorMessage: 'portal:security:scanTokensError',
|
|
1210
|
+
resultMessage: 'portal:security:scanTokensResult',
|
|
1211
|
+
data: tokens,
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
scanUrl(url) {
|
|
1216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1217
|
+
return this.handleRequestToIframeAndPost({
|
|
1218
|
+
methodMessage: 'portal:security:scanUrl',
|
|
1219
|
+
errorMessage: 'portal:security:scanUrlError',
|
|
1220
|
+
resultMessage: 'portal:security:scanUrlResult',
|
|
1221
|
+
data: { url },
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1115
1225
|
/***************************
|
|
1116
1226
|
* Private Methods
|
|
1117
1227
|
***************************/
|
|
@@ -1175,6 +1285,47 @@ class Mpc {
|
|
|
1175
1285
|
: `https://${host}`;
|
|
1176
1286
|
return origin;
|
|
1177
1287
|
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Fetches a scoped JWT for passkey operations from the iframe.
|
|
1290
|
+
* The JWT has only "passkey" permission, reducing blast radius if compromised.
|
|
1291
|
+
*/
|
|
1292
|
+
getPasskeyJwt() {
|
|
1293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1294
|
+
return new Promise((resolve, reject) => {
|
|
1295
|
+
const handleResult = (event) => {
|
|
1296
|
+
const { type, data } = event.data;
|
|
1297
|
+
const { origin } = event;
|
|
1298
|
+
// ignore any broadcast postMessages
|
|
1299
|
+
if (origin !== this.getOrigin()) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (type === 'portal:getPasskeyJwtResult') {
|
|
1303
|
+
window.removeEventListener('message', handleResult);
|
|
1304
|
+
window.removeEventListener('message', handleError);
|
|
1305
|
+
resolve(data.token);
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
const handleError = (event) => {
|
|
1309
|
+
const { type, data } = event.data;
|
|
1310
|
+
const { origin } = event;
|
|
1311
|
+
if (origin !== this.getOrigin()) {
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
if (type === 'portal:getPasskeyJwtError') {
|
|
1315
|
+
window.removeEventListener('message', handleResult);
|
|
1316
|
+
window.removeEventListener('message', handleError);
|
|
1317
|
+
reject(new Error(data.message));
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
window.addEventListener('message', handleResult);
|
|
1321
|
+
window.addEventListener('message', handleError);
|
|
1322
|
+
this.postMessage({
|
|
1323
|
+
type: 'portal:getPasskeyJwt',
|
|
1324
|
+
data: {},
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1178
1329
|
postMessage(event) {
|
|
1179
1330
|
var _a, _b;
|
|
1180
1331
|
(_b = (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(event, this.getOrigin());
|