@imtbl/sdk 0.1.9-alpha.4 → 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 +6 -4
- package/dist/blockchain-data.js +1 -2
- package/dist/browser/checkout.js +2 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.cjs +465 -435
- package/dist/index.d.ts +6 -4
- package/dist/index.js +467 -433
- package/dist/passport.js +443 -408
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { ActivityType } from '@imtbl/generated-clients/dist/multi-rollup';
|
|
2
1
|
import globalAxios$1 from 'axios';
|
|
3
2
|
import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, TransfersApi, OrdersApi as OrdersApi$1, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi as TokensApi$1 } from '@imtbl/core-sdk';
|
|
4
3
|
export { createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
|
|
@@ -149,7 +148,7 @@ const setSearchParams$1 = function (url, ...objects) {
|
|
|
149
148
|
*
|
|
150
149
|
* @export
|
|
151
150
|
*/
|
|
152
|
-
const serializeDataIfNeeded = function (value, requestOptions, configuration) {
|
|
151
|
+
const serializeDataIfNeeded$1 = function (value, requestOptions, configuration) {
|
|
153
152
|
const nonString = typeof value !== 'string';
|
|
154
153
|
const needsSerialization = nonString && configuration && configuration.isJsonMime
|
|
155
154
|
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
|
|
@@ -1178,7 +1177,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
|
|
|
1178
1177
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1179
1178
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1180
1179
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1181
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1180
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createListingRequestBody, localVarRequestOptions, configuration);
|
|
1182
1181
|
return {
|
|
1183
1182
|
url: toPathString$1(localVarUrlObj),
|
|
1184
1183
|
options: localVarRequestOptions,
|
|
@@ -1469,7 +1468,7 @@ const PassportApiAxiosParamCreator = function (configuration) {
|
|
|
1469
1468
|
setSearchParams$1(localVarUrlObj, localVarQueryParameter);
|
|
1470
1469
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
1471
1470
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
1472
|
-
localVarRequestOptions.data = serializeDataIfNeeded(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1471
|
+
localVarRequestOptions.data = serializeDataIfNeeded$1(createCounterfactualAddressRequest, localVarRequestOptions, configuration);
|
|
1473
1472
|
return {
|
|
1474
1473
|
url: toPathString$1(localVarUrlObj),
|
|
1475
1474
|
options: localVarRequestOptions,
|
|
@@ -2221,7 +2220,7 @@ class APIError extends Error {
|
|
|
2221
2220
|
|
|
2222
2221
|
/* eslint-disable implicit-arrow-linebreak */
|
|
2223
2222
|
const defaultHeaders = {
|
|
2224
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.
|
|
2223
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.1.10-alpha',
|
|
2225
2224
|
};
|
|
2226
2225
|
/**
|
|
2227
2226
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -2487,7 +2486,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
2487
2486
|
chainID,
|
|
2488
2487
|
coreContractAddress,
|
|
2489
2488
|
registrationContractAddress,
|
|
2490
|
-
sdkVersion: 'ts-immutable-sdk-0.1.
|
|
2489
|
+
sdkVersion: 'ts-immutable-sdk-0.1.10-alpha',
|
|
2491
2490
|
});
|
|
2492
2491
|
/**
|
|
2493
2492
|
* Sets `sdkVersion` at the time of build
|
|
@@ -2990,78 +2989,6 @@ class ImmutableXClient {
|
|
|
2990
2989
|
}
|
|
2991
2990
|
}
|
|
2992
2991
|
|
|
2993
|
-
// used to sign message with L1 keys. Used for registration
|
|
2994
|
-
function serializeEthSignature(sig) {
|
|
2995
|
-
// This is because golang appends a recovery param
|
|
2996
|
-
// https://github.com/ethers-io/ethers.js/issues/823
|
|
2997
|
-
return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString(16), 64)
|
|
2998
|
-
+ encUtils.padLeft(sig.s.toString(16), 64)
|
|
2999
|
-
+ encUtils.padLeft(sig.recoveryParam?.toString(16) || '', 2));
|
|
3000
|
-
}
|
|
3001
|
-
function importRecoveryParam(v) {
|
|
3002
|
-
const isValidBigNumber = new BN(v, 16).cmp(new BN(27)) !== -1
|
|
3003
|
-
? new BN(v, 16).sub(new BN(27)).toNumber()
|
|
3004
|
-
: new BN(v, 16).toNumber();
|
|
3005
|
-
return v.trim()
|
|
3006
|
-
? isValidBigNumber
|
|
3007
|
-
: undefined;
|
|
3008
|
-
}
|
|
3009
|
-
// used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
|
|
3010
|
-
function deserializeSignature(sig, size = 64) {
|
|
3011
|
-
const removedHexPrefixSig = encUtils.removeHexPrefix(sig);
|
|
3012
|
-
return {
|
|
3013
|
-
r: new BN(removedHexPrefixSig.substring(0, size), 'hex'),
|
|
3014
|
-
s: new BN(removedHexPrefixSig.substring(size, size * 2), 'hex'),
|
|
3015
|
-
recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
|
|
3016
|
-
};
|
|
3017
|
-
}
|
|
3018
|
-
async function signRaw(payload, signer) {
|
|
3019
|
-
const signature = deserializeSignature(await signer.signMessage(payload));
|
|
3020
|
-
return serializeEthSignature(signature);
|
|
3021
|
-
}
|
|
3022
|
-
async function signMessage(message, signer) {
|
|
3023
|
-
const ethAddress = await signer.getAddress();
|
|
3024
|
-
const ethSignature = await signRaw(message, signer);
|
|
3025
|
-
return {
|
|
3026
|
-
message,
|
|
3027
|
-
ethAddress,
|
|
3028
|
-
ethSignature,
|
|
3029
|
-
};
|
|
3030
|
-
}
|
|
3031
|
-
|
|
3032
|
-
/**
|
|
3033
|
-
* Helper method to convert token type to a SignableToken type
|
|
3034
|
-
* @param token - the token type to convert to a SignableToken type
|
|
3035
|
-
* @returns the converted SignableToken
|
|
3036
|
-
*/
|
|
3037
|
-
function convertToSignableToken(token) {
|
|
3038
|
-
switch (token.type) {
|
|
3039
|
-
case 'ERC721':
|
|
3040
|
-
return {
|
|
3041
|
-
type: 'ERC721',
|
|
3042
|
-
data: {
|
|
3043
|
-
token_id: token.tokenId,
|
|
3044
|
-
token_address: token.tokenAddress,
|
|
3045
|
-
},
|
|
3046
|
-
};
|
|
3047
|
-
case 'ERC20':
|
|
3048
|
-
return {
|
|
3049
|
-
type: 'ERC20',
|
|
3050
|
-
data: {
|
|
3051
|
-
token_address: token.tokenAddress,
|
|
3052
|
-
},
|
|
3053
|
-
};
|
|
3054
|
-
case 'ETH':
|
|
3055
|
-
default:
|
|
3056
|
-
return {
|
|
3057
|
-
type: 'ETH',
|
|
3058
|
-
data: {
|
|
3059
|
-
decimals: 18,
|
|
3060
|
-
},
|
|
3061
|
-
};
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
|
|
3065
2992
|
function bind(fn, thisArg) {
|
|
3066
2993
|
return function wrap() {
|
|
3067
2994
|
return fn.apply(thisArg, arguments);
|
|
@@ -6273,7 +6200,7 @@ var globalAxios = axios;
|
|
|
6273
6200
|
/* tslint:disable */
|
|
6274
6201
|
/* eslint-disable */
|
|
6275
6202
|
/**
|
|
6276
|
-
*
|
|
6203
|
+
* Guardian
|
|
6277
6204
|
* Guardian API
|
|
6278
6205
|
*
|
|
6279
6206
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6283,7 +6210,7 @@ var globalAxios = axios;
|
|
|
6283
6210
|
* https://openapi-generator.tech
|
|
6284
6211
|
* Do not edit the class manually.
|
|
6285
6212
|
*/
|
|
6286
|
-
const BASE_PATH = "
|
|
6213
|
+
const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
6287
6214
|
/**
|
|
6288
6215
|
*
|
|
6289
6216
|
* @export
|
|
@@ -6320,7 +6247,7 @@ class RequiredError extends Error {
|
|
|
6320
6247
|
/* tslint:disable */
|
|
6321
6248
|
/* eslint-disable */
|
|
6322
6249
|
/**
|
|
6323
|
-
*
|
|
6250
|
+
* Guardian
|
|
6324
6251
|
* Guardian API
|
|
6325
6252
|
*
|
|
6326
6253
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6386,6 +6313,19 @@ const setSearchParams = function (url, ...objects) {
|
|
|
6386
6313
|
setFlattenedQueryParams(searchParams, objects);
|
|
6387
6314
|
url.search = searchParams.toString();
|
|
6388
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
|
+
};
|
|
6389
6329
|
/**
|
|
6390
6330
|
*
|
|
6391
6331
|
* @export
|
|
@@ -6407,7 +6347,7 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6407
6347
|
/* tslint:disable */
|
|
6408
6348
|
/* eslint-disable */
|
|
6409
6349
|
/**
|
|
6410
|
-
*
|
|
6350
|
+
* Guardian
|
|
6411
6351
|
* Guardian API
|
|
6412
6352
|
*
|
|
6413
6353
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6418,22 +6358,25 @@ const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, confi
|
|
|
6418
6358
|
* Do not edit the class manually.
|
|
6419
6359
|
*/
|
|
6420
6360
|
/**
|
|
6421
|
-
*
|
|
6361
|
+
* TransactionsApi - axios parameter creator
|
|
6422
6362
|
* @export
|
|
6423
6363
|
*/
|
|
6424
|
-
const
|
|
6364
|
+
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6425
6365
|
return {
|
|
6426
6366
|
/**
|
|
6427
|
-
*
|
|
6428
|
-
* @summary
|
|
6367
|
+
* Approve a pending transaction
|
|
6368
|
+
* @summary Approve a pending transaction given chain
|
|
6429
6369
|
* @param {string} payloadHash Hash for the payload
|
|
6370
|
+
* @param {TransactionApprovalRequest} transactionApprovalRequest request body for approving a pending transactio
|
|
6430
6371
|
* @param {*} [options] Override http request option.
|
|
6431
6372
|
* @throws {RequiredError}
|
|
6432
6373
|
*/
|
|
6433
|
-
|
|
6374
|
+
approvePendingTransaction: async (payloadHash, transactionApprovalRequest, options = {}) => {
|
|
6434
6375
|
// verify required parameter 'payloadHash' is not null or undefined
|
|
6435
|
-
assertParamExists('
|
|
6436
|
-
|
|
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`
|
|
6437
6380
|
.replace(`{${"payloadHash"}}`, encodeURIComponent(String(payloadHash)));
|
|
6438
6381
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
6439
6382
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
@@ -6447,80 +6390,58 @@ const StarkexTransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6447
6390
|
// authentication BearerAuth required
|
|
6448
6391
|
// http bearer authentication required
|
|
6449
6392
|
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
6393
|
+
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
6450
6394
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
6451
6395
|
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
6452
6396
|
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
6397
|
+
localVarRequestOptions.data = serializeDataIfNeeded(transactionApprovalRequest, localVarRequestOptions, configuration);
|
|
6453
6398
|
return {
|
|
6454
6399
|
url: toPathString(localVarUrlObj),
|
|
6455
6400
|
options: localVarRequestOptions,
|
|
6456
6401
|
};
|
|
6457
6402
|
},
|
|
6458
|
-
};
|
|
6459
|
-
};
|
|
6460
|
-
/**
|
|
6461
|
-
* StarkexTransactionsApi - functional programming interface
|
|
6462
|
-
* @export
|
|
6463
|
-
*/
|
|
6464
|
-
const StarkexTransactionsApiFp = function (configuration) {
|
|
6465
|
-
const localVarAxiosParamCreator = StarkexTransactionsApiAxiosParamCreator(configuration);
|
|
6466
|
-
return {
|
|
6467
6403
|
/**
|
|
6468
|
-
* Check if
|
|
6469
|
-
* @summary Evaluate
|
|
6470
|
-
* @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
|
|
6471
6408
|
* @param {*} [options] Override http request option.
|
|
6472
6409
|
* @throws {RequiredError}
|
|
6473
6410
|
*/
|
|
6474
|
-
async
|
|
6475
|
-
|
|
6476
|
-
|
|
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
|
+
};
|
|
6477
6439
|
},
|
|
6478
|
-
};
|
|
6479
|
-
};
|
|
6480
|
-
/**
|
|
6481
|
-
* StarkexTransactionsApi - object-oriented interface
|
|
6482
|
-
* @export
|
|
6483
|
-
* @class StarkexTransactionsApi
|
|
6484
|
-
* @extends {BaseAPI}
|
|
6485
|
-
*/
|
|
6486
|
-
class StarkexTransactionsApi extends BaseAPI {
|
|
6487
|
-
/**
|
|
6488
|
-
* Check if it is a valid transaction by payload hash
|
|
6489
|
-
* @summary Evaluate if it is an valid transaction
|
|
6490
|
-
* @param {StarkexTransactionsApiEvaluateStarkexTransactionRequest} requestParameters Request parameters.
|
|
6491
|
-
* @param {*} [options] Override http request option.
|
|
6492
|
-
* @throws {RequiredError}
|
|
6493
|
-
* @memberof StarkexTransactionsApi
|
|
6494
|
-
*/
|
|
6495
|
-
evaluateStarkexTransaction(requestParameters, options) {
|
|
6496
|
-
return StarkexTransactionsApiFp(this.configuration).evaluateStarkexTransaction(requestParameters.payloadHash, options).then((request) => request(this.axios, this.basePath));
|
|
6497
|
-
}
|
|
6498
|
-
}
|
|
6499
|
-
|
|
6500
|
-
/* tslint:disable */
|
|
6501
|
-
/* eslint-disable */
|
|
6502
|
-
/**
|
|
6503
|
-
* Swagger Guardian
|
|
6504
|
-
* Guardian API
|
|
6505
|
-
*
|
|
6506
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6507
|
-
* Contact: support@immutable.com
|
|
6508
|
-
*
|
|
6509
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
6510
|
-
* https://openapi-generator.tech
|
|
6511
|
-
* Do not edit the class manually.
|
|
6512
|
-
*/
|
|
6513
|
-
/**
|
|
6514
|
-
* TransactionsApi - axios parameter creator
|
|
6515
|
-
* @export
|
|
6516
|
-
*/
|
|
6517
|
-
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
6518
|
-
return {
|
|
6519
6440
|
/**
|
|
6520
6441
|
* Get a transaction by payload hash
|
|
6521
6442
|
* @summary Info for a specific transaction
|
|
6522
6443
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6523
|
-
* @param {
|
|
6444
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6524
6445
|
* @param {number} [chainID] ID of evm chain
|
|
6525
6446
|
* @param {*} [options] Override http request option.
|
|
6526
6447
|
* @throws {RequiredError}
|
|
@@ -6567,11 +6488,35 @@ const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
|
6567
6488
|
const TransactionsApiFp = function (configuration) {
|
|
6568
6489
|
const localVarAxiosParamCreator = TransactionsApiAxiosParamCreator(configuration);
|
|
6569
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
|
+
},
|
|
6570
6515
|
/**
|
|
6571
6516
|
* Get a transaction by payload hash
|
|
6572
6517
|
* @summary Info for a specific transaction
|
|
6573
6518
|
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
6574
|
-
* @param {
|
|
6519
|
+
* @param {'starkex' | 'evm'} chainType roll up type
|
|
6575
6520
|
* @param {number} [chainID] ID of evm chain
|
|
6576
6521
|
* @param {*} [options] Override http request option.
|
|
6577
6522
|
* @throws {RequiredError}
|
|
@@ -6589,6 +6534,28 @@ const TransactionsApiFp = function (configuration) {
|
|
|
6589
6534
|
* @extends {BaseAPI}
|
|
6590
6535
|
*/
|
|
6591
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
|
+
}
|
|
6592
6559
|
/**
|
|
6593
6560
|
* Get a transaction by payload hash
|
|
6594
6561
|
* @summary Info for a specific transaction
|
|
@@ -6605,7 +6572,7 @@ class TransactionsApi extends BaseAPI {
|
|
|
6605
6572
|
/* tslint:disable */
|
|
6606
6573
|
/* eslint-disable */
|
|
6607
6574
|
/**
|
|
6608
|
-
*
|
|
6575
|
+
* Guardian
|
|
6609
6576
|
* Guardian API
|
|
6610
6577
|
*
|
|
6611
6578
|
* The version of the OpenAPI document: 1.0.0
|
|
@@ -6690,6 +6657,78 @@ class Configuration {
|
|
|
6690
6657
|
}
|
|
6691
6658
|
}
|
|
6692
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
|
+
|
|
6693
6732
|
var PassportErrorType;
|
|
6694
6733
|
(function (PassportErrorType) {
|
|
6695
6734
|
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
@@ -6848,17 +6887,84 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
|
6848
6887
|
return createStarkSigner(privateKey);
|
|
6849
6888
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
6850
6889
|
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
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,
|
|
6862
6968
|
},
|
|
6863
6969
|
});
|
|
6864
6970
|
const starkAddress = await starkSigner.getAddress();
|
|
@@ -6892,165 +6998,16 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
|
|
|
6892
6998
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
6893
6999
|
}
|
|
6894
7000
|
|
|
6895
|
-
var ReceiveMessage;
|
|
6896
|
-
(function (ReceiveMessage) {
|
|
6897
|
-
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
6898
|
-
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
6899
|
-
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
6900
|
-
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
6901
|
-
var SendMessage;
|
|
6902
|
-
(function (SendMessage) {
|
|
6903
|
-
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
6904
|
-
})(SendMessage || (SendMessage = {}));
|
|
6905
|
-
var TransactionTypes;
|
|
6906
|
-
(function (TransactionTypes) {
|
|
6907
|
-
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
6908
|
-
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
6909
|
-
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
6910
|
-
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
6911
|
-
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
6912
|
-
})(TransactionTypes || (TransactionTypes = {}));
|
|
6913
|
-
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
6914
|
-
|
|
6915
|
-
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
6916
|
-
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
6917
|
-
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
6918
|
-
const newWindow = window.open(url, title, `
|
|
6919
|
-
scrollbars=yes,
|
|
6920
|
-
width=${width},
|
|
6921
|
-
height=${height},
|
|
6922
|
-
top=${top},
|
|
6923
|
-
left=${left}
|
|
6924
|
-
`);
|
|
6925
|
-
if (!newWindow) {
|
|
6926
|
-
throw new Error('Failed to open confirmation screen');
|
|
6927
|
-
}
|
|
6928
|
-
newWindow.focus();
|
|
6929
|
-
return newWindow;
|
|
6930
|
-
};
|
|
6931
|
-
|
|
6932
|
-
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
6933
|
-
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
6934
|
-
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
6935
|
-
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
6936
|
-
class ConfirmationScreen {
|
|
6937
|
-
config;
|
|
6938
|
-
confirmationWindow;
|
|
6939
|
-
constructor(config) {
|
|
6940
|
-
this.config = config;
|
|
6941
|
-
}
|
|
6942
|
-
postMessage(destinationWindow, accessToken, message) {
|
|
6943
|
-
destinationWindow.postMessage({
|
|
6944
|
-
eventType: PASSPORT_EVENT_TYPE,
|
|
6945
|
-
accessToken,
|
|
6946
|
-
...message,
|
|
6947
|
-
}, this.config.passportDomain);
|
|
6948
|
-
}
|
|
6949
|
-
startTransaction(accessToken, transaction, popupOptions) {
|
|
6950
|
-
return new Promise((resolve, reject) => {
|
|
6951
|
-
const messageHandler = ({ data, origin }) => {
|
|
6952
|
-
if (origin !== this.config.passportDomain
|
|
6953
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
6954
|
-
return;
|
|
6955
|
-
}
|
|
6956
|
-
switch (data.messageType) {
|
|
6957
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
6958
|
-
// TODO: remove once fixed
|
|
6959
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
6960
|
-
this.postMessage(confirmationWindow, accessToken, {
|
|
6961
|
-
messageType: SendMessage.TRANSACTION_START,
|
|
6962
|
-
messageData: transaction,
|
|
6963
|
-
});
|
|
6964
|
-
break;
|
|
6965
|
-
}
|
|
6966
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
6967
|
-
resolve({ confirmed: true });
|
|
6968
|
-
break;
|
|
6969
|
-
}
|
|
6970
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
6971
|
-
reject(new Error('Transaction error'));
|
|
6972
|
-
break;
|
|
6973
|
-
}
|
|
6974
|
-
default:
|
|
6975
|
-
reject(new Error('Unsupported message type'));
|
|
6976
|
-
}
|
|
6977
|
-
};
|
|
6978
|
-
window.addEventListener('message', messageHandler);
|
|
6979
|
-
const confirmationWindow = openPopupCenter({
|
|
6980
|
-
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
6981
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
6982
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
6983
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
6984
|
-
});
|
|
6985
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
6986
|
-
const timer = setInterval(() => {
|
|
6987
|
-
if (confirmationWindow.closed) {
|
|
6988
|
-
clearInterval(timer);
|
|
6989
|
-
window.removeEventListener('message', messageHandler);
|
|
6990
|
-
resolve({ confirmed: false });
|
|
6991
|
-
}
|
|
6992
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
6993
|
-
});
|
|
6994
|
-
}
|
|
6995
|
-
startGuardianTransaction(transactionId) {
|
|
6996
|
-
return new Promise((resolve, reject) => {
|
|
6997
|
-
const messageHandler = ({ data, origin }) => {
|
|
6998
|
-
if (origin !== this.config.passportDomain
|
|
6999
|
-
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7000
|
-
return;
|
|
7001
|
-
}
|
|
7002
|
-
switch (data.messageType) {
|
|
7003
|
-
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7004
|
-
break;
|
|
7005
|
-
}
|
|
7006
|
-
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7007
|
-
resolve({ confirmed: true });
|
|
7008
|
-
break;
|
|
7009
|
-
}
|
|
7010
|
-
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7011
|
-
reject(new Error('Transaction error'));
|
|
7012
|
-
break;
|
|
7013
|
-
}
|
|
7014
|
-
default:
|
|
7015
|
-
reject(new Error('Unsupported message type'));
|
|
7016
|
-
}
|
|
7017
|
-
};
|
|
7018
|
-
window.addEventListener('message', messageHandler);
|
|
7019
|
-
if (!this.confirmationWindow) {
|
|
7020
|
-
resolve({ confirmed: false });
|
|
7021
|
-
return;
|
|
7022
|
-
}
|
|
7023
|
-
// eslint-disable-next-line max-len
|
|
7024
|
-
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&chainType=starkex`;
|
|
7025
|
-
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7026
|
-
const timer = setInterval(() => {
|
|
7027
|
-
if (this.confirmationWindow?.closed) {
|
|
7028
|
-
clearInterval(timer);
|
|
7029
|
-
window.removeEventListener('message', messageHandler);
|
|
7030
|
-
resolve({ confirmed: false });
|
|
7031
|
-
}
|
|
7032
|
-
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7033
|
-
});
|
|
7034
|
-
}
|
|
7035
|
-
loading(popupOptions) {
|
|
7036
|
-
this.confirmationWindow = openPopupCenter({
|
|
7037
|
-
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7038
|
-
title: CONFIRMATION_WINDOW_TITLE,
|
|
7039
|
-
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7040
|
-
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7041
|
-
});
|
|
7042
|
-
}
|
|
7043
|
-
closeWindow() {
|
|
7044
|
-
this.confirmationWindow?.close();
|
|
7045
|
-
}
|
|
7046
|
-
}
|
|
7047
|
-
|
|
7048
7001
|
const ERC721$1 = 'ERC721';
|
|
7049
|
-
async function createOrder$1({ starkSigner, user, request, ordersApi,
|
|
7002
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
|
|
7050
7003
|
return withPassportError(async () => {
|
|
7051
7004
|
const { ethAddress } = user.imx;
|
|
7052
7005
|
const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
|
|
7053
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
|
+
};
|
|
7054
7011
|
const getSignableOrderRequestV3 = {
|
|
7055
7012
|
user: ethAddress,
|
|
7056
7013
|
amount_buy: amountBuy,
|
|
@@ -7062,14 +7019,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7062
7019
|
};
|
|
7063
7020
|
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
7064
7021
|
getSignableOrderRequestV3,
|
|
7022
|
+
}, { headers });
|
|
7023
|
+
await guardianClient.validate({
|
|
7024
|
+
payloadHash: getSignableOrderResponse.data.payload_hash,
|
|
7065
7025
|
});
|
|
7066
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7067
|
-
transactionType: TransactionTypes.createOrder,
|
|
7068
|
-
transactionData: getSignableOrderRequestV3,
|
|
7069
|
-
});
|
|
7070
|
-
if (!confirmationResult.confirmed) {
|
|
7071
|
-
throw new Error('Transaction rejected by user');
|
|
7072
|
-
}
|
|
7073
7026
|
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
7074
7027
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7075
7028
|
const signableResultData = getSignableOrderResponse.data;
|
|
@@ -7089,11 +7042,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7089
7042
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7090
7043
|
},
|
|
7091
7044
|
};
|
|
7092
|
-
const
|
|
7093
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7094
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7095
|
-
};
|
|
7096
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
7045
|
+
const createOrderResponse = await ordersApi.createOrderV3(orderParams, {
|
|
7097
7046
|
headers,
|
|
7098
7047
|
});
|
|
7099
7048
|
return {
|
|
@@ -7101,28 +7050,24 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7101
7050
|
};
|
|
7102
7051
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
7103
7052
|
}
|
|
7104
|
-
async function cancelOrder$1({ user, starkSigner, request, ordersApi,
|
|
7053
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
|
|
7105
7054
|
return withPassportError(async () => {
|
|
7106
7055
|
const getSignableCancelOrderRequest = {
|
|
7107
7056
|
order_id: request.order_id,
|
|
7108
7057
|
};
|
|
7109
|
-
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
|
|
7110
|
-
getSignableCancelOrderRequest,
|
|
7111
|
-
});
|
|
7112
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7113
|
-
transactionType: TransactionTypes.cancelOrder,
|
|
7114
|
-
transactionData: getSignableCancelOrderRequest,
|
|
7115
|
-
});
|
|
7116
|
-
if (!confirmationResult.confirmed) {
|
|
7117
|
-
throw new Error('Transaction rejected by user');
|
|
7118
|
-
}
|
|
7119
|
-
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7120
|
-
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7121
7058
|
const headers = {
|
|
7122
7059
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7123
7060
|
Authorization: `Bearer ${user.accessToken}`,
|
|
7124
7061
|
};
|
|
7125
|
-
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({
|
|
7126
7071
|
id: request.order_id.toString(),
|
|
7127
7072
|
cancelOrderRequest: {
|
|
7128
7073
|
order_id: request.order_id,
|
|
@@ -7162,7 +7107,7 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
7162
7107
|
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7163
7108
|
}
|
|
7164
7109
|
|
|
7165
|
-
async function createTrade$1({ request, tradesApi, user, starkSigner,
|
|
7110
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
7166
7111
|
return withPassportError(async () => {
|
|
7167
7112
|
const { ethAddress } = user.imx;
|
|
7168
7113
|
const getSignableTradeRequest = {
|
|
@@ -7171,16 +7116,14 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7171
7116
|
order_id: request.order_id,
|
|
7172
7117
|
user: ethAddress,
|
|
7173
7118
|
};
|
|
7119
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7120
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7174
7121
|
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
7175
7122
|
getSignableTradeRequest,
|
|
7123
|
+
}, { headers });
|
|
7124
|
+
await guardianClient.validate({
|
|
7125
|
+
payloadHash: getSignableTradeResponse.data.payload_hash,
|
|
7176
7126
|
});
|
|
7177
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7178
|
-
transactionType: TransactionTypes.createTrade,
|
|
7179
|
-
transactionData: getSignableTradeRequest,
|
|
7180
|
-
});
|
|
7181
|
-
if (!confirmationResult.confirmed) {
|
|
7182
|
-
throw new Error('Transaction rejected by user');
|
|
7183
|
-
}
|
|
7184
7127
|
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
7185
7128
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7186
7129
|
const { data: signableResultData } = getSignableTradeResponse;
|
|
@@ -7202,8 +7145,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7202
7145
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7203
7146
|
},
|
|
7204
7147
|
};
|
|
7205
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7206
|
-
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7207
7148
|
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
7208
7149
|
headers,
|
|
7209
7150
|
});
|
|
@@ -7211,66 +7152,8 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7211
7152
|
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
7212
7153
|
}
|
|
7213
7154
|
|
|
7214
|
-
const POLL_INTERVAL = 1 * 1000; // every 1 second
|
|
7215
|
-
const MAX_RETRIES = 3;
|
|
7216
|
-
const wait = (ms) => new Promise((resolve) => {
|
|
7217
|
-
setTimeout(() => resolve(), ms);
|
|
7218
|
-
});
|
|
7219
|
-
const retryWithDelay = async (fn, options) => {
|
|
7220
|
-
const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
|
|
7221
|
-
try {
|
|
7222
|
-
return await fn();
|
|
7223
|
-
}
|
|
7224
|
-
catch (err) {
|
|
7225
|
-
if (retries <= 0) {
|
|
7226
|
-
return Promise.reject(finalErr);
|
|
7227
|
-
}
|
|
7228
|
-
await wait(interval);
|
|
7229
|
-
return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
|
|
7230
|
-
}
|
|
7231
|
-
finally {
|
|
7232
|
-
if (retries <= 0) {
|
|
7233
|
-
finallyFn();
|
|
7234
|
-
}
|
|
7235
|
-
}
|
|
7236
|
-
};
|
|
7237
|
-
|
|
7238
7155
|
const ERC721$2 = 'ERC721';
|
|
7239
|
-
|
|
7240
|
-
confirmationScreen.loading();
|
|
7241
|
-
const transactionAPI = new TransactionsApi(new Configuration({
|
|
7242
|
-
accessToken,
|
|
7243
|
-
basePath: imxPublicApiDomain,
|
|
7244
|
-
}));
|
|
7245
|
-
const starkExTransactionApi = new StarkexTransactionsApi(new Configuration({
|
|
7246
|
-
accessToken,
|
|
7247
|
-
basePath: imxPublicApiDomain,
|
|
7248
|
-
}));
|
|
7249
|
-
const finallyFn = () => {
|
|
7250
|
-
confirmationScreen.closeWindow();
|
|
7251
|
-
};
|
|
7252
|
-
const transactionRes = await retryWithDelay(async () => transactionAPI.getTransactionByID({
|
|
7253
|
-
transactionID: payloadHash,
|
|
7254
|
-
chainType: 'starkex',
|
|
7255
|
-
}), { finallyFn });
|
|
7256
|
-
if (!transactionRes.data.id) {
|
|
7257
|
-
throw new Error("Transaction doesn't exists");
|
|
7258
|
-
}
|
|
7259
|
-
const evaluateStarkexRes = await starkExTransactionApi.evaluateStarkexTransaction({
|
|
7260
|
-
payloadHash,
|
|
7261
|
-
});
|
|
7262
|
-
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
7263
|
-
if (confirmationRequired) {
|
|
7264
|
-
const confirmationResult = await confirmationScreen.startGuardianTransaction(payloadHash);
|
|
7265
|
-
if (!confirmationResult.confirmed) {
|
|
7266
|
-
throw new Error('Transaction rejected by user');
|
|
7267
|
-
}
|
|
7268
|
-
}
|
|
7269
|
-
else {
|
|
7270
|
-
confirmationScreen.closeWindow();
|
|
7271
|
-
}
|
|
7272
|
-
};
|
|
7273
|
-
async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicApiDomain, confirmationScreen, }) {
|
|
7156
|
+
async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
|
|
7274
7157
|
return withPassportError(async () => {
|
|
7275
7158
|
const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
|
|
7276
7159
|
const getSignableTransferRequest = {
|
|
@@ -7285,11 +7168,8 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7285
7168
|
const signableResult = await transfersApi.getSignableTransferV1({
|
|
7286
7169
|
getSignableTransferRequest,
|
|
7287
7170
|
}, { headers });
|
|
7288
|
-
await
|
|
7289
|
-
imxPublicApiDomain,
|
|
7290
|
-
accessToken: user.accessToken,
|
|
7171
|
+
await guardianClient.validate({
|
|
7291
7172
|
payloadHash: signableResult.data.payload_hash,
|
|
7292
|
-
confirmationScreen,
|
|
7293
7173
|
});
|
|
7294
7174
|
const signableResultData = signableResult.data;
|
|
7295
7175
|
const { payload_hash: payloadHash } = signableResultData;
|
|
@@ -7318,7 +7198,7 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7318
7198
|
};
|
|
7319
7199
|
}, PassportErrorType.TRANSFER_ERROR);
|
|
7320
7200
|
}
|
|
7321
|
-
async function batchNftTransfer({ user, starkSigner, request, transfersApi,
|
|
7201
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
|
|
7322
7202
|
return withPassportError(async () => {
|
|
7323
7203
|
const { ethAddress } = user.imx;
|
|
7324
7204
|
const signableRequests = request.map((nftTransfer) => ({
|
|
@@ -7334,17 +7214,18 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7334
7214
|
sender_ether_key: ethAddress,
|
|
7335
7215
|
signable_requests: signableRequests,
|
|
7336
7216
|
};
|
|
7217
|
+
const headers = {
|
|
7218
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7219
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7220
|
+
};
|
|
7337
7221
|
const signableResult = await transfersApi.getSignableTransfer({
|
|
7338
7222
|
getSignableTransferRequestV2,
|
|
7339
|
-
});
|
|
7223
|
+
}, { headers });
|
|
7340
7224
|
const popupWindowSize = { width: 480, height: 784 };
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
}
|
|
7345
|
-
if (!confirmationResult.confirmed) {
|
|
7346
|
-
throw new Error('Transaction rejected by user');
|
|
7347
|
-
}
|
|
7225
|
+
await guardianClient.validate({
|
|
7226
|
+
payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
|
|
7227
|
+
popupWindowSize,
|
|
7228
|
+
});
|
|
7348
7229
|
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
7349
7230
|
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
7350
7231
|
return {
|
|
@@ -7362,10 +7243,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7362
7243
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
7363
7244
|
requests,
|
|
7364
7245
|
};
|
|
7365
|
-
const headers = {
|
|
7366
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7367
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7368
|
-
};
|
|
7369
7246
|
const response = await transfersApi.createTransfer({
|
|
7370
7247
|
createTransferRequestV2: transferSigningParams,
|
|
7371
7248
|
}, { headers });
|
|
@@ -7380,13 +7257,18 @@ class PassportImxProvider {
|
|
|
7380
7257
|
starkSigner;
|
|
7381
7258
|
immutableXClient;
|
|
7382
7259
|
confirmationScreen;
|
|
7383
|
-
|
|
7260
|
+
guardianClient;
|
|
7384
7261
|
constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
|
|
7385
7262
|
this.user = user;
|
|
7386
7263
|
this.starkSigner = starkSigner;
|
|
7387
7264
|
this.immutableXClient = immutableXClient;
|
|
7388
|
-
this.imxPublicApiDomain = imxPublicApiDomain;
|
|
7389
7265
|
this.confirmationScreen = confirmationScreen;
|
|
7266
|
+
this.guardianClient = new GuardianClient({
|
|
7267
|
+
imxPublicApiDomain,
|
|
7268
|
+
accessToken: user.accessToken,
|
|
7269
|
+
confirmationScreen,
|
|
7270
|
+
imxEtherAddress: user.imx.ethAddress,
|
|
7271
|
+
});
|
|
7390
7272
|
}
|
|
7391
7273
|
async transfer(request) {
|
|
7392
7274
|
return transfer$1({
|
|
@@ -7394,8 +7276,7 @@ class PassportImxProvider {
|
|
|
7394
7276
|
user: this.user,
|
|
7395
7277
|
starkSigner: this.starkSigner,
|
|
7396
7278
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7397
|
-
|
|
7398
|
-
imxPublicApiDomain: this.imxPublicApiDomain,
|
|
7279
|
+
guardianClient: this.guardianClient,
|
|
7399
7280
|
});
|
|
7400
7281
|
}
|
|
7401
7282
|
// TODO: Remove once implemented
|
|
@@ -7414,7 +7295,7 @@ class PassportImxProvider {
|
|
|
7414
7295
|
user: this.user,
|
|
7415
7296
|
starkSigner: this.starkSigner,
|
|
7416
7297
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7417
|
-
|
|
7298
|
+
guardianClient: this.guardianClient,
|
|
7418
7299
|
});
|
|
7419
7300
|
}
|
|
7420
7301
|
cancelOrder(request) {
|
|
@@ -7423,7 +7304,7 @@ class PassportImxProvider {
|
|
|
7423
7304
|
user: this.user,
|
|
7424
7305
|
starkSigner: this.starkSigner,
|
|
7425
7306
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7426
|
-
|
|
7307
|
+
guardianClient: this.guardianClient,
|
|
7427
7308
|
});
|
|
7428
7309
|
}
|
|
7429
7310
|
createTrade(request) {
|
|
@@ -7432,7 +7313,7 @@ class PassportImxProvider {
|
|
|
7432
7313
|
user: this.user,
|
|
7433
7314
|
starkSigner: this.starkSigner,
|
|
7434
7315
|
tradesApi: this.immutableXClient.tradesApi,
|
|
7435
|
-
|
|
7316
|
+
guardianClient: this.guardianClient,
|
|
7436
7317
|
});
|
|
7437
7318
|
}
|
|
7438
7319
|
batchNftTransfer(request) {
|
|
@@ -7441,7 +7322,7 @@ class PassportImxProvider {
|
|
|
7441
7322
|
user: this.user,
|
|
7442
7323
|
starkSigner: this.starkSigner,
|
|
7443
7324
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7444
|
-
|
|
7325
|
+
guardianClient: this.guardianClient,
|
|
7445
7326
|
});
|
|
7446
7327
|
}
|
|
7447
7328
|
exchangeTransfer(request) {
|
|
@@ -7624,6 +7505,159 @@ class PassportConfiguration {
|
|
|
7624
7505
|
}
|
|
7625
7506
|
}
|
|
7626
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
|
+
|
|
7627
7661
|
class Passport {
|
|
7628
7662
|
authManager;
|
|
7629
7663
|
config;
|