@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
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.7.0';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -78,12 +78,19 @@ class Mpc {
|
|
|
78
78
|
// Remove the event listeners
|
|
79
79
|
window.removeEventListener('message', handleBackup);
|
|
80
80
|
window.removeEventListener('message', handleProgress);
|
|
81
|
+
const resultData = result;
|
|
82
|
+
const backupIds = Array.isArray(resultData.backupIds)
|
|
83
|
+
? resultData.backupIds
|
|
84
|
+
: [];
|
|
81
85
|
const storageCallback = () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE',
|
|
86
|
+
yield this.setBackupStatus('STORED_CLIENT_BACKUP_SHARE', backupIds);
|
|
83
87
|
});
|
|
84
88
|
// Resolve the promise with the result
|
|
85
89
|
resolve({
|
|
86
|
-
cipherText:
|
|
90
|
+
cipherText: resultData.cipherText,
|
|
91
|
+
encryptionKey: typeof resultData.encryptionKey === 'string'
|
|
92
|
+
? resultData.encryptionKey
|
|
93
|
+
: undefined,
|
|
87
94
|
storageCallback,
|
|
88
95
|
});
|
|
89
96
|
}
|
|
@@ -670,7 +677,7 @@ class Mpc {
|
|
|
670
677
|
});
|
|
671
678
|
});
|
|
672
679
|
}
|
|
673
|
-
getQuote(
|
|
680
|
+
getQuote(chainId, args, apiKey) {
|
|
674
681
|
return __awaiter(this, void 0, void 0, function* () {
|
|
675
682
|
return new Promise((resolve, reject) => {
|
|
676
683
|
const handleGetQuote = (event) => {
|
|
@@ -707,7 +714,7 @@ class Mpc {
|
|
|
707
714
|
});
|
|
708
715
|
});
|
|
709
716
|
}
|
|
710
|
-
getSources(
|
|
717
|
+
getSources(chainId, apiKey) {
|
|
711
718
|
return __awaiter(this, void 0, void 0, function* () {
|
|
712
719
|
return new Promise((resolve, reject) => {
|
|
713
720
|
const handleGetSources = (event) => {
|
|
@@ -1109,6 +1116,109 @@ class Mpc {
|
|
|
1109
1116
|
});
|
|
1110
1117
|
});
|
|
1111
1118
|
}
|
|
1119
|
+
getSwapsQuoteV2(data, options) {
|
|
1120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1121
|
+
return this.handleRequestToIframeAndPost({
|
|
1122
|
+
methodMessage: 'portal:swaps:getQuoteV2',
|
|
1123
|
+
errorMessage: 'portal:swaps:getQuoteV2Error',
|
|
1124
|
+
resultMessage: 'portal:swaps:getQuoteV2Result',
|
|
1125
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1126
|
+
});
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
getSwapsSourcesV2(data, options) {
|
|
1130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1131
|
+
return this.handleRequestToIframeAndPost({
|
|
1132
|
+
methodMessage: 'portal:swaps:getSourcesV2',
|
|
1133
|
+
errorMessage: 'portal:swaps:getSourcesV2Error',
|
|
1134
|
+
resultMessage: 'portal:swaps:getSourcesV2Result',
|
|
1135
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
getSwapsPrice(data, options) {
|
|
1140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1141
|
+
return this.handleRequestToIframeAndPost({
|
|
1142
|
+
methodMessage: 'portal:swaps:getPrice',
|
|
1143
|
+
errorMessage: 'portal:swaps:getPriceError',
|
|
1144
|
+
resultMessage: 'portal:swaps:getPriceResult',
|
|
1145
|
+
data: Object.assign(Object.assign({}, data), { options }),
|
|
1146
|
+
});
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
/*******************************
|
|
1150
|
+
* Security Methods
|
|
1151
|
+
*******************************/
|
|
1152
|
+
scanAddresses(data) {
|
|
1153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1154
|
+
return this.handleRequestToIframeAndPost({
|
|
1155
|
+
methodMessage: 'portal:security:scanAddresses',
|
|
1156
|
+
errorMessage: 'portal:security:scanAddressesError',
|
|
1157
|
+
resultMessage: 'portal:security:scanAddressesResult',
|
|
1158
|
+
data,
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
scanEVMTx(data) {
|
|
1163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1164
|
+
return this.handleRequestToIframeAndPost({
|
|
1165
|
+
methodMessage: 'portal:security:scanEVMTx',
|
|
1166
|
+
errorMessage: 'portal:security:scanEVMTxError',
|
|
1167
|
+
resultMessage: 'portal:security:scanEVMTxResult',
|
|
1168
|
+
data,
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
scanEip712Tx(data) {
|
|
1173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1174
|
+
return this.handleRequestToIframeAndPost({
|
|
1175
|
+
methodMessage: 'portal:security:scanEip712Tx',
|
|
1176
|
+
errorMessage: 'portal:security:scanEip712TxError',
|
|
1177
|
+
resultMessage: 'portal:security:scanEip712TxResult',
|
|
1178
|
+
data,
|
|
1179
|
+
});
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
scanSolanaTx(data) {
|
|
1183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1184
|
+
return this.handleRequestToIframeAndPost({
|
|
1185
|
+
methodMessage: 'portal:security:scanSolanaTx',
|
|
1186
|
+
errorMessage: 'portal:security:scanSolanaTxError',
|
|
1187
|
+
resultMessage: 'portal:security:scanSolanaTxResult',
|
|
1188
|
+
data,
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
scanNFTs(nfts) {
|
|
1193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1194
|
+
return this.handleRequestToIframeAndPost({
|
|
1195
|
+
methodMessage: 'portal:security:scanNfts',
|
|
1196
|
+
errorMessage: 'portal:security:scanNftsError',
|
|
1197
|
+
resultMessage: 'portal:security:scanNftsResult',
|
|
1198
|
+
data: nfts,
|
|
1199
|
+
});
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
scanTokens(tokens) {
|
|
1203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1204
|
+
return this.handleRequestToIframeAndPost({
|
|
1205
|
+
methodMessage: 'portal:security:scanTokens',
|
|
1206
|
+
errorMessage: 'portal:security:scanTokensError',
|
|
1207
|
+
resultMessage: 'portal:security:scanTokensResult',
|
|
1208
|
+
data: tokens,
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
scanUrl(url) {
|
|
1213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1214
|
+
return this.handleRequestToIframeAndPost({
|
|
1215
|
+
methodMessage: 'portal:security:scanUrl',
|
|
1216
|
+
errorMessage: 'portal:security:scanUrlError',
|
|
1217
|
+
resultMessage: 'portal:security:scanUrlResult',
|
|
1218
|
+
data: { url },
|
|
1219
|
+
});
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1112
1222
|
/***************************
|
|
1113
1223
|
* Private Methods
|
|
1114
1224
|
***************************/
|
|
@@ -1172,6 +1282,47 @@ class Mpc {
|
|
|
1172
1282
|
: `https://${host}`;
|
|
1173
1283
|
return origin;
|
|
1174
1284
|
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Fetches a scoped JWT for passkey operations from the iframe.
|
|
1287
|
+
* The JWT has only "passkey" permission, reducing blast radius if compromised.
|
|
1288
|
+
*/
|
|
1289
|
+
getPasskeyJwt() {
|
|
1290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1291
|
+
return new Promise((resolve, reject) => {
|
|
1292
|
+
const handleResult = (event) => {
|
|
1293
|
+
const { type, data } = event.data;
|
|
1294
|
+
const { origin } = event;
|
|
1295
|
+
// ignore any broadcast postMessages
|
|
1296
|
+
if (origin !== this.getOrigin()) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
if (type === 'portal:getPasskeyJwtResult') {
|
|
1300
|
+
window.removeEventListener('message', handleResult);
|
|
1301
|
+
window.removeEventListener('message', handleError);
|
|
1302
|
+
resolve(data.token);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
const handleError = (event) => {
|
|
1306
|
+
const { type, data } = event.data;
|
|
1307
|
+
const { origin } = event;
|
|
1308
|
+
if (origin !== this.getOrigin()) {
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
if (type === 'portal:getPasskeyJwtError') {
|
|
1312
|
+
window.removeEventListener('message', handleResult);
|
|
1313
|
+
window.removeEventListener('message', handleError);
|
|
1314
|
+
reject(new Error(data.message));
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
window.addEventListener('message', handleResult);
|
|
1318
|
+
window.addEventListener('message', handleError);
|
|
1319
|
+
this.postMessage({
|
|
1320
|
+
type: 'portal:getPasskeyJwt',
|
|
1321
|
+
data: {},
|
|
1322
|
+
});
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1175
1326
|
postMessage(event) {
|
|
1176
1327
|
var _a, _b;
|
|
1177
1328
|
(_b = (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(event, this.getOrigin());
|