@imtbl/sdk 0.1.9-alpha.3 → 0.1.10-alpha
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/dist/blockchain-data.d.ts +7 -5
- package/dist/blockchain-data.js +3 -3
- package/dist/browser/checkout.js +2 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.cjs +467 -432
- package/dist/index.d.ts +7 -5
- package/dist/index.js +469 -434
- package/dist/passport.js +443 -408
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -148,7 +148,7 @@ const setSearchParams$1 = function (url, ...objects) {
|
|
|
148
148
|
*
|
|
149
149
|
* @export
|
|
150
150
|
*/
|
|
151
|
-
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
151
|
+
const serializeDataIfNeeded$1 = function (value, requestOptions, configuration) {
|
|
152
152
|
const nonString = typeof value !== 'string';
|
|
153
153
|
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
154
154
|
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
@@ -1177,7 +1177,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
|
|
|
1177
1177
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1178
1178
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1179
1179
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1180
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1180
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1181
1181
|
return {
|
|
1182
1182
|
url: toPathString$1(localVarUrlObj),
|
|
1183
1183
|
options: localVarRequestOptions,
|
|
@@ -1468,7 +1468,7 @@ const PassportApiAxiosParamCreator = function (configuration) {
|
|
|
1468
1468
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1469
1469
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1470
1470
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1471
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1471
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1472
1472
|
return {
|
|
1473
1473
|
url: toPathString$1(localVarUrlObj),
|
|
1474
1474
|
options: localVarRequestOptions,
|
|
@@ -2220,7 +2220,7 @@ class APIError extends Error {
|
|
|
2220
2220
|
|
|
2221
2221
|
/* eslint-disable implicit-arrow-linebreak */
|
|
2222
2222
|
const defaultHeaders = {
|
|
2223
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.
|
|
2223
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.10-alpha',
|
|
2224
2224
|
};
|
|
2225
2225
|
/**
|
|
2226
2226
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -2238,10 +2238,10 @@ const createAPIConfiguration = ({ basePath, headers: baseHeaders, }) => {
|
|
|
2238
2238
|
return new index.Configuration(configParams);
|
|
2239
2239
|
};
|
|
2240
2240
|
const production$1 = () => createAPIConfiguration({
|
|
2241
|
-
basePath: 'https://indexer-mr.
|
|
2241
|
+
basePath: 'https://indexer-mr.imtbl.com',
|
|
2242
2242
|
});
|
|
2243
2243
|
const sandbox$1 = () => createAPIConfiguration({
|
|
2244
|
-
basePath: 'https://indexer-mr.
|
|
2244
|
+
basePath: 'https://indexer-mr.sandbox.imtbl.com',
|
|
2245
2245
|
});
|
|
2246
2246
|
class BlockchainDataConfiguration {
|
|
2247
2247
|
apiConfig;
|
|
@@ -2486,7 +2486,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2486
2486
|
chainID,
|
|
2487
2487
|
coreContractAddress,
|
|
2488
2488
|
registrationContractAddress,
|
|
2489
|
-
sdkVersion: 'ts-immutable-sdk-0.1.
|
|
2489
|
+
sdkVersion: 'ts-immutable-sdk-0.1.10-alpha',
|
|
2490
2490
|
});
|
|
2491
2491
|
/**
|
|
2492
2492
|
* Sets `sdkVersion` at the time of build
|
|
@@ -2989,78 +2989,6 @@ class ImmutableXClient {
|
|
|
2989
2989
|
}
|
|
2990
2990
|
}
|
|
2991
2991
|
|
|
2992
|
-
// used to sign message with L1 keys. Used for registration
|
|
2993
|
-
function serializeEthSignature(sig) {
|
|
2994
|
-
// This is because golang appends a recovery param
|
|
2995
|
-
// https://github.com/ethers-io/ethers.js/issues/823
|
|
2996
|
-
return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString(16), 64)
|
|
2997
|
-
+ encUtils.padLeft(sig.s.toString(16), 64)
|
|
2998
|
-
+ encUtils.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
2999
|
-
}
|
|
3000
|
-
function importRecoveryParam(v) {
|
|
3001
|
-
const isValidBigNumber = new BN(v, 16).cmp(new BN(27)) !== -1
|
|
3002
|
-
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
3003
|
-
: new BN(v, 16).toNumber();
|
|
3004
|
-
return v.trim()
|
|
3005
|
-
? isValidBigNumber
|
|
3006
|
-
: undefined;
|
|
3007
|
-
}
|
|
3008
|
-
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
3009
|
-
function deserializeSignature(sig, size = 64) {
|
|
3010
|
-
const removedHexPrefixSig = encUtils.removeHexPrefix(sig);
|
|
3011
|
-
return {
|
|
3012
|
-
r: new BN(removedHexPrefixSig.substring(0, size), 'hex'),
|
|
3013
|
-
s: new BN(removedHexPrefixSig.substring(size, size * 2), 'hex'),
|
|
3014
|
-
recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
|
|
3015
|
-
};
|
|
3016
|
-
}
|
|
3017
|
-
async function signRaw(payload, signer) {
|
|
3018
|
-
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
3019
|
-
return serializeEthSignature(signature);
|
|
3020
|
-
}
|
|
3021
|
-
async function signMessage(message, signer) {
|
|
3022
|
-
const ethAddress = await signer.getAddress();
|
|
3023
|
-
const ethSignature = await signRaw(message, signer);
|
|
3024
|
-
return {
|
|
3025
|
-
message,
|
|
3026
|
-
ethAddress,
|
|
3027
|
-
ethSignature,
|
|
3028
|
-
};
|
|
3029
|
-
}
|
|
3030
|
-
|
|
3031
|
-
/**
|
|
3032
|
-
* Helper method to convert token type to a SignableToken type
|
|
3033
|
-
* @param token - the token type to convert to a SignableToken type
|
|
3034
|
-
* @returns the converted SignableToken
|
|
3035
|
-
*/
|
|
3036
|
-
function convertToSignableToken(token) {
|
|
3037
|
-
switch (token.type) {
|
|
3038
|
-
case 'ERC721':
|
|
3039
|
-
return {
|
|
3040
|
-
type: 'ERC721',
|
|
3041
|
-
data: {
|
|
3042
|
-
token_id: token.tokenId,
|
|
3043
|
-
token_address: token.tokenAddress,
|
|
3044
|
-
},
|
|
3045
|
-
};
|
|
3046
|
-
case 'ERC20':
|
|
3047
|
-
return {
|
|
3048
|
-
type: 'ERC20',
|
|
3049
|
-
data: {
|
|
3050
|
-
token_address: token.tokenAddress,
|
|
3051
|
-
},
|
|
3052
|
-
};
|
|
3053
|
-
case 'ETH':
|
|
3054
|
-
default:
|
|
3055
|
-
return {
|
|
3056
|
-
type: 'ETH',
|
|
3057
|
-
data: {
|
|
3058
|
-
decimals: 18,
|
|
3059
|
-
},
|
|
3060
|
-
};
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
|
|
3064
2992
|
function bind(fn, thisArg) {
|
|
3065
2993
|
return function wrap() {
|
|
3066
2994
|
return fn.apply(thisArg, arguments);
|
|
@@ -6272,7 +6200,7 @@ var globalAxios = axios;
|
|
|
6272
6200
|
/* tslint:disable */
|
|
6273
6201
|
/* eslint-disable */
|
|
6274
6202
|
/**
|
|
6275
|
-
*
|
|
6203
|
+
* Guardian
|
|
6276
6204
|
* Guardian API
|
|
6277
6205
|
*
|
|
6278
6206
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6282,7 +6210,7 @@ var globalAxios = axios;
|
|
|
6282
6210
|
* https://openapi-generator.tech
|
|
6283
6211
|
* Do not edit the class manually.
|
|
6284
6212
|
*/
|
|
6285
|
-
const BASE_PATH = "
|
|
6213
|
+
const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
6286
6214
|
/**
|
|
6287
6215
|
*
|
|
6288
6216
|
* @export
|
|
@@ -6319,7 +6247,7 @@ class RequiredError extends Error {
|
|
|
6319
6247
|
/* tslint:disable */
|
|
6320
6248
|
/* eslint-disable */
|
|
6321
6249
|
/**
|
|
6322
|
-
*
|
|
6250
|
+
* Guardian
|
|
6323
6251
|
* Guardian API
|
|
6324
6252
|
*
|
|
6325
6253
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6385,6 +6313,19 @@ const setSearchParams = function (url, ...objects) {
|
|
|
6385
6313
|
setFlattenedQueryParams(searchParams, objects);
|
|
6386
6314
|
url.search = searchParams.toString();
|
|
6387
6315
|
};
|
|
6316
|
+
/**
|
|
6317
|
+
*
|
|
6318
|
+
* @export
|
|
6319
|
+
*/
|
|
6320
|
+
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
6321
|
+
const nonString = typeof value !== 'string';
|
|
6322
|
+
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
6323
|
+
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
6324
|
+
: nonString;
|
|
6325
|
+
return needsSerialization
|
|
6326
|
+
? JSON.stringify(value !== undefined ? value : {})
|
|
6327
|
+
: (value || "");
|
|
6328
|
+
};
|
|
6388
6329
|
/**
|
|
6389
6330
|
*
|
|
6390
6331
|
* @export
|
|
@@ -6406,7 +6347,7 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6406
6347
|
/* tslint:disable */
|
|
6407
6348
|
/* eslint-disable */
|
|
6408
6349
|
/**
|
|
6409
|
-
*
|
|
6350
|
+
* Guardian
|
|
6410
6351
|
* Guardian API
|
|
6411
6352
|
*
|
|
6412
6353
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6417,22 +6358,25 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6417
6358
|
* Do not edit the class manually.
|
|
6418
6359
|
*/
|
|
6419
6360
|
/**
|
|
6420
|
-
*
|
|
6361
|
+
* TransactionsApi - axios parameter creator
|
|
6421
6362
|
* @export
|
|
6422
6363
|
*/
|
|
6423
|
-
const
|
|
6364
|
+
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6424
6365
|
return {
|
|
6425
6366
|
/**
|
|
6426
|
-
*
|
|
6427
|
-
* @summary
|
|
6367
|
+
* Approve a pending transaction
|
|
6368
|
+
* @summary Approve a pending transaction given chain
|
|
6428
6369
|
* @param {string} payloadHash Hash for the payload
|
|
6370
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transactio
|
|
6429
6371
|
* @param {*} [options] Override http request option.
|
|
6430
6372
|
* @throws {RequiredError}
|
|
6431
6373
|
*/
|
|
6432
|
-
|
|
6374
|
+
approvePendingTransaction: async (payloadHash, transactionApprovalRequest, options = {}) => {
|
|
6433
6375
|
// verify required parameter 'payloadHash' is not null or undefined
|
|
6434
|
-
assertParamExists('
|
|
6435
|
-
|
|
6376
|
+
assertParamExists('approvePendingTransaction', 'payloadHash', payloadHash);
|
|
6377
|
+
// verify required parameter 'transactionApprovalRequest' is not null or undefined
|
|
6378
|
+
assertParamExists('approvePendingTransaction', 'transactionApprovalRequest', transactionApprovalRequest);
|
|
6379
|
+
const localVarPath = `/guardian/v1/transactions/{payloadHash}/approve`
|
|
6436
6380
|
.replace(`{${"payloadHash"}}`, encodeURIComponent(String(payloadHash)));
|
|
6437
6381
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6438
6382
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -6446,80 +6390,58 @@ const StarkexTransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6446
6390
|
// authentication BearerAuth required
|
|
6447
6391
|
// http bearer authentication required
|
|
6448
6392
|
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6393
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
6449
6394
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6450
6395
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6451
6396
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6397
|
+
localVarRequestOptions.data = serializeDataIfNeeded(transactionApprovalRequest, localVarRequestOptions, configuration);
|
|
6452
6398
|
return {
|
|
6453
6399
|
url: toPathString(localVarUrlObj),
|
|
6454
6400
|
options: localVarRequestOptions,
|
|
6455
6401
|
};
|
|
6456
6402
|
},
|
|
6457
|
-
};
|
|
6458
|
-
};
|
|
6459
|
-
/**
|
|
6460
|
-
* StarkexTransactionsApi - functional programming interface
|
|
6461
|
-
* @export
|
|
6462
|
-
*/
|
|
6463
|
-
const StarkexTransactionsApiFp = function (configuration) {
|
|
6464
|
-
const localVarAxiosParamCreator = StarkexTransactionsApiAxiosParamCreator(configuration);
|
|
6465
|
-
return {
|
|
6466
6403
|
/**
|
|
6467
|
-
* Check if
|
|
6468
|
-
* @summary Evaluate
|
|
6469
|
-
* @param {string} payloadHash
|
|
6404
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6405
|
+
* @summary Evaluate a transaction
|
|
6406
|
+
* @param {string} id Transaction identifier: payloadHash on StarkEx or EVM ID
|
|
6407
|
+
* @param {TransactionEvaluationRequest} transactionEvaluationRequest Specifies the kind of transaction
|
|
6470
6408
|
* @param {*} [options] Override http request option.
|
|
6471
6409
|
* @throws {RequiredError}
|
|
6472
6410
|
*/
|
|
6473
|
-
async
|
|
6474
|
-
|
|
6475
|
-
|
|
6411
|
+
evaluateTransaction: async (id, transactionEvaluationRequest, options = {}) => {
|
|
6412
|
+
// verify required parameter 'id' is not null or undefined
|
|
6413
|
+
assertParamExists('evaluateTransaction', 'id', id);
|
|
6414
|
+
// verify required parameter 'transactionEvaluationRequest' is not null or undefined
|
|
6415
|
+
assertParamExists('evaluateTransaction', 'transactionEvaluationRequest', transactionEvaluationRequest);
|
|
6416
|
+
const localVarPath = `/guardian/v1/transactions/{id}/evaluate`
|
|
6417
|
+
.replace(`{${"id"}}`, encodeURIComponent(String(id)));
|
|
6418
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6419
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
6420
|
+
let baseOptions;
|
|
6421
|
+
if (configuration) {
|
|
6422
|
+
baseOptions = configuration.baseOptions;
|
|
6423
|
+
}
|
|
6424
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
6425
|
+
const localVarHeaderParameter = {};
|
|
6426
|
+
const localVarQueryParameter = {};
|
|
6427
|
+
// authentication BearerAuth required
|
|
6428
|
+
// http bearer authentication required
|
|
6429
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6430
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
6431
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6432
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6433
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6434
|
+
localVarRequestOptions.data = serializeDataIfNeeded(transactionEvaluationRequest, localVarRequestOptions, configuration);
|
|
6435
|
+
return {
|
|
6436
|
+
url: toPathString(localVarUrlObj),
|
|
6437
|
+
options: localVarRequestOptions,
|
|
6438
|
+
};
|
|
6476
6439
|
},
|
|
6477
|
-
};
|
|
6478
|
-
};
|
|
6479
|
-
/**
|
|
6480
|
-
* StarkexTransactionsApi - object-oriented interface
|
|
6481
|
-
* @export
|
|
6482
|
-
* @class StarkexTransactionsApi
|
|
6483
|
-
* @extends {BaseAPI}
|
|
6484
|
-
*/
|
|
6485
|
-
class StarkexTransactionsApi extends BaseAPI {
|
|
6486
|
-
/**
|
|
6487
|
-
* Check if it is a valid transaction by payload hash
|
|
6488
|
-
* @summary Evaluate if it is an valid transaction
|
|
6489
|
-
* @param {StarkexTransactionsApiEvaluateStarkexTransactionRequest} requestParameters Request parameters.
|
|
6490
|
-
* @param {*} [options] Override http request option.
|
|
6491
|
-
* @throws {RequiredError}
|
|
6492
|
-
* @memberof StarkexTransactionsApi
|
|
6493
|
-
*/
|
|
6494
|
-
evaluateStarkexTransaction(requestParameters, options) {
|
|
6495
|
-
return StarkexTransactionsApiFp(this.configuration).evaluateStarkexTransaction(requestParameters.payloadHash, options).then((request) => request(this.axios, this.basePath));
|
|
6496
|
-
}
|
|
6497
|
-
}
|
|
6498
|
-
|
|
6499
|
-
/* tslint:disable */
|
|
6500
|
-
/* eslint-disable */
|
|
6501
|
-
/**
|
|
6502
|
-
* Swagger Guardian
|
|
6503
|
-
* Guardian API
|
|
6504
|
-
*
|
|
6505
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6506
|
-
* Contact: support@immutable.com
|
|
6507
|
-
*
|
|
6508
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
6509
|
-
* https://openapi-generator.tech
|
|
6510
|
-
* Do not edit the class manually.
|
|
6511
|
-
*/
|
|
6512
|
-
/**
|
|
6513
|
-
* TransactionsApi - axios parameter creator
|
|
6514
|
-
* @export
|
|
6515
|
-
*/
|
|
6516
|
-
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6517
|
-
return {
|
|
6518
6440
|
/**
|
|
6519
6441
|
* Get a transaction by payload hash
|
|
6520
6442
|
* @summary Info for a specific transaction
|
|
6521
6443
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6522
|
-
* @param {
|
|
6444
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6523
6445
|
* @param {number} [chainID] ID of evm chain
|
|
6524
6446
|
* @param {*} [options] Override http request option.
|
|
6525
6447
|
* @throws {RequiredError}
|
|
@@ -6566,11 +6488,35 @@ const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6566
6488
|
const TransactionsApiFp = function (configuration) {
|
|
6567
6489
|
const localVarAxiosParamCreator = TransactionsApiAxiosParamCreator(configuration);
|
|
6568
6490
|
return {
|
|
6491
|
+
/**
|
|
6492
|
+
* Approve a pending transaction
|
|
6493
|
+
* @summary Approve a pending transaction given chain
|
|
6494
|
+
* @param {string} payloadHash Hash for the payload
|
|
6495
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transactio
|
|
6496
|
+
* @param {*} [options] Override http request option.
|
|
6497
|
+
* @throws {RequiredError}
|
|
6498
|
+
*/
|
|
6499
|
+
async approvePendingTransaction(payloadHash, transactionApprovalRequest, options) {
|
|
6500
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.approvePendingTransaction(payloadHash, transactionApprovalRequest, options);
|
|
6501
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
6502
|
+
},
|
|
6503
|
+
/**
|
|
6504
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6505
|
+
* @summary Evaluate a transaction
|
|
6506
|
+
* @param {string} id Transaction identifier: payloadHash on StarkEx or EVM ID
|
|
6507
|
+
* @param {TransactionEvaluationRequest} transactionEvaluationRequest Specifies the kind of transaction
|
|
6508
|
+
* @param {*} [options] Override http request option.
|
|
6509
|
+
* @throws {RequiredError}
|
|
6510
|
+
*/
|
|
6511
|
+
async evaluateTransaction(id, transactionEvaluationRequest, options) {
|
|
6512
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.evaluateTransaction(id, transactionEvaluationRequest, options);
|
|
6513
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
6514
|
+
},
|
|
6569
6515
|
/**
|
|
6570
6516
|
* Get a transaction by payload hash
|
|
6571
6517
|
* @summary Info for a specific transaction
|
|
6572
6518
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6573
|
-
* @param {
|
|
6519
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6574
6520
|
* @param {number} [chainID] ID of evm chain
|
|
6575
6521
|
* @param {*} [options] Override http request option.
|
|
6576
6522
|
* @throws {RequiredError}
|
|
@@ -6588,6 +6534,28 @@ const TransactionsApiFp = function (configuration) {
|
|
|
6588
6534
|
* @extends {BaseAPI}
|
|
6589
6535
|
*/
|
|
6590
6536
|
class TransactionsApi extends BaseAPI {
|
|
6537
|
+
/**
|
|
6538
|
+
* Approve a pending transaction
|
|
6539
|
+
* @summary Approve a pending transaction given chain
|
|
6540
|
+
* @param {TransactionsApiApprovePendingTransactionRequest} requestParameters Request parameters.
|
|
6541
|
+
* @param {*} [options] Override http request option.
|
|
6542
|
+
* @throws {RequiredError}
|
|
6543
|
+
* @memberof TransactionsApi
|
|
6544
|
+
*/
|
|
6545
|
+
approvePendingTransaction(requestParameters, options) {
|
|
6546
|
+
return TransactionsApiFp(this.configuration).approvePendingTransaction(requestParameters.payloadHash, requestParameters.transactionApprovalRequest, options).then((request) => request(this.axios, this.basePath));
|
|
6547
|
+
}
|
|
6548
|
+
/**
|
|
6549
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6550
|
+
* @summary Evaluate a transaction
|
|
6551
|
+
* @param {TransactionsApiEvaluateTransactionRequest} requestParameters Request parameters.
|
|
6552
|
+
* @param {*} [options] Override http request option.
|
|
6553
|
+
* @throws {RequiredError}
|
|
6554
|
+
* @memberof TransactionsApi
|
|
6555
|
+
*/
|
|
6556
|
+
evaluateTransaction(requestParameters, options) {
|
|
6557
|
+
return TransactionsApiFp(this.configuration).evaluateTransaction(requestParameters.id, requestParameters.transactionEvaluationRequest, options).then((request) => request(this.axios, this.basePath));
|
|
6558
|
+
}
|
|
6591
6559
|
/**
|
|
6592
6560
|
* Get a transaction by payload hash
|
|
6593
6561
|
* @summary Info for a specific transaction
|
|
@@ -6604,7 +6572,7 @@ class TransactionsApi extends BaseAPI {
|
|
|
6604
6572
|
/* tslint:disable */
|
|
6605
6573
|
/* eslint-disable */
|
|
6606
6574
|
/**
|
|
6607
|
-
*
|
|
6575
|
+
* Guardian
|
|
6608
6576
|
* Guardian API
|
|
6609
6577
|
*
|
|
6610
6578
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6689,6 +6657,78 @@ class Configuration {
|
|
|
6689
6657
|
}
|
|
6690
6658
|
}
|
|
6691
6659
|
|
|
6660
|
+
// used to sign message with L1 keys. Used for registration
|
|
6661
|
+
function serializeEthSignature(sig) {
|
|
6662
|
+
// This is because golang appends a recovery param
|
|
6663
|
+
// https://github.com/ethers-io/ethers.js/issues/823
|
|
6664
|
+
return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString(16), 64)
|
|
6665
|
+
+ encUtils.padLeft(sig.s.toString(16), 64)
|
|
6666
|
+
+ encUtils.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
6667
|
+
}
|
|
6668
|
+
function importRecoveryParam(v) {
|
|
6669
|
+
const isValidBigNumber = new BN(v, 16).cmp(new BN(27)) !== -1
|
|
6670
|
+
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
6671
|
+
: new BN(v, 16).toNumber();
|
|
6672
|
+
return v.trim()
|
|
6673
|
+
? isValidBigNumber
|
|
6674
|
+
: undefined;
|
|
6675
|
+
}
|
|
6676
|
+
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
6677
|
+
function deserializeSignature(sig, size = 64) {
|
|
6678
|
+
const removedHexPrefixSig = encUtils.removeHexPrefix(sig);
|
|
6679
|
+
return {
|
|
6680
|
+
r: new BN(removedHexPrefixSig.substring(0, size), 'hex'),
|
|
6681
|
+
s: new BN(removedHexPrefixSig.substring(size, size * 2), 'hex'),
|
|
6682
|
+
recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
|
|
6683
|
+
};
|
|
6684
|
+
}
|
|
6685
|
+
async function signRaw(payload, signer) {
|
|
6686
|
+
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
6687
|
+
return serializeEthSignature(signature);
|
|
6688
|
+
}
|
|
6689
|
+
async function signMessage(message, signer) {
|
|
6690
|
+
const ethAddress = await signer.getAddress();
|
|
6691
|
+
const ethSignature = await signRaw(message, signer);
|
|
6692
|
+
return {
|
|
6693
|
+
message,
|
|
6694
|
+
ethAddress,
|
|
6695
|
+
ethSignature,
|
|
6696
|
+
};
|
|
6697
|
+
}
|
|
6698
|
+
|
|
6699
|
+
/**
|
|
6700
|
+
* Helper method to convert token type to a SignableToken type
|
|
6701
|
+
* @param token - the token type to convert to a SignableToken type
|
|
6702
|
+
* @returns the converted SignableToken
|
|
6703
|
+
*/
|
|
6704
|
+
function convertToSignableToken(token) {
|
|
6705
|
+
switch (token.type) {
|
|
6706
|
+
case 'ERC721':
|
|
6707
|
+
return {
|
|
6708
|
+
type: 'ERC721',
|
|
6709
|
+
data: {
|
|
6710
|
+
token_id: token.tokenId,
|
|
6711
|
+
token_address: token.tokenAddress,
|
|
6712
|
+
},
|
|
6713
|
+
};
|
|
6714
|
+
case 'ERC20':
|
|
6715
|
+
return {
|
|
6716
|
+
type: 'ERC20',
|
|
6717
|
+
data: {
|
|
6718
|
+
token_address: token.tokenAddress,
|
|
6719
|
+
},
|
|
6720
|
+
};
|
|
6721
|
+
case 'ETH':
|
|
6722
|
+
default:
|
|
6723
|
+
return {
|
|
6724
|
+
type: 'ETH',
|
|
6725
|
+
data: {
|
|
6726
|
+
decimals: 18,
|
|
6727
|
+
},
|
|
6728
|
+
};
|
|
6729
|
+
}
|
|
6730
|
+
}
|
|
6731
|
+
|
|
6692
6732
|
var PassportErrorType;
|
|
6693
6733
|
(function (PassportErrorType) {
|
|
6694
6734
|
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
@@ -6847,17 +6887,84 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
|
6847
6887
|
return createStarkSigner(privateKey);
|
|
6848
6888
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
6849
6889
|
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6890
|
+
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
6891
|
+
const MAX_RETRIES = 3;
|
|
6892
|
+
const wait = (ms) => new Promise((resolve) => {
|
|
6893
|
+
setTimeout(() => resolve(), ms);
|
|
6894
|
+
});
|
|
6895
|
+
const retryWithDelay = async (fn, options) => {
|
|
6896
|
+
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
|
|
6897
|
+
try {
|
|
6898
|
+
return await fn();
|
|
6899
|
+
}
|
|
6900
|
+
catch (err) {
|
|
6901
|
+
if (retries <= 0) {
|
|
6902
|
+
return Promise.reject(finalErr);
|
|
6903
|
+
}
|
|
6904
|
+
await wait(interval);
|
|
6905
|
+
return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
|
|
6906
|
+
}
|
|
6907
|
+
finally {
|
|
6908
|
+
if (retries <= 0) {
|
|
6909
|
+
finallyFn();
|
|
6910
|
+
}
|
|
6911
|
+
}
|
|
6912
|
+
};
|
|
6913
|
+
|
|
6914
|
+
class GuardianClient {
|
|
6915
|
+
transactionAPI;
|
|
6916
|
+
confirmationScreen;
|
|
6917
|
+
imxEtherAddress;
|
|
6918
|
+
constructor({ imxPublicApiDomain, accessToken, confirmationScreen, imxEtherAddress, }) {
|
|
6919
|
+
this.confirmationScreen = confirmationScreen;
|
|
6920
|
+
this.transactionAPI = new TransactionsApi(new Configuration({
|
|
6921
|
+
accessToken,
|
|
6922
|
+
basePath: imxPublicApiDomain,
|
|
6923
|
+
}));
|
|
6924
|
+
this.imxEtherAddress = imxEtherAddress;
|
|
6925
|
+
}
|
|
6926
|
+
async validate({ popupWindowSize, payloadHash }) {
|
|
6927
|
+
this.confirmationScreen.loading(popupWindowSize);
|
|
6928
|
+
const finallyFn = () => {
|
|
6929
|
+
this.confirmationScreen.closeWindow();
|
|
6930
|
+
};
|
|
6931
|
+
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
6932
|
+
transactionID: payloadHash,
|
|
6933
|
+
chainType: 'starkex',
|
|
6934
|
+
}), { finallyFn });
|
|
6935
|
+
if (!transactionRes.data.id) {
|
|
6936
|
+
throw new Error("Transaction doesn't exists");
|
|
6937
|
+
}
|
|
6938
|
+
const evaluateStarkexRes = await this.transactionAPI.evaluateTransaction({
|
|
6939
|
+
id: payloadHash,
|
|
6940
|
+
transactionEvaluationRequest: {
|
|
6941
|
+
chainType: 'starkex',
|
|
6942
|
+
},
|
|
6943
|
+
});
|
|
6944
|
+
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
6945
|
+
if (confirmationRequired) {
|
|
6946
|
+
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
|
|
6947
|
+
if (!confirmationResult.confirmed) {
|
|
6948
|
+
throw new Error('Transaction rejected by user');
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
else {
|
|
6952
|
+
this.confirmationScreen.closeWindow();
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
}
|
|
6956
|
+
|
|
6957
|
+
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
6958
|
+
return withPassportError(async () => {
|
|
6959
|
+
const { ethAddress } = user.imx;
|
|
6960
|
+
const transferAmount = request.amount;
|
|
6961
|
+
const signableResult = await exchangesApi.getExchangeSignableTransfer({
|
|
6962
|
+
id: request.transactionID,
|
|
6963
|
+
getSignableTransferRequest: {
|
|
6964
|
+
sender: ethAddress,
|
|
6965
|
+
token: convertToSignableToken(request),
|
|
6966
|
+
amount: transferAmount,
|
|
6967
|
+
receiver: request.receiver,
|
|
6861
6968
|
},
|
|
6862
6969
|
});
|
|
6863
6970
|
const starkAddress = await starkSigner.getAddress();
|
|
@@ -6891,165 +6998,16 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
|
|
|
6891
6998
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
6892
6999
|
}
|
|
6893
7000
|
|
|
6894
|
-
var ReceiveMessage;
|
|
6895
|
-
(function (ReceiveMessage) {
|
|
6896
|
-
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
6897
|
-
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
6898
|
-
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
6899
|
-
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
6900
|
-
var SendMessage;
|
|
6901
|
-
(function (SendMessage) {
|
|
6902
|
-
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
6903
|
-
})(SendMessage || (SendMessage = {}));
|
|
6904
|
-
var TransactionTypes;
|
|
6905
|
-
(function (TransactionTypes) {
|
|
6906
|
-
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
6907
|
-
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
6908
|
-
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
6909
|
-
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
6910
|
-
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
6911
|
-
})(TransactionTypes || (TransactionTypes = {}));
|
|
6912
|
-
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
6913
|
-
|
|
6914
|
-
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
6915
|
-
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
6916
|
-
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
6917
|
-
const newWindow = window.open(url, title, `
|
|
6918
|
-
scrollbars=yes,
|
|
6919
|
-
width=${width},
|
|
6920
|
-
height=${height},
|
|
6921
|
-
top=${top},
|
|
6922
|
-
left=${left}
|
|
6923
|
-
`);
|
|
6924
|
-
if (!newWindow) {
|
|
6925
|
-
throw new Error('Failed to open confirmation screen');
|
|
6926
|
-
}
|
|
6927
|
-
newWindow.focus();
|
|
6928
|
-
return newWindow;
|
|
6929
|
-
};
|
|
6930
|
-
|
|
6931
|
-
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
6932
|
-
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
6933
|
-
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
6934
|
-
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
6935
|
-
class ConfirmationScreen {
|
|
6936
|
-
config;
|
|
6937
|
-
confirmationWindow;
|
|
6938
|
-
constructor(config) {
|
|
6939
|
-
this.config = config;
|
|
6940
|
-
}
|
|
6941
|
-
postMessage(destinationWindow, accessToken, message) {
|
|
6942
|
-
destinationWindow.postMessage({
|
|
6943
|
-
eventType: PASSPORT_EVENT_TYPE,
|
|
6944
|
-
accessToken,
|
|
6945
|
-
...message,
|
|
6946
|
-
}, this.config.passportDomain);
|
|
6947
|
-
}
|
|
6948
|
-
startTransaction(accessToken, transaction, popupOptions) {
|
|
6949
|
-
return new Promise((resolve, reject) => {
|
|
6950
|
-
const messageHandler = ({ data, origin }) => {
|
|
6951
|
-
if (origin !== this.config.passportDomain
|
|
6952
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
6953
|
-
return;
|
|
6954
|
-
}
|
|
6955
|
-
switch (data.messageType) {
|
|
6956
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
6957
|
-
// TODO: remove once fixed
|
|
6958
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
6959
|
-
this.postMessage(confirmationWindow, accessToken, {
|
|
6960
|
-
messageType: SendMessage.TRANSACTION_START,
|
|
6961
|
-
messageData: transaction,
|
|
6962
|
-
});
|
|
6963
|
-
break;
|
|
6964
|
-
}
|
|
6965
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
6966
|
-
resolve({ confirmed: true });
|
|
6967
|
-
break;
|
|
6968
|
-
}
|
|
6969
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
6970
|
-
reject(new Error('Transaction error'));
|
|
6971
|
-
break;
|
|
6972
|
-
}
|
|
6973
|
-
default:
|
|
6974
|
-
reject(new Error('Unsupported message type'));
|
|
6975
|
-
}
|
|
6976
|
-
};
|
|
6977
|
-
window.addEventListener('message', messageHandler);
|
|
6978
|
-
const confirmationWindow = openPopupCenter({
|
|
6979
|
-
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
6980
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
6981
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
6982
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
6983
|
-
});
|
|
6984
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
6985
|
-
const timer = setInterval(() => {
|
|
6986
|
-
if (confirmationWindow.closed) {
|
|
6987
|
-
clearInterval(timer);
|
|
6988
|
-
window.removeEventListener('message', messageHandler);
|
|
6989
|
-
resolve({ confirmed: false });
|
|
6990
|
-
}
|
|
6991
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
6992
|
-
});
|
|
6993
|
-
}
|
|
6994
|
-
startGuardianTransaction(transactionId) {
|
|
6995
|
-
return new Promise((resolve, reject) => {
|
|
6996
|
-
const messageHandler = ({ data, origin }) => {
|
|
6997
|
-
if (origin !== this.config.passportDomain
|
|
6998
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
6999
|
-
return;
|
|
7000
|
-
}
|
|
7001
|
-
switch (data.messageType) {
|
|
7002
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7003
|
-
break;
|
|
7004
|
-
}
|
|
7005
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7006
|
-
resolve({ confirmed: true });
|
|
7007
|
-
break;
|
|
7008
|
-
}
|
|
7009
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7010
|
-
reject(new Error('Transaction error'));
|
|
7011
|
-
break;
|
|
7012
|
-
}
|
|
7013
|
-
default:
|
|
7014
|
-
reject(new Error('Unsupported message type'));
|
|
7015
|
-
}
|
|
7016
|
-
};
|
|
7017
|
-
window.addEventListener('message', messageHandler);
|
|
7018
|
-
if (!this.confirmationWindow) {
|
|
7019
|
-
resolve({ confirmed: false });
|
|
7020
|
-
return;
|
|
7021
|
-
}
|
|
7022
|
-
// eslint-disable-next-line max-len
|
|
7023
|
-
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&chainType=starkex`;
|
|
7024
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7025
|
-
const timer = setInterval(() => {
|
|
7026
|
-
if (this.confirmationWindow?.closed) {
|
|
7027
|
-
clearInterval(timer);
|
|
7028
|
-
window.removeEventListener('message', messageHandler);
|
|
7029
|
-
resolve({ confirmed: false });
|
|
7030
|
-
}
|
|
7031
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7032
|
-
});
|
|
7033
|
-
}
|
|
7034
|
-
loading(popupOptions) {
|
|
7035
|
-
this.confirmationWindow = openPopupCenter({
|
|
7036
|
-
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7037
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
7038
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7039
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7040
|
-
});
|
|
7041
|
-
}
|
|
7042
|
-
closeWindow() {
|
|
7043
|
-
this.confirmationWindow?.close();
|
|
7044
|
-
}
|
|
7045
|
-
}
|
|
7046
|
-
|
|
7047
7001
|
const ERC721$1 = 'ERC721';
|
|
7048
|
-
async function createOrder$1({ starkSigner, user, request, ordersApi,
|
|
7002
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
|
|
7049
7003
|
return withPassportError(async () => {
|
|
7050
7004
|
const { ethAddress } = user.imx;
|
|
7051
7005
|
const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
|
|
7052
7006
|
const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
|
|
7007
|
+
const headers = {
|
|
7008
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7009
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7010
|
+
};
|
|
7053
7011
|
const getSignableOrderRequestV3 = {
|
|
7054
7012
|
user: ethAddress,
|
|
7055
7013
|
amount_buy: amountBuy,
|
|
@@ -7061,14 +7019,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7061
7019
|
};
|
|
7062
7020
|
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
7063
7021
|
getSignableOrderRequestV3,
|
|
7022
|
+
}, { headers });
|
|
7023
|
+
await guardianClient.validate({
|
|
7024
|
+
payloadHash: getSignableOrderResponse.data.payload_hash,
|
|
7064
7025
|
});
|
|
7065
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7066
|
-
transactionType: TransactionTypes.createOrder,
|
|
7067
|
-
transactionData: getSignableOrderRequestV3,
|
|
7068
|
-
});
|
|
7069
|
-
if (!confirmationResult.confirmed) {
|
|
7070
|
-
throw new Error('Transaction rejected by user');
|
|
7071
|
-
}
|
|
7072
7026
|
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
7073
7027
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7074
7028
|
const signableResultData = getSignableOrderResponse.data;
|
|
@@ -7088,11 +7042,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7088
7042
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7089
7043
|
},
|
|
7090
7044
|
};
|
|
7091
|
-
const
|
|
7092
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7093
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7094
|
-
};
|
|
7095
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
7045
|
+
const createOrderResponse = await ordersApi.createOrderV3(orderParams, {
|
|
7096
7046
|
headers,
|
|
7097
7047
|
});
|
|
7098
7048
|
return {
|
|
@@ -7100,28 +7050,24 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7100
7050
|
};
|
|
7101
7051
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
7102
7052
|
}
|
|
7103
|
-
async function cancelOrder$1({ user, starkSigner, request, ordersApi,
|
|
7053
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
|
|
7104
7054
|
return withPassportError(async () => {
|
|
7105
7055
|
const getSignableCancelOrderRequest = {
|
|
7106
7056
|
order_id: request.order_id,
|
|
7107
7057
|
};
|
|
7108
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
7109
|
-
getSignableCancelOrderRequest,
|
|
7110
|
-
});
|
|
7111
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7112
|
-
transactionType: TransactionTypes.cancelOrder,
|
|
7113
|
-
transactionData: getSignableCancelOrderRequest,
|
|
7114
|
-
});
|
|
7115
|
-
if (!confirmationResult.confirmed) {
|
|
7116
|
-
throw new Error('Transaction rejected by user');
|
|
7117
|
-
}
|
|
7118
|
-
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7119
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7120
7058
|
const headers = {
|
|
7121
7059
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7122
7060
|
Authorization: `Bearer ${user.accessToken}`,
|
|
7123
7061
|
};
|
|
7124
|
-
const
|
|
7062
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrderV3({
|
|
7063
|
+
getSignableCancelOrderRequest,
|
|
7064
|
+
}, { headers });
|
|
7065
|
+
await guardianClient.validate({
|
|
7066
|
+
payloadHash: getSignableCancelOrderResponse.data.payload_hash,
|
|
7067
|
+
});
|
|
7068
|
+
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7069
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7070
|
+
const cancelOrderResponse = await ordersApi.cancelOrderV3({
|
|
7125
7071
|
id: request.order_id.toString(),
|
|
7126
7072
|
cancelOrderRequest: {
|
|
7127
7073
|
order_id: request.order_id,
|
|
@@ -7161,7 +7107,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
7161
7107
|
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7162
7108
|
}
|
|
7163
7109
|
|
|
7164
|
-
async function createTrade$1({ request, tradesApi, user, starkSigner,
|
|
7110
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
7165
7111
|
return withPassportError(async () => {
|
|
7166
7112
|
const { ethAddress } = user.imx;
|
|
7167
7113
|
const getSignableTradeRequest = {
|
|
@@ -7170,16 +7116,14 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7170
7116
|
order_id: request.order_id,
|
|
7171
7117
|
user: ethAddress,
|
|
7172
7118
|
};
|
|
7119
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7120
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7173
7121
|
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
7174
7122
|
getSignableTradeRequest,
|
|
7123
|
+
}, { headers });
|
|
7124
|
+
await guardianClient.validate({
|
|
7125
|
+
payloadHash: getSignableTradeResponse.data.payload_hash,
|
|
7175
7126
|
});
|
|
7176
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7177
|
-
transactionType: TransactionTypes.createTrade,
|
|
7178
|
-
transactionData: getSignableTradeRequest,
|
|
7179
|
-
});
|
|
7180
|
-
if (!confirmationResult.confirmed) {
|
|
7181
|
-
throw new Error('Transaction rejected by user');
|
|
7182
|
-
}
|
|
7183
7127
|
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
7184
7128
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7185
7129
|
const { data: signableResultData } = getSignableTradeResponse;
|
|
@@ -7201,8 +7145,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7201
7145
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7202
7146
|
},
|
|
7203
7147
|
};
|
|
7204
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7205
|
-
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7206
7148
|
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
7207
7149
|
headers,
|
|
7208
7150
|
});
|
|
@@ -7210,66 +7152,8 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7210
7152
|
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
7211
7153
|
}
|
|
7212
7154
|
|
|
7213
|
-
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
7214
|
-
const MAX_RETRIES = 3;
|
|
7215
|
-
const wait = (ms) => new Promise((resolve) => {
|
|
7216
|
-
setTimeout(() => resolve(), ms);
|
|
7217
|
-
});
|
|
7218
|
-
const retryWithDelay = async (fn, options) => {
|
|
7219
|
-
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
|
|
7220
|
-
try {
|
|
7221
|
-
return await fn();
|
|
7222
|
-
}
|
|
7223
|
-
catch (err) {
|
|
7224
|
-
if (retries <= 0) {
|
|
7225
|
-
return Promise.reject(finalErr);
|
|
7226
|
-
}
|
|
7227
|
-
await wait(interval);
|
|
7228
|
-
return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
|
|
7229
|
-
}
|
|
7230
|
-
finally {
|
|
7231
|
-
if (retries <= 0) {
|
|
7232
|
-
finallyFn();
|
|
7233
|
-
}
|
|
7234
|
-
}
|
|
7235
|
-
};
|
|
7236
|
-
|
|
7237
7155
|
const ERC721$2 = 'ERC721';
|
|
7238
|
-
|
|
7239
|
-
confirmationScreen.loading();
|
|
7240
|
-
const transactionAPI = new TransactionsApi(new Configuration({
|
|
7241
|
-
accessToken,
|
|
7242
|
-
basePath: imxPublicApiDomain,
|
|
7243
|
-
}));
|
|
7244
|
-
const starkExTransactionApi = new StarkexTransactionsApi(new Configuration({
|
|
7245
|
-
accessToken,
|
|
7246
|
-
basePath: imxPublicApiDomain,
|
|
7247
|
-
}));
|
|
7248
|
-
const finallyFn = () => {
|
|
7249
|
-
confirmationScreen.closeWindow();
|
|
7250
|
-
};
|
|
7251
|
-
const transactionRes = await retryWithDelay(async () => transactionAPI.getTransactionByID({
|
|
7252
|
-
transactionID: payloadHash,
|
|
7253
|
-
chainType: 'starkex',
|
|
7254
|
-
}), { finallyFn });
|
|
7255
|
-
if (!transactionRes.data.id) {
|
|
7256
|
-
throw new Error("Transaction doesn't exists");
|
|
7257
|
-
}
|
|
7258
|
-
const evaluateStarkexRes = await starkExTransactionApi.evaluateStarkexTransaction({
|
|
7259
|
-
payloadHash,
|
|
7260
|
-
});
|
|
7261
|
-
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
7262
|
-
if (confirmationRequired) {
|
|
7263
|
-
const confirmationResult = await confirmationScreen.startGuardianTransaction(payloadHash);
|
|
7264
|
-
if (!confirmationResult.confirmed) {
|
|
7265
|
-
throw new Error('Transaction rejected by user');
|
|
7266
|
-
}
|
|
7267
|
-
}
|
|
7268
|
-
else {
|
|
7269
|
-
confirmationScreen.closeWindow();
|
|
7270
|
-
}
|
|
7271
|
-
};
|
|
7272
|
-
async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicApiDomain, confirmationScreen, }) {
|
|
7156
|
+
async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
|
|
7273
7157
|
return withPassportError(async () => {
|
|
7274
7158
|
const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
|
|
7275
7159
|
const getSignableTransferRequest = {
|
|
@@ -7284,11 +7168,8 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7284
7168
|
const signableResult = await transfersApi.getSignableTransferV1({
|
|
7285
7169
|
getSignableTransferRequest,
|
|
7286
7170
|
}, { headers });
|
|
7287
|
-
await
|
|
7288
|
-
imxPublicApiDomain,
|
|
7289
|
-
accessToken: user.accessToken,
|
|
7171
|
+
await guardianClient.validate({
|
|
7290
7172
|
payloadHash: signableResult.data.payload_hash,
|
|
7291
|
-
confirmationScreen,
|
|
7292
7173
|
});
|
|
7293
7174
|
const signableResultData = signableResult.data;
|
|
7294
7175
|
const { payload_hash: payloadHash } = signableResultData;
|
|
@@ -7317,7 +7198,7 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7317
7198
|
};
|
|
7318
7199
|
}, PassportErrorType.TRANSFER_ERROR);
|
|
7319
7200
|
}
|
|
7320
|
-
async function batchNftTransfer({ user, starkSigner, request, transfersApi,
|
|
7201
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
|
|
7321
7202
|
return withPassportError(async () => {
|
|
7322
7203
|
const { ethAddress } = user.imx;
|
|
7323
7204
|
const signableRequests = request.map((nftTransfer) => ({
|
|
@@ -7333,17 +7214,18 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7333
7214
|
sender_ether_key: ethAddress,
|
|
7334
7215
|
signable_requests: signableRequests,
|
|
7335
7216
|
};
|
|
7217
|
+
const headers = {
|
|
7218
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7219
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7220
|
+
};
|
|
7336
7221
|
const signableResult = await transfersApi.getSignableTransfer({
|
|
7337
7222
|
getSignableTransferRequestV2,
|
|
7338
|
-
});
|
|
7223
|
+
}, { headers });
|
|
7339
7224
|
const popupWindowSize = { width: 480, height: 784 };
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
}
|
|
7344
|
-
if (!confirmationResult.confirmed) {
|
|
7345
|
-
throw new Error('Transaction rejected by user');
|
|
7346
|
-
}
|
|
7225
|
+
await guardianClient.validate({
|
|
7226
|
+
payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
|
|
7227
|
+
popupWindowSize,
|
|
7228
|
+
});
|
|
7347
7229
|
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
7348
7230
|
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
7349
7231
|
return {
|
|
@@ -7361,10 +7243,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7361
7243
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
7362
7244
|
requests,
|
|
7363
7245
|
};
|
|
7364
|
-
const headers = {
|
|
7365
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7366
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7367
|
-
};
|
|
7368
7246
|
const response = await transfersApi.createTransfer({
|
|
7369
7247
|
createTransferRequestV2: transferSigningParams,
|
|
7370
7248
|
}, { headers });
|
|
@@ -7379,13 +7257,18 @@ class PassportImxProvider {
|
|
|
7379
7257
|
starkSigner;
|
|
7380
7258
|
immutableXClient;
|
|
7381
7259
|
confirmationScreen;
|
|
7382
|
-
|
|
7260
|
+
guardianClient;
|
|
7383
7261
|
constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
|
|
7384
7262
|
this.user = user;
|
|
7385
7263
|
this.starkSigner = starkSigner;
|
|
7386
7264
|
this.immutableXClient = immutableXClient;
|
|
7387
|
-
this.imxPublicApiDomain = imxPublicApiDomain;
|
|
7388
7265
|
this.confirmationScreen = confirmationScreen;
|
|
7266
|
+
this.guardianClient = new GuardianClient({
|
|
7267
|
+
imxPublicApiDomain,
|
|
7268
|
+
accessToken: user.accessToken,
|
|
7269
|
+
confirmationScreen,
|
|
7270
|
+
imxEtherAddress: user.imx.ethAddress,
|
|
7271
|
+
});
|
|
7389
7272
|
}
|
|
7390
7273
|
async transfer(request) {
|
|
7391
7274
|
return transfer$1({
|
|
@@ -7393,8 +7276,7 @@ class PassportImxProvider {
|
|
|
7393
7276
|
user: this.user,
|
|
7394
7277
|
starkSigner: this.starkSigner,
|
|
7395
7278
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7396
|
-
|
|
7397
|
-
imxPublicApiDomain: this.imxPublicApiDomain,
|
|
7279
|
+
guardianClient: this.guardianClient,
|
|
7398
7280
|
});
|
|
7399
7281
|
}
|
|
7400
7282
|
// TODO: Remove once implemented
|
|
@@ -7413,7 +7295,7 @@ class PassportImxProvider {
|
|
|
7413
7295
|
user: this.user,
|
|
7414
7296
|
starkSigner: this.starkSigner,
|
|
7415
7297
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7416
|
-
|
|
7298
|
+
guardianClient: this.guardianClient,
|
|
7417
7299
|
});
|
|
7418
7300
|
}
|
|
7419
7301
|
cancelOrder(request) {
|
|
@@ -7422,7 +7304,7 @@ class PassportImxProvider {
|
|
|
7422
7304
|
user: this.user,
|
|
7423
7305
|
starkSigner: this.starkSigner,
|
|
7424
7306
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7425
|
-
|
|
7307
|
+
guardianClient: this.guardianClient,
|
|
7426
7308
|
});
|
|
7427
7309
|
}
|
|
7428
7310
|
createTrade(request) {
|
|
@@ -7431,7 +7313,7 @@ class PassportImxProvider {
|
|
|
7431
7313
|
user: this.user,
|
|
7432
7314
|
starkSigner: this.starkSigner,
|
|
7433
7315
|
tradesApi: this.immutableXClient.tradesApi,
|
|
7434
|
-
|
|
7316
|
+
guardianClient: this.guardianClient,
|
|
7435
7317
|
});
|
|
7436
7318
|
}
|
|
7437
7319
|
batchNftTransfer(request) {
|
|
@@ -7440,7 +7322,7 @@ class PassportImxProvider {
|
|
|
7440
7322
|
user: this.user,
|
|
7441
7323
|
starkSigner: this.starkSigner,
|
|
7442
7324
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7443
|
-
|
|
7325
|
+
guardianClient: this.guardianClient,
|
|
7444
7326
|
});
|
|
7445
7327
|
}
|
|
7446
7328
|
exchangeTransfer(request) {
|
|
@@ -7623,6 +7505,159 @@ class PassportConfiguration {
|
|
|
7623
7505
|
}
|
|
7624
7506
|
}
|
|
7625
7507
|
|
|
7508
|
+
var ReceiveMessage;
|
|
7509
|
+
(function (ReceiveMessage) {
|
|
7510
|
+
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
7511
|
+
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
7512
|
+
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
7513
|
+
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
7514
|
+
var SendMessage;
|
|
7515
|
+
(function (SendMessage) {
|
|
7516
|
+
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
7517
|
+
})(SendMessage || (SendMessage = {}));
|
|
7518
|
+
var TransactionTypes;
|
|
7519
|
+
(function (TransactionTypes) {
|
|
7520
|
+
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
7521
|
+
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
7522
|
+
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
7523
|
+
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
7524
|
+
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
7525
|
+
})(TransactionTypes || (TransactionTypes = {}));
|
|
7526
|
+
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
7527
|
+
|
|
7528
|
+
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
7529
|
+
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
7530
|
+
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
7531
|
+
const newWindow = window.open(url, title, `
|
|
7532
|
+
scrollbars=yes,
|
|
7533
|
+
width=${width},
|
|
7534
|
+
height=${height},
|
|
7535
|
+
top=${top},
|
|
7536
|
+
left=${left}
|
|
7537
|
+
`);
|
|
7538
|
+
if (!newWindow) {
|
|
7539
|
+
throw new Error('Failed to open confirmation screen');
|
|
7540
|
+
}
|
|
7541
|
+
newWindow.focus();
|
|
7542
|
+
return newWindow;
|
|
7543
|
+
};
|
|
7544
|
+
|
|
7545
|
+
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
7546
|
+
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
7547
|
+
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
7548
|
+
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
7549
|
+
class ConfirmationScreen {
|
|
7550
|
+
config;
|
|
7551
|
+
confirmationWindow;
|
|
7552
|
+
constructor(config) {
|
|
7553
|
+
this.config = config;
|
|
7554
|
+
}
|
|
7555
|
+
postMessage(destinationWindow, accessToken, message) {
|
|
7556
|
+
destinationWindow.postMessage({
|
|
7557
|
+
eventType: PASSPORT_EVENT_TYPE,
|
|
7558
|
+
accessToken,
|
|
7559
|
+
...message,
|
|
7560
|
+
}, this.config.passportDomain);
|
|
7561
|
+
}
|
|
7562
|
+
startTransaction(accessToken, transaction, popupOptions) {
|
|
7563
|
+
return new Promise((resolve, reject) => {
|
|
7564
|
+
const messageHandler = ({ data, origin }) => {
|
|
7565
|
+
if (origin !== this.config.passportDomain
|
|
7566
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7567
|
+
return;
|
|
7568
|
+
}
|
|
7569
|
+
switch (data.messageType) {
|
|
7570
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7571
|
+
// TODO: remove once fixed
|
|
7572
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
7573
|
+
this.postMessage(confirmationWindow, accessToken, {
|
|
7574
|
+
messageType: SendMessage.TRANSACTION_START,
|
|
7575
|
+
messageData: transaction,
|
|
7576
|
+
});
|
|
7577
|
+
break;
|
|
7578
|
+
}
|
|
7579
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7580
|
+
resolve({ confirmed: true });
|
|
7581
|
+
break;
|
|
7582
|
+
}
|
|
7583
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7584
|
+
reject(new Error('Transaction error'));
|
|
7585
|
+
break;
|
|
7586
|
+
}
|
|
7587
|
+
default:
|
|
7588
|
+
reject(new Error('Unsupported message type'));
|
|
7589
|
+
}
|
|
7590
|
+
};
|
|
7591
|
+
window.addEventListener('message', messageHandler);
|
|
7592
|
+
const confirmationWindow = openPopupCenter({
|
|
7593
|
+
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
7594
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7595
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7596
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7597
|
+
});
|
|
7598
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7599
|
+
const timer = setInterval(() => {
|
|
7600
|
+
if (confirmationWindow.closed) {
|
|
7601
|
+
clearInterval(timer);
|
|
7602
|
+
window.removeEventListener('message', messageHandler);
|
|
7603
|
+
resolve({ confirmed: false });
|
|
7604
|
+
}
|
|
7605
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7606
|
+
});
|
|
7607
|
+
}
|
|
7608
|
+
startGuardianTransaction(transactionId, imxEtherAddress) {
|
|
7609
|
+
return new Promise((resolve, reject) => {
|
|
7610
|
+
const messageHandler = ({ data, origin }) => {
|
|
7611
|
+
if (origin !== this.config.passportDomain
|
|
7612
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7613
|
+
return;
|
|
7614
|
+
}
|
|
7615
|
+
switch (data.messageType) {
|
|
7616
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7617
|
+
break;
|
|
7618
|
+
}
|
|
7619
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7620
|
+
resolve({ confirmed: true });
|
|
7621
|
+
break;
|
|
7622
|
+
}
|
|
7623
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7624
|
+
reject(new Error('Transaction error'));
|
|
7625
|
+
break;
|
|
7626
|
+
}
|
|
7627
|
+
default:
|
|
7628
|
+
reject(new Error('Unsupported message type'));
|
|
7629
|
+
}
|
|
7630
|
+
};
|
|
7631
|
+
window.addEventListener('message', messageHandler);
|
|
7632
|
+
if (!this.confirmationWindow) {
|
|
7633
|
+
resolve({ confirmed: false });
|
|
7634
|
+
return;
|
|
7635
|
+
}
|
|
7636
|
+
// eslint-disable-next-line max-len
|
|
7637
|
+
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
|
|
7638
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7639
|
+
const timer = setInterval(() => {
|
|
7640
|
+
if (this.confirmationWindow?.closed) {
|
|
7641
|
+
clearInterval(timer);
|
|
7642
|
+
window.removeEventListener('message', messageHandler);
|
|
7643
|
+
resolve({ confirmed: false });
|
|
7644
|
+
}
|
|
7645
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7646
|
+
});
|
|
7647
|
+
}
|
|
7648
|
+
loading(popupOptions) {
|
|
7649
|
+
this.confirmationWindow = openPopupCenter({
|
|
7650
|
+
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7651
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7652
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7653
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7654
|
+
});
|
|
7655
|
+
}
|
|
7656
|
+
closeWindow() {
|
|
7657
|
+
this.confirmationWindow?.close();
|
|
7658
|
+
}
|
|
7659
|
+
}
|
|
7660
|
+
|
|
7626
7661
|
class Passport {
|
|
7627
7662
|
authManager;
|
|
7628
7663
|
config;
|