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