@imtbl/sdk 0.1.9-alpha.4 → 0.1.10-alpha.1
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 +471 -435
- package/dist/index.d.ts +6 -4
- package/dist/index.js +473 -433
- package/dist/passport.js +482 -441
- 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.1',
|
|
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.1',
|
|
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,86 @@ 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
|
+
loading(popupWindowSize) {
|
|
6927
|
+
this.confirmationScreen.loading(popupWindowSize);
|
|
6928
|
+
}
|
|
6929
|
+
async validate({ payloadHash }) {
|
|
6930
|
+
const finallyFn = () => {
|
|
6931
|
+
this.confirmationScreen.closeWindow();
|
|
6932
|
+
};
|
|
6933
|
+
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
6934
|
+
transactionID: payloadHash,
|
|
6935
|
+
chainType: 'starkex',
|
|
6936
|
+
}), { finallyFn });
|
|
6937
|
+
if (!transactionRes.data.id) {
|
|
6938
|
+
throw new Error("Transaction doesn't exists");
|
|
6939
|
+
}
|
|
6940
|
+
const evaluateStarkexRes = await this.transactionAPI.evaluateTransaction({
|
|
6941
|
+
id: payloadHash,
|
|
6942
|
+
transactionEvaluationRequest: {
|
|
6943
|
+
chainType: 'starkex',
|
|
6944
|
+
},
|
|
6945
|
+
});
|
|
6946
|
+
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
6947
|
+
if (confirmationRequired) {
|
|
6948
|
+
const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
|
|
6949
|
+
if (!confirmationResult.confirmed) {
|
|
6950
|
+
throw new Error('Transaction rejected by user');
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
else {
|
|
6954
|
+
this.confirmationScreen.closeWindow();
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
}
|
|
6958
|
+
|
|
6959
|
+
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
6960
|
+
return withPassportError(async () => {
|
|
6961
|
+
const { ethAddress } = user.imx;
|
|
6962
|
+
const transferAmount = request.amount;
|
|
6963
|
+
const signableResult = await exchangesApi.getExchangeSignableTransfer({
|
|
6964
|
+
id: request.transactionID,
|
|
6965
|
+
getSignableTransferRequest: {
|
|
6966
|
+
sender: ethAddress,
|
|
6967
|
+
token: convertToSignableToken(request),
|
|
6968
|
+
amount: transferAmount,
|
|
6969
|
+
receiver: request.receiver,
|
|
6862
6970
|
},
|
|
6863
6971
|
});
|
|
6864
6972
|
const starkAddress = await starkSigner.getAddress();
|
|
@@ -6892,165 +7000,17 @@ async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, })
|
|
|
6892
7000
|
}, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
|
|
6893
7001
|
}
|
|
6894
7002
|
|
|
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
7003
|
const ERC721$1 = 'ERC721';
|
|
7049
|
-
async function createOrder$1({ starkSigner, user, request, ordersApi,
|
|
7004
|
+
async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
|
|
7050
7005
|
return withPassportError(async () => {
|
|
7006
|
+
guardianClient.loading();
|
|
7051
7007
|
const { ethAddress } = user.imx;
|
|
7052
7008
|
const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
|
|
7053
7009
|
const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
|
|
7010
|
+
const headers = {
|
|
7011
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7012
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7013
|
+
};
|
|
7054
7014
|
const getSignableOrderRequestV3 = {
|
|
7055
7015
|
user: ethAddress,
|
|
7056
7016
|
amount_buy: amountBuy,
|
|
@@ -7062,14 +7022,10 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7062
7022
|
};
|
|
7063
7023
|
const getSignableOrderResponse = await ordersApi.getSignableOrder({
|
|
7064
7024
|
getSignableOrderRequestV3,
|
|
7025
|
+
}, { headers });
|
|
7026
|
+
await guardianClient.validate({
|
|
7027
|
+
payloadHash: getSignableOrderResponse.data.payload_hash,
|
|
7065
7028
|
});
|
|
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
7029
|
const { payload_hash: payloadHash } = getSignableOrderResponse.data;
|
|
7074
7030
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7075
7031
|
const signableResultData = getSignableOrderResponse.data;
|
|
@@ -7089,11 +7045,7 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7089
7045
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7090
7046
|
},
|
|
7091
7047
|
};
|
|
7092
|
-
const
|
|
7093
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7094
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7095
|
-
};
|
|
7096
|
-
const createOrderResponse = await ordersApi.createOrder(orderParams, {
|
|
7048
|
+
const createOrderResponse = await ordersApi.createOrderV3(orderParams, {
|
|
7097
7049
|
headers,
|
|
7098
7050
|
});
|
|
7099
7051
|
return {
|
|
@@ -7101,28 +7053,25 @@ async function createOrder$1({ starkSigner, user, request, ordersApi, confirmati
|
|
|
7101
7053
|
};
|
|
7102
7054
|
}, PassportErrorType.CREATE_ORDER_ERROR);
|
|
7103
7055
|
}
|
|
7104
|
-
async function cancelOrder$1({ user, starkSigner, request, ordersApi,
|
|
7056
|
+
async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
|
|
7105
7057
|
return withPassportError(async () => {
|
|
7058
|
+
guardianClient.loading();
|
|
7106
7059
|
const getSignableCancelOrderRequest = {
|
|
7107
7060
|
order_id: request.order_id,
|
|
7108
7061
|
};
|
|
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
7062
|
const headers = {
|
|
7122
7063
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7123
7064
|
Authorization: `Bearer ${user.accessToken}`,
|
|
7124
7065
|
};
|
|
7125
|
-
const
|
|
7066
|
+
const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrderV3({
|
|
7067
|
+
getSignableCancelOrderRequest,
|
|
7068
|
+
}, { headers });
|
|
7069
|
+
await guardianClient.validate({
|
|
7070
|
+
payloadHash: getSignableCancelOrderResponse.data.payload_hash,
|
|
7071
|
+
});
|
|
7072
|
+
const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
|
|
7073
|
+
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7074
|
+
const cancelOrderResponse = await ordersApi.cancelOrderV3({
|
|
7126
7075
|
id: request.order_id.toString(),
|
|
7127
7076
|
cancelOrderRequest: {
|
|
7128
7077
|
order_id: request.order_id,
|
|
@@ -7162,8 +7111,9 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
|
|
|
7162
7111
|
}, PassportErrorType.USER_REGISTRATION_ERROR);
|
|
7163
7112
|
}
|
|
7164
7113
|
|
|
7165
|
-
async function createTrade$1({ request, tradesApi, user, starkSigner,
|
|
7114
|
+
async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
|
|
7166
7115
|
return withPassportError(async () => {
|
|
7116
|
+
guardianClient.loading();
|
|
7167
7117
|
const { ethAddress } = user.imx;
|
|
7168
7118
|
const getSignableTradeRequest = {
|
|
7169
7119
|
expiration_timestamp: request.expiration_timestamp,
|
|
@@ -7171,16 +7121,14 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7171
7121
|
order_id: request.order_id,
|
|
7172
7122
|
user: ethAddress,
|
|
7173
7123
|
};
|
|
7124
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7125
|
+
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7174
7126
|
const getSignableTradeResponse = await tradesApi.getSignableTrade({
|
|
7175
7127
|
getSignableTradeRequest,
|
|
7128
|
+
}, { headers });
|
|
7129
|
+
await guardianClient.validate({
|
|
7130
|
+
payloadHash: getSignableTradeResponse.data.payload_hash,
|
|
7176
7131
|
});
|
|
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
7132
|
const { payload_hash: payloadHash } = getSignableTradeResponse.data;
|
|
7185
7133
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
7186
7134
|
const { data: signableResultData } = getSignableTradeResponse;
|
|
@@ -7202,8 +7150,6 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7202
7150
|
vault_id_sell: signableResultData.vault_id_sell,
|
|
7203
7151
|
},
|
|
7204
7152
|
};
|
|
7205
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7206
|
-
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
7207
7153
|
const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
|
|
7208
7154
|
headers,
|
|
7209
7155
|
});
|
|
@@ -7211,67 +7157,10 @@ async function createTrade$1({ request, tradesApi, user, starkSigner, confirmati
|
|
|
7211
7157
|
}, PassportErrorType.CREATE_TRADE_ERROR);
|
|
7212
7158
|
}
|
|
7213
7159
|
|
|
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
7160
|
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, }) {
|
|
7161
|
+
async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
|
|
7274
7162
|
return withPassportError(async () => {
|
|
7163
|
+
guardianClient.loading();
|
|
7275
7164
|
const transferAmount = request.type === ERC721$2 ? '1' : request.amount;
|
|
7276
7165
|
const getSignableTransferRequest = {
|
|
7277
7166
|
sender: user.imx.ethAddress,
|
|
@@ -7285,11 +7174,8 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7285
7174
|
const signableResult = await transfersApi.getSignableTransferV1({
|
|
7286
7175
|
getSignableTransferRequest,
|
|
7287
7176
|
}, { headers });
|
|
7288
|
-
await
|
|
7289
|
-
imxPublicApiDomain,
|
|
7290
|
-
accessToken: user.accessToken,
|
|
7177
|
+
await guardianClient.validate({
|
|
7291
7178
|
payloadHash: signableResult.data.payload_hash,
|
|
7292
|
-
confirmationScreen,
|
|
7293
7179
|
});
|
|
7294
7180
|
const signableResultData = signableResult.data;
|
|
7295
7181
|
const { payload_hash: payloadHash } = signableResultData;
|
|
@@ -7318,8 +7204,10 @@ async function transfer$1({ request, transfersApi, starkSigner, user, imxPublicA
|
|
|
7318
7204
|
};
|
|
7319
7205
|
}, PassportErrorType.TRANSFER_ERROR);
|
|
7320
7206
|
}
|
|
7321
|
-
async function batchNftTransfer({ user, starkSigner, request, transfersApi,
|
|
7207
|
+
async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
|
|
7322
7208
|
return withPassportError(async () => {
|
|
7209
|
+
const popupWindowSize = { width: 480, height: 784 };
|
|
7210
|
+
guardianClient.loading(popupWindowSize);
|
|
7323
7211
|
const { ethAddress } = user.imx;
|
|
7324
7212
|
const signableRequests = request.map((nftTransfer) => ({
|
|
7325
7213
|
amount: '1',
|
|
@@ -7334,17 +7222,16 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7334
7222
|
sender_ether_key: ethAddress,
|
|
7335
7223
|
signable_requests: signableRequests,
|
|
7336
7224
|
};
|
|
7225
|
+
const headers = {
|
|
7226
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7227
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
7228
|
+
};
|
|
7337
7229
|
const signableResult = await transfersApi.getSignableTransfer({
|
|
7338
7230
|
getSignableTransferRequestV2,
|
|
7231
|
+
}, { headers });
|
|
7232
|
+
await guardianClient.validate({
|
|
7233
|
+
payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
|
|
7339
7234
|
});
|
|
7340
|
-
const popupWindowSize = { width: 480, height: 784 };
|
|
7341
|
-
const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
|
|
7342
|
-
transactionType: TransactionTypes.createBatchTransfer,
|
|
7343
|
-
transactionData: getSignableTransferRequestV2,
|
|
7344
|
-
}, popupWindowSize);
|
|
7345
|
-
if (!confirmationResult.confirmed) {
|
|
7346
|
-
throw new Error('Transaction rejected by user');
|
|
7347
|
-
}
|
|
7348
7235
|
const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
|
|
7349
7236
|
const starkSignature = await starkSigner.signMessage(resp.payload_hash);
|
|
7350
7237
|
return {
|
|
@@ -7362,10 +7249,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, conf
|
|
|
7362
7249
|
sender_stark_key: signableResult.data.sender_stark_key,
|
|
7363
7250
|
requests,
|
|
7364
7251
|
};
|
|
7365
|
-
const headers = {
|
|
7366
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7367
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
7368
|
-
};
|
|
7369
7252
|
const response = await transfersApi.createTransfer({
|
|
7370
7253
|
createTransferRequestV2: transferSigningParams,
|
|
7371
7254
|
}, { headers });
|
|
@@ -7380,13 +7263,18 @@ class PassportImxProvider {
|
|
|
7380
7263
|
starkSigner;
|
|
7381
7264
|
immutableXClient;
|
|
7382
7265
|
confirmationScreen;
|
|
7383
|
-
|
|
7266
|
+
guardianClient;
|
|
7384
7267
|
constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
|
|
7385
7268
|
this.user = user;
|
|
7386
7269
|
this.starkSigner = starkSigner;
|
|
7387
7270
|
this.immutableXClient = immutableXClient;
|
|
7388
|
-
this.imxPublicApiDomain = imxPublicApiDomain;
|
|
7389
7271
|
this.confirmationScreen = confirmationScreen;
|
|
7272
|
+
this.guardianClient = new GuardianClient({
|
|
7273
|
+
imxPublicApiDomain,
|
|
7274
|
+
accessToken: user.accessToken,
|
|
7275
|
+
confirmationScreen,
|
|
7276
|
+
imxEtherAddress: user.imx.ethAddress,
|
|
7277
|
+
});
|
|
7390
7278
|
}
|
|
7391
7279
|
async transfer(request) {
|
|
7392
7280
|
return transfer$1({
|
|
@@ -7394,8 +7282,7 @@ class PassportImxProvider {
|
|
|
7394
7282
|
user: this.user,
|
|
7395
7283
|
starkSigner: this.starkSigner,
|
|
7396
7284
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7397
|
-
|
|
7398
|
-
imxPublicApiDomain: this.imxPublicApiDomain,
|
|
7285
|
+
guardianClient: this.guardianClient,
|
|
7399
7286
|
});
|
|
7400
7287
|
}
|
|
7401
7288
|
// TODO: Remove once implemented
|
|
@@ -7414,7 +7301,7 @@ class PassportImxProvider {
|
|
|
7414
7301
|
user: this.user,
|
|
7415
7302
|
starkSigner: this.starkSigner,
|
|
7416
7303
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7417
|
-
|
|
7304
|
+
guardianClient: this.guardianClient,
|
|
7418
7305
|
});
|
|
7419
7306
|
}
|
|
7420
7307
|
cancelOrder(request) {
|
|
@@ -7423,7 +7310,7 @@ class PassportImxProvider {
|
|
|
7423
7310
|
user: this.user,
|
|
7424
7311
|
starkSigner: this.starkSigner,
|
|
7425
7312
|
ordersApi: this.immutableXClient.ordersApi,
|
|
7426
|
-
|
|
7313
|
+
guardianClient: this.guardianClient,
|
|
7427
7314
|
});
|
|
7428
7315
|
}
|
|
7429
7316
|
createTrade(request) {
|
|
@@ -7432,7 +7319,7 @@ class PassportImxProvider {
|
|
|
7432
7319
|
user: this.user,
|
|
7433
7320
|
starkSigner: this.starkSigner,
|
|
7434
7321
|
tradesApi: this.immutableXClient.tradesApi,
|
|
7435
|
-
|
|
7322
|
+
guardianClient: this.guardianClient,
|
|
7436
7323
|
});
|
|
7437
7324
|
}
|
|
7438
7325
|
batchNftTransfer(request) {
|
|
@@ -7441,7 +7328,7 @@ class PassportImxProvider {
|
|
|
7441
7328
|
user: this.user,
|
|
7442
7329
|
starkSigner: this.starkSigner,
|
|
7443
7330
|
transfersApi: this.immutableXClient.transfersApi,
|
|
7444
|
-
|
|
7331
|
+
guardianClient: this.guardianClient,
|
|
7445
7332
|
});
|
|
7446
7333
|
}
|
|
7447
7334
|
exchangeTransfer(request) {
|
|
@@ -7624,6 +7511,159 @@ class PassportConfiguration {
|
|
|
7624
7511
|
}
|
|
7625
7512
|
}
|
|
7626
7513
|
|
|
7514
|
+
var ReceiveMessage;
|
|
7515
|
+
(function (ReceiveMessage) {
|
|
7516
|
+
ReceiveMessage["CONFIRMATION_WINDOW_READY"] = "confirmation_window_ready";
|
|
7517
|
+
ReceiveMessage["TRANSACTION_CONFIRMED"] = "transaction_confirmed";
|
|
7518
|
+
ReceiveMessage["TRANSACTION_ERROR"] = "transaction_error";
|
|
7519
|
+
})(ReceiveMessage || (ReceiveMessage = {}));
|
|
7520
|
+
var SendMessage;
|
|
7521
|
+
(function (SendMessage) {
|
|
7522
|
+
SendMessage["TRANSACTION_START"] = "transaction_start";
|
|
7523
|
+
})(SendMessage || (SendMessage = {}));
|
|
7524
|
+
var TransactionTypes;
|
|
7525
|
+
(function (TransactionTypes) {
|
|
7526
|
+
TransactionTypes["cancelOrder"] = "delete:v1/orders";
|
|
7527
|
+
TransactionTypes["createOrder"] = "post:v1/orders";
|
|
7528
|
+
TransactionTypes["createTrade"] = "post:v1/trades";
|
|
7529
|
+
TransactionTypes["createTransfer"] = "post:v1/transfers";
|
|
7530
|
+
TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
|
|
7531
|
+
})(TransactionTypes || (TransactionTypes = {}));
|
|
7532
|
+
const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
|
|
7533
|
+
|
|
7534
|
+
const openPopupCenter = ({ url, title, width, height, }) => {
|
|
7535
|
+
const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
|
|
7536
|
+
const top = Math.max(0, Math.round(window.screenY + (window.outerHeight - height) / 2));
|
|
7537
|
+
const newWindow = window.open(url, title, `
|
|
7538
|
+
scrollbars=yes,
|
|
7539
|
+
width=${width},
|
|
7540
|
+
height=${height},
|
|
7541
|
+
top=${top},
|
|
7542
|
+
left=${left}
|
|
7543
|
+
`);
|
|
7544
|
+
if (!newWindow) {
|
|
7545
|
+
throw new Error('Failed to open confirmation screen');
|
|
7546
|
+
}
|
|
7547
|
+
newWindow.focus();
|
|
7548
|
+
return newWindow;
|
|
7549
|
+
};
|
|
7550
|
+
|
|
7551
|
+
const CONFIRMATION_WINDOW_TITLE = 'Confirm this transaction';
|
|
7552
|
+
const CONFIRMATION_WINDOW_HEIGHT = 380;
|
|
7553
|
+
const CONFIRMATION_WINDOW_WIDTH = 480;
|
|
7554
|
+
const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
|
|
7555
|
+
class ConfirmationScreen {
|
|
7556
|
+
config;
|
|
7557
|
+
confirmationWindow;
|
|
7558
|
+
constructor(config) {
|
|
7559
|
+
this.config = config;
|
|
7560
|
+
}
|
|
7561
|
+
postMessage(destinationWindow, accessToken, message) {
|
|
7562
|
+
destinationWindow.postMessage({
|
|
7563
|
+
eventType: PASSPORT_EVENT_TYPE,
|
|
7564
|
+
accessToken,
|
|
7565
|
+
...message,
|
|
7566
|
+
}, this.config.passportDomain);
|
|
7567
|
+
}
|
|
7568
|
+
startTransaction(accessToken, transaction, popupOptions) {
|
|
7569
|
+
return new Promise((resolve, reject) => {
|
|
7570
|
+
const messageHandler = ({ data, origin }) => {
|
|
7571
|
+
if (origin !== this.config.passportDomain
|
|
7572
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7573
|
+
return;
|
|
7574
|
+
}
|
|
7575
|
+
switch (data.messageType) {
|
|
7576
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7577
|
+
// TODO: remove once fixed
|
|
7578
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
7579
|
+
this.postMessage(confirmationWindow, accessToken, {
|
|
7580
|
+
messageType: SendMessage.TRANSACTION_START,
|
|
7581
|
+
messageData: transaction,
|
|
7582
|
+
});
|
|
7583
|
+
break;
|
|
7584
|
+
}
|
|
7585
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7586
|
+
resolve({ confirmed: true });
|
|
7587
|
+
break;
|
|
7588
|
+
}
|
|
7589
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7590
|
+
reject(new Error('Transaction error'));
|
|
7591
|
+
break;
|
|
7592
|
+
}
|
|
7593
|
+
default:
|
|
7594
|
+
reject(new Error('Unsupported message type'));
|
|
7595
|
+
}
|
|
7596
|
+
};
|
|
7597
|
+
window.addEventListener('message', messageHandler);
|
|
7598
|
+
const confirmationWindow = openPopupCenter({
|
|
7599
|
+
url: `${this.config.passportDomain}/transaction-confirmation`,
|
|
7600
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7601
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7602
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7603
|
+
});
|
|
7604
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7605
|
+
const timer = setInterval(() => {
|
|
7606
|
+
if (confirmationWindow.closed) {
|
|
7607
|
+
clearInterval(timer);
|
|
7608
|
+
window.removeEventListener('message', messageHandler);
|
|
7609
|
+
resolve({ confirmed: false });
|
|
7610
|
+
}
|
|
7611
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7612
|
+
});
|
|
7613
|
+
}
|
|
7614
|
+
startGuardianTransaction(transactionId, imxEtherAddress) {
|
|
7615
|
+
return new Promise((resolve, reject) => {
|
|
7616
|
+
const messageHandler = ({ data, origin }) => {
|
|
7617
|
+
if (origin !== this.config.passportDomain
|
|
7618
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
7619
|
+
return;
|
|
7620
|
+
}
|
|
7621
|
+
switch (data.messageType) {
|
|
7622
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
7623
|
+
break;
|
|
7624
|
+
}
|
|
7625
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
7626
|
+
resolve({ confirmed: true });
|
|
7627
|
+
break;
|
|
7628
|
+
}
|
|
7629
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
7630
|
+
reject(new Error('Transaction error'));
|
|
7631
|
+
break;
|
|
7632
|
+
}
|
|
7633
|
+
default:
|
|
7634
|
+
reject(new Error('Unsupported message type'));
|
|
7635
|
+
}
|
|
7636
|
+
};
|
|
7637
|
+
window.addEventListener('message', messageHandler);
|
|
7638
|
+
if (!this.confirmationWindow) {
|
|
7639
|
+
resolve({ confirmed: false });
|
|
7640
|
+
return;
|
|
7641
|
+
}
|
|
7642
|
+
// eslint-disable-next-line max-len
|
|
7643
|
+
this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
|
|
7644
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
7645
|
+
const timer = setInterval(() => {
|
|
7646
|
+
if (this.confirmationWindow?.closed) {
|
|
7647
|
+
clearInterval(timer);
|
|
7648
|
+
window.removeEventListener('message', messageHandler);
|
|
7649
|
+
resolve({ confirmed: false });
|
|
7650
|
+
}
|
|
7651
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
7652
|
+
});
|
|
7653
|
+
}
|
|
7654
|
+
loading(popupOptions) {
|
|
7655
|
+
this.confirmationWindow = openPopupCenter({
|
|
7656
|
+
url: `${this.config.passportDomain}/transaction-confirmation/loading.html`,
|
|
7657
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
7658
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
7659
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
7660
|
+
});
|
|
7661
|
+
}
|
|
7662
|
+
closeWindow() {
|
|
7663
|
+
this.confirmationWindow?.close();
|
|
7664
|
+
}
|
|
7665
|
+
}
|
|
7666
|
+
|
|
7627
7667
|
class Passport {
|
|
7628
7668
|
authManager;
|
|
7629
7669
|
config;
|