@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.cjs
CHANGED
|
@@ -168,7 +168,7 @@ const setSearchParams$1 = function (url, ...objects) {
|
|
|
168
168
|
*
|
|
169
169
|
* @export
|
|
170
170
|
*/
|
|
171
|
-
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
171
|
+
const serializeDataIfNeeded$1 = function (value, requestOptions, configuration) {
|
|
172
172
|
const nonString = typeof value !== 'string';
|
|
173
173
|
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
174
174
|
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
@@ -1197,7 +1197,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
|
|
|
1197
1197
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1198
1198
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1199
1199
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1200
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1200
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1201
1201
|
return {
|
|
1202
1202
|
url: toPathString$1(localVarUrlObj),
|
|
1203
1203
|
options: localVarRequestOptions,
|
|
@@ -1488,7 +1488,7 @@ const PassportApiAxiosParamCreator = function (configuration) {
|
|
|
1488
1488
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1489
1489
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1490
1490
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1491
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1491
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1492
1492
|
return {
|
|
1493
1493
|
url: toPathString$1(localVarUrlObj),
|
|
1494
1494
|
options: localVarRequestOptions,
|
|
@@ -2258,10 +2258,10 @@ const createAPIConfiguration = ({ basePath, headers: baseHeaders, }) => {
|
|
|
2258
2258
|
return new index.Configuration(configParams);
|
|
2259
2259
|
};
|
|
2260
2260
|
const production$1 = () => createAPIConfiguration({
|
|
2261
|
-
basePath: 'https://indexer-mr.
|
|
2261
|
+
basePath: 'https://indexer-mr.imtbl.com',
|
|
2262
2262
|
});
|
|
2263
2263
|
const sandbox$1 = () => createAPIConfiguration({
|
|
2264
|
-
basePath: 'https://indexer-mr.
|
|
2264
|
+
basePath: 'https://indexer-mr.sandbox.imtbl.com',
|
|
2265
2265
|
});
|
|
2266
2266
|
class BlockchainDataConfiguration {
|
|
2267
2267
|
apiConfig;
|
|
@@ -3009,78 +3009,6 @@ class ImmutableXClient {
|
|
|
3009
3009
|
}
|
|
3010
3010
|
}
|
|
3011
3011
|
|
|
3012
|
-
// used to sign message with L1 keys. Used for registration
|
|
3013
|
-
function serializeEthSignature(sig) {
|
|
3014
|
-
// This is because golang appends a recovery param
|
|
3015
|
-
// https://github.com/ethers-io/ethers.js/issues/823
|
|
3016
|
-
return encUtils__namespace.addHexPrefix(encUtils__namespace.padLeft(sig.r.toString(16), 64)
|
|
3017
|
-
+ encUtils__namespace.padLeft(sig.s.toString(16), 64)
|
|
3018
|
-
+ encUtils__namespace.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
3019
|
-
}
|
|
3020
|
-
function importRecoveryParam(v) {
|
|
3021
|
-
const isValidBigNumber = new BN(v, 16).cmp(new BN(27)) !== -1
|
|
3022
|
-
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
3023
|
-
: new BN(v, 16).toNumber();
|
|
3024
|
-
return v.trim()
|
|
3025
|
-
? isValidBigNumber
|
|
3026
|
-
: undefined;
|
|
3027
|
-
}
|
|
3028
|
-
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
3029
|
-
function deserializeSignature(sig, size = 64) {
|
|
3030
|
-
const removedHexPrefixSig = encUtils__namespace.removeHexPrefix(sig);
|
|
3031
|
-
return {
|
|
3032
|
-
r: new BN(removedHexPrefixSig.substring(0, size), 'hex'),
|
|
3033
|
-
s: new BN(removedHexPrefixSig.substring(size, size * 2), 'hex'),
|
|
3034
|
-
recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
|
|
3035
|
-
};
|
|
3036
|
-
}
|
|
3037
|
-
async function signRaw(payload, signer) {
|
|
3038
|
-
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
3039
|
-
return serializeEthSignature(signature);
|
|
3040
|
-
}
|
|
3041
|
-
async function signMessage(message, signer) {
|
|
3042
|
-
const ethAddress = await signer.getAddress();
|
|
3043
|
-
const ethSignature = await signRaw(message, signer);
|
|
3044
|
-
return {
|
|
3045
|
-
message,
|
|
3046
|
-
ethAddress,
|
|
3047
|
-
ethSignature,
|
|
3048
|
-
};
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
/**
|
|
3052
|
-
* Helper method to convert token type to a SignableToken type
|
|
3053
|
-
* @param token - the token type to convert to a SignableToken type
|
|
3054
|
-
* @returns the converted SignableToken
|
|
3055
|
-
*/
|
|
3056
|
-
function convertToSignableToken(token) {
|
|
3057
|
-
switch (token.type) {
|
|
3058
|
-
case 'ERC721':
|
|
3059
|
-
return {
|
|
3060
|
-
type: 'ERC721',
|
|
3061
|
-
data: {
|
|
3062
|
-
token_id: token.tokenId,
|
|
3063
|
-
token_address: token.tokenAddress,
|
|
3064
|
-
},
|
|
3065
|
-
};
|
|
3066
|
-
case 'ERC20':
|
|
3067
|
-
return {
|
|
3068
|
-
type: 'ERC20',
|
|
3069
|
-
data: {
|
|
3070
|
-
token_address: token.tokenAddress,
|
|
3071
|
-
},
|
|
3072
|
-
};
|
|
3073
|
-
case 'ETH':
|
|
3074
|
-
default:
|
|
3075
|
-
return {
|
|
3076
|
-
type: 'ETH',
|
|
3077
|
-
data: {
|
|
3078
|
-
decimals: 18,
|
|
3079
|
-
},
|
|
3080
|
-
};
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
3012
|
function bind(fn, thisArg) {
|
|
3085
3013
|
return function wrap() {
|
|
3086
3014
|
return fn.apply(thisArg, arguments);
|
|
@@ -6292,7 +6220,7 @@ var globalAxios = axios;
|
|
|
6292
6220
|
/* tslint:disable */
|
|
6293
6221
|
/* eslint-disable */
|
|
6294
6222
|
/**
|
|
6295
|
-
*
|
|
6223
|
+
* Guardian
|
|
6296
6224
|
* Guardian API
|
|
6297
6225
|
*
|
|
6298
6226
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6302,7 +6230,7 @@ var globalAxios = axios;
|
|
|
6302
6230
|
* https://openapi-generator.tech
|
|
6303
6231
|
* Do not edit the class manually.
|
|
6304
6232
|
*/
|
|
6305
|
-
const BASE_PATH = "
|
|
6233
|
+
const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
6306
6234
|
/**
|
|
6307
6235
|
*
|
|
6308
6236
|
* @export
|
|
@@ -6339,7 +6267,7 @@ class RequiredError extends Error {
|
|
|
6339
6267
|
/* tslint:disable */
|
|
6340
6268
|
/* eslint-disable */
|
|
6341
6269
|
/**
|
|
6342
|
-
*
|
|
6270
|
+
* Guardian
|
|
6343
6271
|
* Guardian API
|
|
6344
6272
|
*
|
|
6345
6273
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6405,6 +6333,19 @@ const setSearchParams = function (url, ...objects) {
|
|
|
6405
6333
|
setFlattenedQueryParams(searchParams, objects);
|
|
6406
6334
|
url.search = searchParams.toString();
|
|
6407
6335
|
};
|
|
6336
|
+
/**
|
|
6337
|
+
*
|
|
6338
|
+
* @export
|
|
6339
|
+
*/
|
|
6340
|
+
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
6341
|
+
const nonString = typeof value !== 'string';
|
|
6342
|
+
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
6343
|
+
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
6344
|
+
: nonString;
|
|
6345
|
+
return needsSerialization
|
|
6346
|
+
? JSON.stringify(value !== undefined ? value : {})
|
|
6347
|
+
: (value || "");
|
|
6348
|
+
};
|
|
6408
6349
|
/**
|
|
6409
6350
|
*
|
|
6410
6351
|
* @export
|
|
@@ -6426,7 +6367,7 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6426
6367
|
/* tslint:disable */
|
|
6427
6368
|
/* eslint-disable */
|
|
6428
6369
|
/**
|
|
6429
|
-
*
|
|
6370
|
+
* Guardian
|
|
6430
6371
|
* Guardian API
|
|
6431
6372
|
*
|
|
6432
6373
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6437,22 +6378,25 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6437
6378
|
* Do not edit the class manually.
|
|
6438
6379
|
*/
|
|
6439
6380
|
/**
|
|
6440
|
-
*
|
|
6381
|
+
* TransactionsApi - axios parameter creator
|
|
6441
6382
|
* @export
|
|
6442
6383
|
*/
|
|
6443
|
-
const
|
|
6384
|
+
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6444
6385
|
return {
|
|
6445
6386
|
/**
|
|
6446
|
-
*
|
|
6447
|
-
* @summary
|
|
6387
|
+
* Approve a pending transaction
|
|
6388
|
+
* @summary Approve a pending transaction given chain
|
|
6448
6389
|
* @param {string} payloadHash Hash for the payload
|
|
6390
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transactio
|
|
6449
6391
|
* @param {*} [options] Override http request option.
|
|
6450
6392
|
* @throws {RequiredError}
|
|
6451
6393
|
*/
|
|
6452
|
-
|
|
6394
|
+
approvePendingTransaction: async (payloadHash, transactionApprovalRequest, options = {}) => {
|
|
6453
6395
|
// verify required parameter 'payloadHash' is not null or undefined
|
|
6454
|
-
assertParamExists('
|
|
6455
|
-
|
|
6396
|
+
assertParamExists('approvePendingTransaction', 'payloadHash', payloadHash);
|
|
6397
|
+
// verify required parameter 'transactionApprovalRequest' is not null or undefined
|
|
6398
|
+
assertParamExists('approvePendingTransaction', 'transactionApprovalRequest', transactionApprovalRequest);
|
|
6399
|
+
const localVarPath = `/guardian/v1/transactions/{payloadHash}/approve`
|
|
6456
6400
|
.replace(`{${"payloadHash"}}`, encodeURIComponent(String(payloadHash)));
|
|
6457
6401
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6458
6402
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -6466,80 +6410,58 @@ const StarkexTransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6466
6410
|
// authentication BearerAuth required
|
|
6467
6411
|
// http bearer authentication required
|
|
6468
6412
|
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6413
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
6469
6414
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6470
6415
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6471
6416
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6417
|
+
localVarRequestOptions.data = serializeDataIfNeeded(transactionApprovalRequest, localVarRequestOptions, configuration);
|
|
6472
6418
|
return {
|
|
6473
6419
|
url: toPathString(localVarUrlObj),
|
|
6474
6420
|
options: localVarRequestOptions,
|
|
6475
6421
|
};
|
|
6476
6422
|
},
|
|
6477
|
-
};
|
|
6478
|
-
};
|
|
6479
|
-
/**
|
|
6480
|
-
* StarkexTransactionsApi - functional programming interface
|
|
6481
|
-
* @export
|
|
6482
|
-
*/
|
|
6483
|
-
const StarkexTransactionsApiFp = function (configuration) {
|
|
6484
|
-
const localVarAxiosParamCreator = StarkexTransactionsApiAxiosParamCreator(configuration);
|
|
6485
|
-
return {
|
|
6486
6423
|
/**
|
|
6487
|
-
* Check if
|
|
6488
|
-
* @summary Evaluate
|
|
6489
|
-
* @param {string} payloadHash
|
|
6424
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6425
|
+
* @summary Evaluate a transaction
|
|
6426
|
+
* @param {string} id Transaction identifier: payloadHash on StarkEx or EVM ID
|
|
6427
|
+
* @param {TransactionEvaluationRequest} transactionEvaluationRequest Specifies the kind of transaction
|
|
6490
6428
|
* @param {*} [options] Override http request option.
|
|
6491
6429
|
* @throws {RequiredError}
|
|
6492
6430
|
*/
|
|
6493
|
-
async
|
|
6494
|
-
|
|
6495
|
-
|
|
6431
|
+
evaluateTransaction: async (id, transactionEvaluationRequest, options = {}) => {
|
|
6432
|
+
// verify required parameter 'id' is not null or undefined
|
|
6433
|
+
assertParamExists('evaluateTransaction', 'id', id);
|
|
6434
|
+
// verify required parameter 'transactionEvaluationRequest' is not null or undefined
|
|
6435
|
+
assertParamExists('evaluateTransaction', 'transactionEvaluationRequest', transactionEvaluationRequest);
|
|
6436
|
+
const localVarPath = `/guardian/v1/transactions/{id}/evaluate`
|
|
6437
|
+
.replace(`{${"id"}}`, encodeURIComponent(String(id)));
|
|
6438
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6439
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
6440
|
+
let baseOptions;
|
|
6441
|
+
if (configuration) {
|
|
6442
|
+
baseOptions = configuration.baseOptions;
|
|
6443
|
+
}
|
|
6444
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
6445
|
+
const localVarHeaderParameter = {};
|
|
6446
|
+
const localVarQueryParameter = {};
|
|
6447
|
+
// authentication BearerAuth required
|
|
6448
|
+
// http bearer authentication required
|
|
6449
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6450
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
6451
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6452
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6453
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6454
|
+
localVarRequestOptions.data = serializeDataIfNeeded(transactionEvaluationRequest, localVarRequestOptions, configuration);
|
|
6455
|
+
return {
|
|
6456
|
+
url: toPathString(localVarUrlObj),
|
|
6457
|
+
options: localVarRequestOptions,
|
|
6458
|
+
};
|
|
6496
6459
|
},
|
|
6497
|
-
};
|
|
6498
|
-
};
|
|
6499
|
-
/**
|
|
6500
|
-
* StarkexTransactionsApi - object-oriented interface
|
|
6501
|
-
* @export
|
|
6502
|
-
* @class StarkexTransactionsApi
|
|
6503
|
-
* @extends {BaseAPI}
|
|
6504
|
-
*/
|
|
6505
|
-
class StarkexTransactionsApi extends BaseAPI {
|
|
6506
|
-
/**
|
|
6507
|
-
* Check if it is a valid transaction by payload hash
|
|
6508
|
-
* @summary Evaluate if it is an valid transaction
|
|
6509
|
-
* @param {StarkexTransactionsApiEvaluateStarkexTransactionRequest} requestParameters Request parameters.
|
|
6510
|
-
* @param {*} [options] Override http request option.
|
|
6511
|
-
* @throws {RequiredError}
|
|
6512
|
-
* @memberof StarkexTransactionsApi
|
|
6513
|
-
*/
|
|
6514
|
-
evaluateStarkexTransaction(requestParameters, options) {
|
|
6515
|
-
return StarkexTransactionsApiFp(this.configuration).evaluateStarkexTransaction(requestParameters.payloadHash, options).then((request) => request(this.axios, this.basePath));
|
|
6516
|
-
}
|
|
6517
|
-
}
|
|
6518
|
-
|
|
6519
|
-
/* tslint:disable */
|
|
6520
|
-
/* eslint-disable */
|
|
6521
|
-
/**
|
|
6522
|
-
* Swagger Guardian
|
|
6523
|
-
* Guardian API
|
|
6524
|
-
*
|
|
6525
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6526
|
-
* Contact: support@immutable.com
|
|
6527
|
-
*
|
|
6528
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
6529
|
-
* https://openapi-generator.tech
|
|
6530
|
-
* Do not edit the class manually.
|
|
6531
|
-
*/
|
|
6532
|
-
/**
|
|
6533
|
-
* TransactionsApi - axios parameter creator
|
|
6534
|
-
* @export
|
|
6535
|
-
*/
|
|
6536
|
-
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6537
|
-
return {
|
|
6538
6460
|
/**
|
|
6539
6461
|
* Get a transaction by payload hash
|
|
6540
6462
|
* @summary Info for a specific transaction
|
|
6541
6463
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6542
|
-
* @param {
|
|
6464
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6543
6465
|
* @param {number} [chainID] ID of evm chain
|
|
6544
6466
|
* @param {*} [options] Override http request option.
|
|
6545
6467
|
* @throws {RequiredError}
|
|
@@ -6586,11 +6508,35 @@ const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6586
6508
|
const TransactionsApiFp = function (configuration) {
|
|
6587
6509
|
const localVarAxiosParamCreator = TransactionsApiAxiosParamCreator(configuration);
|
|
6588
6510
|
return {
|
|
6511
|
+
/**
|
|
6512
|
+
* Approve a pending transaction
|
|
6513
|
+
* @summary Approve a pending transaction given chain
|
|
6514
|
+
* @param {string} payloadHash Hash for the payload
|
|
6515
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transactio
|
|
6516
|
+
* @param {*} [options] Override http request option.
|
|
6517
|
+
* @throws {RequiredError}
|
|
6518
|
+
*/
|
|
6519
|
+
async approvePendingTransaction(payloadHash, transactionApprovalRequest, options) {
|
|
6520
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.approvePendingTransaction(payloadHash, transactionApprovalRequest, options);
|
|
6521
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
6522
|
+
},
|
|
6523
|
+
/**
|
|
6524
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6525
|
+
* @summary Evaluate a transaction
|
|
6526
|
+
* @param {string} id Transaction identifier: payloadHash on StarkEx or EVM ID
|
|
6527
|
+
* @param {TransactionEvaluationRequest} transactionEvaluationRequest Specifies the kind of transaction
|
|
6528
|
+
* @param {*} [options] Override http request option.
|
|
6529
|
+
* @throws {RequiredError}
|
|
6530
|
+
*/
|
|
6531
|
+
async evaluateTransaction(id, transactionEvaluationRequest, options) {
|
|
6532
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.evaluateTransaction(id, transactionEvaluationRequest, options);
|
|
6533
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
6534
|
+
},
|
|
6589
6535
|
/**
|
|
6590
6536
|
* Get a transaction by payload hash
|
|
6591
6537
|
* @summary Info for a specific transaction
|
|
6592
6538
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6593
|
-
* @param {
|
|
6539
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6594
6540
|
* @param {number} [chainID] ID of evm chain
|
|
6595
6541
|
* @param {*} [options] Override http request option.
|
|
6596
6542
|
* @throws {RequiredError}
|
|
@@ -6608,6 +6554,28 @@ const TransactionsApiFp = function (configuration) {
|
|
|
6608
6554
|
* @extends {BaseAPI}
|
|
6609
6555
|
*/
|
|
6610
6556
|
class TransactionsApi extends BaseAPI {
|
|
6557
|
+
/**
|
|
6558
|
+
* Approve a pending transaction
|
|
6559
|
+
* @summary Approve a pending transaction given chain
|
|
6560
|
+
* @param {TransactionsApiApprovePendingTransactionRequest} requestParameters Request parameters.
|
|
6561
|
+
* @param {*} [options] Override http request option.
|
|
6562
|
+
* @throws {RequiredError}
|
|
6563
|
+
* @memberof TransactionsApi
|
|
6564
|
+
*/
|
|
6565
|
+
approvePendingTransaction(requestParameters, options) {
|
|
6566
|
+
return TransactionsApiFp(this.configuration).approvePendingTransaction(requestParameters.payloadHash, requestParameters.transactionApprovalRequest, options).then((request) => request(this.axios, this.basePath));
|
|
6567
|
+
}
|
|
6568
|
+
/**
|
|
6569
|
+
* Check if the transaction is valid by transaction ID for both StarkEx and EVM
|
|
6570
|
+
* @summary Evaluate a transaction
|
|
6571
|
+
* @param {TransactionsApiEvaluateTransactionRequest} requestParameters Request parameters.
|
|
6572
|
+
* @param {*} [options] Override http request option.
|
|
6573
|
+
* @throws {RequiredError}
|
|
6574
|
+
* @memberof TransactionsApi
|
|
6575
|
+
*/
|
|
6576
|
+
evaluateTransaction(requestParameters, options) {
|
|
6577
|
+
return TransactionsApiFp(this.configuration).evaluateTransaction(requestParameters.id, requestParameters.transactionEvaluationRequest, options).then((request) => request(this.axios, this.basePath));
|
|
6578
|
+
}
|
|
6611
6579
|
/**
|
|
6612
6580
|
* Get a transaction by payload hash
|
|
6613
6581
|
* @summary Info for a specific transaction
|
|
@@ -6624,7 +6592,7 @@ class TransactionsApi extends BaseAPI {
|
|
|
6624
6592
|
/* tslint:disable */
|
|
6625
6593
|
/* eslint-disable */
|
|
6626
6594
|
/**
|
|
6627
|
-
*
|
|
6595
|
+
* Guardian
|
|
6628
6596
|
* Guardian API
|
|
6629
6597
|
*
|
|
6630
6598
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6709,6 +6677,78 @@ class Configuration {
|
|
|
6709
6677
|
}
|
|
6710
6678
|
}
|
|
6711
6679
|
|
|
6680
|
+
// used to sign message with L1 keys. Used for registration
|
|
6681
|
+
function serializeEthSignature(sig) {
|
|
6682
|
+
// This is because golang appends a recovery param
|
|
6683
|
+
// https://github.com/ethers-io/ethers.js/issues/823
|
|
6684
|
+
return encUtils__namespace.addHexPrefix(encUtils__namespace.padLeft(sig.r.toString(16), 64)
|
|
6685
|
+
+ encUtils__namespace.padLeft(sig.s.toString(16), 64)
|
|
6686
|
+
+ encUtils__namespace.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
6687
|
+
}
|
|
6688
|
+
function importRecoveryParam(v) {
|
|
6689
|
+
const isValidBigNumber = new BN(v, 16).cmp(new BN(27)) !== -1
|
|
6690
|
+
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
6691
|
+
: new BN(v, 16).toNumber();
|
|
6692
|
+
return v.trim()
|
|
6693
|
+
? isValidBigNumber
|
|
6694
|
+
: undefined;
|
|
6695
|
+
}
|
|
6696
|
+
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
6697
|
+
function deserializeSignature(sig, size = 64) {
|
|
6698
|
+
const removedHexPrefixSig = encUtils__namespace.removeHexPrefix(sig);
|
|
6699
|
+
return {
|
|
6700
|
+
r: new BN(removedHexPrefixSig.substring(0, size), 'hex'),
|
|
6701
|
+
s: new BN(removedHexPrefixSig.substring(size, size * 2), 'hex'),
|
|
6702
|
+
recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
|
|
6703
|
+
};
|
|
6704
|
+
}
|
|
6705
|
+
async function signRaw(payload, signer) {
|
|
6706
|
+
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
6707
|
+
return serializeEthSignature(signature);
|
|
6708
|
+
}
|
|
6709
|
+
async function signMessage(message, signer) {
|
|
6710
|
+
const ethAddress = await signer.getAddress();
|
|
6711
|
+
const ethSignature = await signRaw(message, signer);
|
|
6712
|
+
return {
|
|
6713
|
+
message,
|
|
6714
|
+
ethAddress,
|
|
6715
|
+
ethSignature,
|
|
6716
|
+
};
|
|
6717
|
+
}
|
|
6718
|
+
|
|
6719
|
+
/**
|
|
6720
|
+
* Helper method to convert token type to a SignableToken type
|
|
6721
|
+
* @param token - the token type to convert to a SignableToken type
|
|
6722
|
+
* @returns the converted SignableToken
|
|
6723
|
+
*/
|
|
6724
|
+
function convertToSignableToken(token) {
|
|
6725
|
+
switch (token.type) {
|
|
6726
|
+
case 'ERC721':
|
|
6727
|
+
return {
|
|
6728
|
+
type: 'ERC721',
|
|
6729
|
+
data: {
|
|
6730
|
+
token_id: token.tokenId,
|
|
6731
|
+
token_address: token.tokenAddress,
|
|
6732
|
+
},
|
|
6733
|
+
};
|
|
6734
|
+
case 'ERC20':
|
|
6735
|
+
return {
|
|
6736
|
+
type: 'ERC20',
|
|
6737
|
+
data: {
|
|
6738
|
+
token_address: token.tokenAddress,
|
|
6739
|
+
},
|
|
6740
|
+
};
|
|
6741
|
+
case 'ETH':
|
|
6742
|
+
default:
|
|
6743
|
+
return {
|
|
6744
|
+
type: 'ETH',
|
|
6745
|
+
data: {
|
|
6746
|
+
decimals: 18,
|
|
6747
|
+
},
|
|
6748
|
+
};
|
|
6749
|
+
}
|
|
6750
|
+
}
|
|
6751
|
+
|
|
6712
6752
|
var PassportErrorType;
|
|
6713
6753
|
(function (PassportErrorType) {
|
|
6714
6754
|
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
@@ -6867,17 +6907,84 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
|
6867
6907
|
return coreSdk.createStarkSigner(privateKey);
|
|
6868
6908
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
6869
6909
|
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6910
|
+
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
6911
|
+
const MAX_RETRIES = 3;
|
|
6912
|
+
const wait = (ms) => new Promise((resolve) => {
|
|
6913
|
+
setTimeout(() => resolve(), ms);
|
|
6914
|
+
});
|
|
6915
|
+
const retryWithDelay = async (fn, options) => {
|
|
6916
|
+
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
|
|
6917
|
+
try {
|
|
6918
|
+
return await fn();
|
|
6919
|
+
}
|
|
6920
|
+
catch (err) {
|
|
6921
|
+
if (retries <= 0) {
|
|
6922
|
+
return Promise.reject(finalErr);
|
|
6923
|
+
}
|
|
6924
|
+
await wait(interval);
|
|
6925
|
+
return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
|
|
6926
|
+
}
|
|
6927
|
+
finally {
|
|
6928
|
+
if (retries <= 0) {
|
|
6929
|
+
finallyFn();
|
|
6930
|
+
}
|
|
6931
|
+
}
|
|
6932
|
+
};
|
|
6933
|
+
|
|
6934
|
+
class GuardianClient {
|
|
6935
|
+
transactionAPI;
|
|
6936
|
+
confirmationScreen;
|
|
6937
|
+
imxEtherAddress;
|
|
6938
|
+
constructor({ imxPublicApiDomain, accessToken, confirmationScreen, imxEtherAddress, }) {
|
|
6939
|
+
this.confirmationScreen = confirmationScreen;
|
|
6940
|
+
this.transactionAPI = new TransactionsApi(new Configuration({
|
|
6941
|
+
accessToken,
|
|
6942
|
+
basePath: imxPublicApiDomain,
|
|
6943
|
+
}));
|
|
6944
|
+
this.imxEtherAddress = imxEtherAddress;
|
|
6945
|
+
}
|
|
6946
|
+
async validate({ popupWindowSize, payloadHash }) {
|
|
6947
|
+
this.confirmationScreen.loading(popupWindowSize);
|
|
6948
|
+
const finallyFn = () => {
|
|
6949
|
+
this.confirmationScreen.closeWindow();
|
|
6950
|
+
};
|
|
6951
|
+
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
6952
|
+
transactionID: payloadHash,
|
|
6953
|
+
chainType: 'starkex',
|
|
6954
|
+
}), { finallyFn });
|
|
6955
|
+
if (!transactionRes.data.id) {
|
|
6956
|
+
throw new Error("Transaction doesn't exists");
|
|
6957
|
+
}
|
|
6958
|
+
const evaluateStarkexRes = await this.transactionAPI.evaluateTransaction({
|
|
6959
|
+
id: payloadHash,
|
|
6960
|
+
transactionEvaluationRequest: {
|
|
6961
|
+
chainType: 'starkex',
|
|
6962
|
+
},
|
|
6963
|
+
});
|
|
6964
|
+
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
6965
|
+
if (confirmationRequired) {
|
|
6966
|
+
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
|
|
6967
|
+
if (!confirmationResult.confirmed) {
|
|
6968
|
+
throw new Error('Transaction rejected by user');
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6971
|
+
else {
|
|
6972
|
+
this.confirmationScreen.closeWindow();
|
|
6973
|
+
}
|
|
6974
|
+
}
|
|
6975
|
+
}
|
|
6976
|
+
|
|
6977
|
+
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
6978
|
+
return withPassportError(async () => {
|
|
6979
|
+
const { ethAddress } = user.imx;
|
|
6980
|
+
const transferAmount = request.amount;
|
|
6981
|
+
const signableResult = await exchangesApi.getExchangeSignableTransfer({
|
|
6982
|
+
id: request.transactionID,
|
|
6983
|
+
getSignableTransferRequest: {
|
|
6984
|
+
sender: ethAddress,
|
|
6985
|
+
token: convertToSignableToken(request),
|
|
6986
|
+
amount: transferAmount,
|
|
6987
|
+
receiver: request.receiver,
|
|
6881
6988
|
},
|
|
6882
6989
|
});
|
|
6883
6990
|
const starkAddress = await starkSigner.getAddress();
|
|
@@ -6911,165 +7018,16 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
|
|
|
6911
7018
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
6912
7019
|
}
|
|
6913
7020
|
|
|
6914
|
-
var ReceiveMessage;
|
|
6915
|
-
(function (ReceiveMessage) {
|
|
6916
|
-
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
6917
|
-
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
6918
|
-
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
6919
|
-
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
6920
|
-
var SendMessage;
|
|
6921
|
-
(function (SendMessage) {
|
|
6922
|
-
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
6923
|
-
})(SendMessage || (SendMessage = {}));
|
|
6924
|
-
var TransactionTypes;
|
|
6925
|
-
(function (TransactionTypes) {
|
|
6926
|
-
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
6927
|
-
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
6928
|
-
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
6929
|
-
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
6930
|
-
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
6931
|
-
})(TransactionTypes || (TransactionTypes = {}));
|
|
6932
|
-
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
6933
|
-
|
|
6934
|
-
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
6935
|
-
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
6936
|
-
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
6937
|
-
const newWindow = window.open(url, title, `
|
|
6938
|
-
scrollbars=yes,
|
|
6939
|
-
width=${width},
|
|
6940
|
-
height=${height},
|
|
6941
|
-
top=${top},
|
|
6942
|
-
left=${left}
|
|
6943
|
-
`);
|
|
6944
|
-
if (!newWindow) {
|
|
6945
|
-
throw new Error('Failed to open confirmation screen');
|
|
6946
|
-
}
|
|
6947
|
-
newWindow.focus();
|
|
6948
|
-
return newWindow;
|
|
6949
|
-
};
|
|
6950
|
-
|
|
6951
|
-
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
6952
|
-
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
6953
|
-
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
6954
|
-
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
6955
|
-
class ConfirmationScreen {
|
|
6956
|
-
config;
|
|
6957
|
-
confirmationWindow;
|
|
6958
|
-
constructor(config) {
|
|
6959
|
-
this.config = config;
|
|
6960
|
-
}
|
|
6961
|
-
postMessage(destinationWindow, accessToken, message) {
|
|
6962
|
-
destinationWindow.postMessage({
|
|
6963
|
-
eventType: PASSPORT_EVENT_TYPE,
|
|
6964
|
-
accessToken,
|
|
6965
|
-
...message,
|
|
6966
|
-
}, this.config.passportDomain);
|
|
6967
|
-
}
|
|
6968
|
-
startTransaction(accessToken, transaction, popupOptions) {
|
|
6969
|
-
return new Promise((resolve, reject) => {
|
|
6970
|
-
const messageHandler = ({ data, origin }) => {
|
|
6971
|
-
if (origin !== this.config.passportDomain
|
|
6972
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
6973
|
-
return;
|
|
6974
|
-
}
|
|
6975
|
-
switch (data.messageType) {
|
|
6976
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
6977
|
-
// TODO: remove once fixed
|
|
6978
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
6979
|
-
this.postMessage(confirmationWindow, accessToken, {
|
|
6980
|
-
messageType: SendMessage.TRANSACTION_START,
|
|
6981
|
-
messageData: transaction,
|
|
6982
|
-
});
|
|
6983
|
-
break;
|
|
6984
|
-
}
|
|
6985
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
6986
|
-
resolve({ confirmed: true });
|
|
6987
|
-
break;
|
|
6988
|
-
}
|
|
6989
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
6990
|
-
reject(new Error('Transaction error'));
|
|
6991
|
-
break;
|
|
6992
|
-
}
|
|
6993
|
-
default:
|
|
6994
|
-
reject(new Error('Unsupported message type'));
|
|
6995
|
-
}
|
|
6996
|
-
};
|
|
6997
|
-
window.addEventListener('message', messageHandler);
|
|
6998
|
-
const confirmationWindow = openPopupCenter({
|
|
6999
|
-
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
7000
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
7001
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7002
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7003
|
-
});
|
|
7004
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7005
|
-
const timer = setInterval(() => {
|
|
7006
|
-
if (confirmationWindow.closed) {
|
|
7007
|
-
clearInterval(timer);
|
|
7008
|
-
window.removeEventListener('message', messageHandler);
|
|
7009
|
-
resolve({ confirmed: false });
|
|
7010
|
-
}
|
|
7011
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7012
|
-
});
|
|
7013
|
-
}
|
|
7014
|
-
startGuardianTransaction(transactionId) {
|
|
7015
|
-
return new Promise((resolve, reject) => {
|
|
7016
|
-
const messageHandler = ({ data, origin }) => {
|
|
7017
|
-
if (origin !== this.config.passportDomain
|
|
7018
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7019
|
-
return;
|
|
7020
|
-
}
|
|
7021
|
-
switch (data.messageType) {
|
|
7022
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7023
|
-
break;
|
|
7024
|
-
}
|
|
7025
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7026
|
-
resolve({ confirmed: true });
|
|
7027
|
-
break;
|
|
7028
|
-
}
|
|
7029
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7030
|
-
reject(new Error('Transaction error'));
|
|
7031
|
-
break;
|
|
7032
|
-
}
|
|
7033
|
-
default:
|
|
7034
|
-
reject(new Error('Unsupported message type'));
|
|
7035
|
-
}
|
|
7036
|
-
};
|
|
7037
|
-
window.addEventListener('message', messageHandler);
|
|
7038
|
-
if (!this.confirmationWindow) {
|
|
7039
|
-
resolve({ confirmed: false });
|
|
7040
|
-
return;
|
|
7041
|
-
}
|
|
7042
|
-
// eslint-disable-next-line max-len
|
|
7043
|
-
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&chainType=starkex`;
|
|
7044
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7045
|
-
const timer = setInterval(() => {
|
|
7046
|
-
if (this.confirmationWindow?.closed) {
|
|
7047
|
-
clearInterval(timer);
|
|
7048
|
-
window.removeEventListener('message', messageHandler);
|
|
7049
|
-
resolve({ confirmed: false });
|
|
7050
|
-
}
|
|
7051
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7052
|
-
});
|
|
7053
|
-
}
|
|
7054
|
-
loading(popupOptions) {
|
|
7055
|
-
this.confirmationWindow = openPopupCenter({
|
|
7056
|
-
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7057
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
7058
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7059
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7060
|
-
});
|
|
7061
|
-
}
|
|
7062
|
-
closeWindow() {
|
|
7063
|
-
this.confirmationWindow?.close();
|
|
7064
|
-
}
|
|
7065
|
-
}
|
|
7066
|
-
|
|
7067
7021
|
const ERC721$1 = 'ERC721';
|
|
7068
|
-
async function createOrder$1({ starkSigner, user, request, ordersApi,
|
|
7022
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
|
|
7069
7023
|
return withPassportError(async () => {
|
|
7070
7024
|
const { ethAddress } = user.imx;
|
|
7071
7025
|
const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
|
|
7072
7026
|
const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
|
|
7027
|
+
const headers = {
|
|
7028
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7029
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7030
|
+
};
|
|
7073
7031
|
const getSignableOrderRequestV3 = {
|
|
7074
7032
|
user: ethAddress,
|
|
7075
7033
|
amount_buy: amountBuy,
|
|
@@ -7081,14 +7039,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7081
7039
|
};
|
|
7082
7040
|
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
7083
7041
|
getSignableOrderRequestV3,
|
|
7042
|
+
}, { headers });
|
|
7043
|
+
await guardianClient.validate({
|
|
7044
|
+
payloadHash: getSignableOrderResponse.data.payload_hash,
|
|
7084
7045
|
});
|
|
7085
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7086
|
-
transactionType: TransactionTypes.createOrder,
|
|
7087
|
-
transactionData: getSignableOrderRequestV3,
|
|
7088
|
-
});
|
|
7089
|
-
if (!confirmationResult.confirmed) {
|
|
7090
|
-
throw new Error('Transaction rejected by user');
|
|
7091
|
-
}
|
|
7092
7046
|
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
7093
7047
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7094
7048
|
const signableResultData = getSignableOrderResponse.data;
|
|
@@ -7108,11 +7062,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7108
7062
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7109
7063
|
},
|
|
7110
7064
|
};
|
|
7111
|
-
const
|
|
7112
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7113
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7114
|
-
};
|
|
7115
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
7065
|
+
const createOrderResponse = await ordersApi.createOrderV3(orderParams, {
|
|
7116
7066
|
headers,
|
|
7117
7067
|
});
|
|
7118
7068
|
return {
|
|
@@ -7120,28 +7070,24 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7120
7070
|
};
|
|
7121
7071
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
7122
7072
|
}
|
|
7123
|
-
async function cancelOrder$1({ user, starkSigner, request, ordersApi,
|
|
7073
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
|
|
7124
7074
|
return withPassportError(async () => {
|
|
7125
7075
|
const getSignableCancelOrderRequest = {
|
|
7126
7076
|
order_id: request.order_id,
|
|
7127
7077
|
};
|
|
7128
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
7129
|
-
getSignableCancelOrderRequest,
|
|
7130
|
-
});
|
|
7131
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7132
|
-
transactionType: TransactionTypes.cancelOrder,
|
|
7133
|
-
transactionData: getSignableCancelOrderRequest,
|
|
7134
|
-
});
|
|
7135
|
-
if (!confirmationResult.confirmed) {
|
|
7136
|
-
throw new Error('Transaction rejected by user');
|
|
7137
|
-
}
|
|
7138
|
-
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7139
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7140
7078
|
const headers = {
|
|
7141
7079
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7142
7080
|
Authorization: `Bearer ${user.accessToken}`,
|
|
7143
7081
|
};
|
|
7144
|
-
const
|
|
7082
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrderV3({
|
|
7083
|
+
getSignableCancelOrderRequest,
|
|
7084
|
+
}, { headers });
|
|
7085
|
+
await guardianClient.validate({
|
|
7086
|
+
payloadHash: getSignableCancelOrderResponse.data.payload_hash,
|
|
7087
|
+
});
|
|
7088
|
+
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7089
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7090
|
+
const cancelOrderResponse = await ordersApi.cancelOrderV3({
|
|
7145
7091
|
id: request.order_id.toString(),
|
|
7146
7092
|
cancelOrderRequest: {
|
|
7147
7093
|
order_id: request.order_id,
|
|
@@ -7181,7 +7127,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
7181
7127
|
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7182
7128
|
}
|
|
7183
7129
|
|
|
7184
|
-
async function createTrade$1({ request, tradesApi, user, starkSigner,
|
|
7130
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
7185
7131
|
return withPassportError(async () => {
|
|
7186
7132
|
const { ethAddress } = user.imx;
|
|
7187
7133
|
const getSignableTradeRequest = {
|
|
@@ -7190,16 +7136,14 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7190
7136
|
order_id: request.order_id,
|
|
7191
7137
|
user: ethAddress,
|
|
7192
7138
|
};
|
|
7139
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7140
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7193
7141
|
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
7194
7142
|
getSignableTradeRequest,
|
|
7143
|
+
}, { headers });
|
|
7144
|
+
await guardianClient.validate({
|
|
7145
|
+
payloadHash: getSignableTradeResponse.data.payload_hash,
|
|
7195
7146
|
});
|
|
7196
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7197
|
-
transactionType: TransactionTypes.createTrade,
|
|
7198
|
-
transactionData: getSignableTradeRequest,
|
|
7199
|
-
});
|
|
7200
|
-
if (!confirmationResult.confirmed) {
|
|
7201
|
-
throw new Error('Transaction rejected by user');
|
|
7202
|
-
}
|
|
7203
7147
|
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
7204
7148
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7205
7149
|
const { data: signableResultData } = getSignableTradeResponse;
|
|
@@ -7221,8 +7165,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7221
7165
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7222
7166
|
},
|
|
7223
7167
|
};
|
|
7224
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7225
|
-
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7226
7168
|
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
7227
7169
|
headers,
|
|
7228
7170
|
});
|
|
@@ -7230,66 +7172,8 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7230
7172
|
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
7231
7173
|
}
|
|
7232
7174
|
|
|
7233
|
-
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
7234
|
-
const MAX_RETRIES = 3;
|
|
7235
|
-
const wait = (ms) => new Promise((resolve) => {
|
|
7236
|
-
setTimeout(() => resolve(), ms);
|
|
7237
|
-
});
|
|
7238
|
-
const retryWithDelay = async (fn, options) => {
|
|
7239
|
-
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
|
|
7240
|
-
try {
|
|
7241
|
-
return await fn();
|
|
7242
|
-
}
|
|
7243
|
-
catch (err) {
|
|
7244
|
-
if (retries <= 0) {
|
|
7245
|
-
return Promise.reject(finalErr);
|
|
7246
|
-
}
|
|
7247
|
-
await wait(interval);
|
|
7248
|
-
return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
|
|
7249
|
-
}
|
|
7250
|
-
finally {
|
|
7251
|
-
if (retries <= 0) {
|
|
7252
|
-
finallyFn();
|
|
7253
|
-
}
|
|
7254
|
-
}
|
|
7255
|
-
};
|
|
7256
|
-
|
|
7257
7175
|
const ERC721$2 = 'ERC721';
|
|
7258
|
-
|
|
7259
|
-
confirmationScreen.loading();
|
|
7260
|
-
const transactionAPI = new TransactionsApi(new Configuration({
|
|
7261
|
-
accessToken,
|
|
7262
|
-
basePath: imxPublicApiDomain,
|
|
7263
|
-
}));
|
|
7264
|
-
const starkExTransactionApi = new StarkexTransactionsApi(new Configuration({
|
|
7265
|
-
accessToken,
|
|
7266
|
-
basePath: imxPublicApiDomain,
|
|
7267
|
-
}));
|
|
7268
|
-
const finallyFn = () => {
|
|
7269
|
-
confirmationScreen.closeWindow();
|
|
7270
|
-
};
|
|
7271
|
-
const transactionRes = await retryWithDelay(async () => transactionAPI.getTransactionByID({
|
|
7272
|
-
transactionID: payloadHash,
|
|
7273
|
-
chainType: 'starkex',
|
|
7274
|
-
}), { finallyFn });
|
|
7275
|
-
if (!transactionRes.data.id) {
|
|
7276
|
-
throw new Error("Transaction doesn't exists");
|
|
7277
|
-
}
|
|
7278
|
-
const evaluateStarkexRes = await starkExTransactionApi.evaluateStarkexTransaction({
|
|
7279
|
-
payloadHash,
|
|
7280
|
-
});
|
|
7281
|
-
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
7282
|
-
if (confirmationRequired) {
|
|
7283
|
-
const confirmationResult = await confirmationScreen.startGuardianTransaction(payloadHash);
|
|
7284
|
-
if (!confirmationResult.confirmed) {
|
|
7285
|
-
throw new Error('Transaction rejected by user');
|
|
7286
|
-
}
|
|
7287
|
-
}
|
|
7288
|
-
else {
|
|
7289
|
-
confirmationScreen.closeWindow();
|
|
7290
|
-
}
|
|
7291
|
-
};
|
|
7292
|
-
async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicApiDomain, confirmationScreen, }) {
|
|
7176
|
+
async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
|
|
7293
7177
|
return withPassportError(async () => {
|
|
7294
7178
|
const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
|
|
7295
7179
|
const getSignableTransferRequest = {
|
|
@@ -7304,11 +7188,8 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7304
7188
|
const signableResult = await transfersApi.getSignableTransferV1({
|
|
7305
7189
|
getSignableTransferRequest,
|
|
7306
7190
|
}, { headers });
|
|
7307
|
-
await
|
|
7308
|
-
imxPublicApiDomain,
|
|
7309
|
-
accessToken: user.accessToken,
|
|
7191
|
+
await guardianClient.validate({
|
|
7310
7192
|
payloadHash: signableResult.data.payload_hash,
|
|
7311
|
-
confirmationScreen,
|
|
7312
7193
|
});
|
|
7313
7194
|
const signableResultData = signableResult.data;
|
|
7314
7195
|
const { payload_hash: payloadHash } = signableResultData;
|
|
@@ -7337,7 +7218,7 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7337
7218
|
};
|
|
7338
7219
|
}, PassportErrorType.TRANSFER_ERROR);
|
|
7339
7220
|
}
|
|
7340
|
-
async function batchNftTransfer({ user, starkSigner, request, transfersApi,
|
|
7221
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
|
|
7341
7222
|
return withPassportError(async () => {
|
|
7342
7223
|
const { ethAddress } = user.imx;
|
|
7343
7224
|
const signableRequests = request.map((nftTransfer) => ({
|
|
@@ -7353,17 +7234,18 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7353
7234
|
sender_ether_key: ethAddress,
|
|
7354
7235
|
signable_requests: signableRequests,
|
|
7355
7236
|
};
|
|
7237
|
+
const headers = {
|
|
7238
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7239
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7240
|
+
};
|
|
7356
7241
|
const signableResult = await transfersApi.getSignableTransfer({
|
|
7357
7242
|
getSignableTransferRequestV2,
|
|
7358
|
-
});
|
|
7243
|
+
}, { headers });
|
|
7359
7244
|
const popupWindowSize = { width: 480, height: 784 };
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
}
|
|
7364
|
-
if (!confirmationResult.confirmed) {
|
|
7365
|
-
throw new Error('Transaction rejected by user');
|
|
7366
|
-
}
|
|
7245
|
+
await guardianClient.validate({
|
|
7246
|
+
payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
|
|
7247
|
+
popupWindowSize,
|
|
7248
|
+
});
|
|
7367
7249
|
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
7368
7250
|
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
7369
7251
|
return {
|
|
@@ -7381,10 +7263,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7381
7263
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
7382
7264
|
requests,
|
|
7383
7265
|
};
|
|
7384
|
-
const headers = {
|
|
7385
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7386
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7387
|
-
};
|
|
7388
7266
|
const response = await transfersApi.createTransfer({
|
|
7389
7267
|
createTransferRequestV2: transferSigningParams,
|
|
7390
7268
|
}, { headers });
|
|
@@ -7399,13 +7277,18 @@ class PassportImxProvider {
|
|
|
7399
7277
|
starkSigner;
|
|
7400
7278
|
immutableXClient;
|
|
7401
7279
|
confirmationScreen;
|
|
7402
|
-
|
|
7280
|
+
guardianClient;
|
|
7403
7281
|
constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
|
|
7404
7282
|
this.user = user;
|
|
7405
7283
|
this.starkSigner = starkSigner;
|
|
7406
7284
|
this.immutableXClient = immutableXClient;
|
|
7407
|
-
this.imxPublicApiDomain = imxPublicApiDomain;
|
|
7408
7285
|
this.confirmationScreen = confirmationScreen;
|
|
7286
|
+
this.guardianClient = new GuardianClient({
|
|
7287
|
+
imxPublicApiDomain,
|
|
7288
|
+
accessToken: user.accessToken,
|
|
7289
|
+
confirmationScreen,
|
|
7290
|
+
imxEtherAddress: user.imx.ethAddress,
|
|
7291
|
+
});
|
|
7409
7292
|
}
|
|
7410
7293
|
async transfer(request) {
|
|
7411
7294
|
return transfer$1({
|
|
@@ -7413,8 +7296,7 @@ class PassportImxProvider {
|
|
|
7413
7296
|
user: this.user,
|
|
7414
7297
|
starkSigner: this.starkSigner,
|
|
7415
7298
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7416
|
-
|
|
7417
|
-
imxPublicApiDomain: this.imxPublicApiDomain,
|
|
7299
|
+
guardianClient: this.guardianClient,
|
|
7418
7300
|
});
|
|
7419
7301
|
}
|
|
7420
7302
|
// TODO: Remove once implemented
|
|
@@ -7433,7 +7315,7 @@ class PassportImxProvider {
|
|
|
7433
7315
|
user: this.user,
|
|
7434
7316
|
starkSigner: this.starkSigner,
|
|
7435
7317
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7436
|
-
|
|
7318
|
+
guardianClient: this.guardianClient,
|
|
7437
7319
|
});
|
|
7438
7320
|
}
|
|
7439
7321
|
cancelOrder(request) {
|
|
@@ -7442,7 +7324,7 @@ class PassportImxProvider {
|
|
|
7442
7324
|
user: this.user,
|
|
7443
7325
|
starkSigner: this.starkSigner,
|
|
7444
7326
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7445
|
-
|
|
7327
|
+
guardianClient: this.guardianClient,
|
|
7446
7328
|
});
|
|
7447
7329
|
}
|
|
7448
7330
|
createTrade(request) {
|
|
@@ -7451,7 +7333,7 @@ class PassportImxProvider {
|
|
|
7451
7333
|
user: this.user,
|
|
7452
7334
|
starkSigner: this.starkSigner,
|
|
7453
7335
|
tradesApi: this.immutableXClient.tradesApi,
|
|
7454
|
-
|
|
7336
|
+
guardianClient: this.guardianClient,
|
|
7455
7337
|
});
|
|
7456
7338
|
}
|
|
7457
7339
|
batchNftTransfer(request) {
|
|
@@ -7460,7 +7342,7 @@ class PassportImxProvider {
|
|
|
7460
7342
|
user: this.user,
|
|
7461
7343
|
starkSigner: this.starkSigner,
|
|
7462
7344
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7463
|
-
|
|
7345
|
+
guardianClient: this.guardianClient,
|
|
7464
7346
|
});
|
|
7465
7347
|
}
|
|
7466
7348
|
exchangeTransfer(request) {
|
|
@@ -7643,6 +7525,159 @@ class PassportConfiguration {
|
|
|
7643
7525
|
}
|
|
7644
7526
|
}
|
|
7645
7527
|
|
|
7528
|
+
var ReceiveMessage;
|
|
7529
|
+
(function (ReceiveMessage) {
|
|
7530
|
+
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
7531
|
+
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
7532
|
+
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
7533
|
+
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
7534
|
+
var SendMessage;
|
|
7535
|
+
(function (SendMessage) {
|
|
7536
|
+
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
7537
|
+
})(SendMessage || (SendMessage = {}));
|
|
7538
|
+
var TransactionTypes;
|
|
7539
|
+
(function (TransactionTypes) {
|
|
7540
|
+
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
7541
|
+
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
7542
|
+
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
7543
|
+
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
7544
|
+
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
7545
|
+
})(TransactionTypes || (TransactionTypes = {}));
|
|
7546
|
+
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
7547
|
+
|
|
7548
|
+
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
7549
|
+
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
7550
|
+
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
7551
|
+
const newWindow = window.open(url, title, `
|
|
7552
|
+
scrollbars=yes,
|
|
7553
|
+
width=${width},
|
|
7554
|
+
height=${height},
|
|
7555
|
+
top=${top},
|
|
7556
|
+
left=${left}
|
|
7557
|
+
`);
|
|
7558
|
+
if (!newWindow) {
|
|
7559
|
+
throw new Error('Failed to open confirmation screen');
|
|
7560
|
+
}
|
|
7561
|
+
newWindow.focus();
|
|
7562
|
+
return newWindow;
|
|
7563
|
+
};
|
|
7564
|
+
|
|
7565
|
+
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
7566
|
+
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
7567
|
+
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
7568
|
+
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
7569
|
+
class ConfirmationScreen {
|
|
7570
|
+
config;
|
|
7571
|
+
confirmationWindow;
|
|
7572
|
+
constructor(config) {
|
|
7573
|
+
this.config = config;
|
|
7574
|
+
}
|
|
7575
|
+
postMessage(destinationWindow, accessToken, message) {
|
|
7576
|
+
destinationWindow.postMessage({
|
|
7577
|
+
eventType: PASSPORT_EVENT_TYPE,
|
|
7578
|
+
accessToken,
|
|
7579
|
+
...message,
|
|
7580
|
+
}, this.config.passportDomain);
|
|
7581
|
+
}
|
|
7582
|
+
startTransaction(accessToken, transaction, popupOptions) {
|
|
7583
|
+
return new Promise((resolve, reject) => {
|
|
7584
|
+
const messageHandler = ({ data, origin }) => {
|
|
7585
|
+
if (origin !== this.config.passportDomain
|
|
7586
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7587
|
+
return;
|
|
7588
|
+
}
|
|
7589
|
+
switch (data.messageType) {
|
|
7590
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7591
|
+
// TODO: remove once fixed
|
|
7592
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
7593
|
+
this.postMessage(confirmationWindow, accessToken, {
|
|
7594
|
+
messageType: SendMessage.TRANSACTION_START,
|
|
7595
|
+
messageData: transaction,
|
|
7596
|
+
});
|
|
7597
|
+
break;
|
|
7598
|
+
}
|
|
7599
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7600
|
+
resolve({ confirmed: true });
|
|
7601
|
+
break;
|
|
7602
|
+
}
|
|
7603
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7604
|
+
reject(new Error('Transaction error'));
|
|
7605
|
+
break;
|
|
7606
|
+
}
|
|
7607
|
+
default:
|
|
7608
|
+
reject(new Error('Unsupported message type'));
|
|
7609
|
+
}
|
|
7610
|
+
};
|
|
7611
|
+
window.addEventListener('message', messageHandler);
|
|
7612
|
+
const confirmationWindow = openPopupCenter({
|
|
7613
|
+
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
7614
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7615
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7616
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7617
|
+
});
|
|
7618
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7619
|
+
const timer = setInterval(() => {
|
|
7620
|
+
if (confirmationWindow.closed) {
|
|
7621
|
+
clearInterval(timer);
|
|
7622
|
+
window.removeEventListener('message', messageHandler);
|
|
7623
|
+
resolve({ confirmed: false });
|
|
7624
|
+
}
|
|
7625
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7626
|
+
});
|
|
7627
|
+
}
|
|
7628
|
+
startGuardianTransaction(transactionId, imxEtherAddress) {
|
|
7629
|
+
return new Promise((resolve, reject) => {
|
|
7630
|
+
const messageHandler = ({ data, origin }) => {
|
|
7631
|
+
if (origin !== this.config.passportDomain
|
|
7632
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7633
|
+
return;
|
|
7634
|
+
}
|
|
7635
|
+
switch (data.messageType) {
|
|
7636
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7637
|
+
break;
|
|
7638
|
+
}
|
|
7639
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7640
|
+
resolve({ confirmed: true });
|
|
7641
|
+
break;
|
|
7642
|
+
}
|
|
7643
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7644
|
+
reject(new Error('Transaction error'));
|
|
7645
|
+
break;
|
|
7646
|
+
}
|
|
7647
|
+
default:
|
|
7648
|
+
reject(new Error('Unsupported message type'));
|
|
7649
|
+
}
|
|
7650
|
+
};
|
|
7651
|
+
window.addEventListener('message', messageHandler);
|
|
7652
|
+
if (!this.confirmationWindow) {
|
|
7653
|
+
resolve({ confirmed: false });
|
|
7654
|
+
return;
|
|
7655
|
+
}
|
|
7656
|
+
// eslint-disable-next-line max-len
|
|
7657
|
+
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
|
|
7658
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7659
|
+
const timer = setInterval(() => {
|
|
7660
|
+
if (this.confirmationWindow?.closed) {
|
|
7661
|
+
clearInterval(timer);
|
|
7662
|
+
window.removeEventListener('message', messageHandler);
|
|
7663
|
+
resolve({ confirmed: false });
|
|
7664
|
+
}
|
|
7665
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7666
|
+
});
|
|
7667
|
+
}
|
|
7668
|
+
loading(popupOptions) {
|
|
7669
|
+
this.confirmationWindow = openPopupCenter({
|
|
7670
|
+
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7671
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7672
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7673
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7674
|
+
});
|
|
7675
|
+
}
|
|
7676
|
+
closeWindow() {
|
|
7677
|
+
this.confirmationWindow?.close();
|
|
7678
|
+
}
|
|
7679
|
+
}
|
|
7680
|
+
|
|
7646
7681
|
class Passport {
|
|
7647
7682
|
authManager;
|
|
7648
7683
|
config;
|