@imtbl/sdk 1.12.2 → 1.13.0
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.js +2 -2
- package/dist/browser/checkout/sdk.js +4 -4
- package/dist/checkout.js +4 -4
- package/dist/config.js +1 -1
- package/dist/index.browser.js +13 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +94 -45
- package/dist/index.js +95 -46
- package/dist/orderbook.js +1 -1
- package/dist/passport.js +91 -42
- package/dist/x.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -174,7 +174,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
177
|
-
const SDK_VERSION$1 = '1.
|
|
177
|
+
const SDK_VERSION$1 = '1.13.0';
|
|
178
178
|
const getReferrer$1 = () => {
|
|
179
179
|
if (isNode$1()) {
|
|
180
180
|
return '';
|
|
@@ -11571,7 +11571,7 @@ class MultiRollupApiClients {
|
|
|
11571
11571
|
}
|
|
11572
11572
|
|
|
11573
11573
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11574
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.
|
|
11574
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.13.0' };
|
|
11575
11575
|
const createConfig = ({ basePath, headers, }) => {
|
|
11576
11576
|
if (!basePath.trim()) {
|
|
11577
11577
|
throw Error('basePath can not be empty');
|
|
@@ -11643,7 +11643,7 @@ class APIError extends Error {
|
|
|
11643
11643
|
|
|
11644
11644
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11645
11645
|
const defaultHeaders = {
|
|
11646
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.
|
|
11646
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.13.0',
|
|
11647
11647
|
};
|
|
11648
11648
|
/**
|
|
11649
11649
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -12126,7 +12126,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
12126
12126
|
chainID,
|
|
12127
12127
|
coreContractAddress,
|
|
12128
12128
|
registrationContractAddress,
|
|
12129
|
-
sdkVersion: 'ts-immutable-sdk-1.
|
|
12129
|
+
sdkVersion: 'ts-immutable-sdk-1.13.0',
|
|
12130
12130
|
});
|
|
12131
12131
|
/**
|
|
12132
12132
|
* Sets `sdkVersion` at the time of build
|
|
@@ -16748,6 +16748,13 @@ function isTokenExpired(oidcUser) {
|
|
|
16748
16748
|
return isIdTokenExpired(idToken);
|
|
16749
16749
|
}
|
|
16750
16750
|
|
|
16751
|
+
var PassportEvents;
|
|
16752
|
+
(function (PassportEvents) {
|
|
16753
|
+
PassportEvents["LOGGED_OUT"] = "loggedOut";
|
|
16754
|
+
})(PassportEvents || (PassportEvents = {}));
|
|
16755
|
+
const isUserZkEvm = (user) => !!user.zkEvm;
|
|
16756
|
+
const isUserImx = (user) => !!user.imx;
|
|
16757
|
+
|
|
16751
16758
|
const formUrlEncodedHeader = {
|
|
16752
16759
|
headers: {
|
|
16753
16760
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -16799,8 +16806,8 @@ function sha256(buffer) {
|
|
|
16799
16806
|
}
|
|
16800
16807
|
class AuthManager {
|
|
16801
16808
|
userManager;
|
|
16802
|
-
config;
|
|
16803
16809
|
deviceCredentialsManager;
|
|
16810
|
+
config;
|
|
16804
16811
|
logoutMode;
|
|
16805
16812
|
/**
|
|
16806
16813
|
* Promise that is used to prevent multiple concurrent calls to the refresh token endpoint.
|
|
@@ -17030,6 +17037,12 @@ class AuthManager {
|
|
|
17030
17037
|
async logoutSilentCallback(url) {
|
|
17031
17038
|
return this.userManager.signoutSilentCallback(url);
|
|
17032
17039
|
}
|
|
17040
|
+
forceUserRefreshInBackground() {
|
|
17041
|
+
this.refreshTokenAndUpdatePromise().catch((error) => {
|
|
17042
|
+
// eslint-disable-next-line no-console
|
|
17043
|
+
console.warn('Failed to refresh user token', error);
|
|
17044
|
+
});
|
|
17045
|
+
}
|
|
17033
17046
|
async forceUserRefresh() {
|
|
17034
17047
|
return this.refreshTokenAndUpdatePromise();
|
|
17035
17048
|
}
|
|
@@ -17051,7 +17064,19 @@ class AuthManager {
|
|
|
17051
17064
|
resolve(null);
|
|
17052
17065
|
}
|
|
17053
17066
|
catch (err) {
|
|
17054
|
-
|
|
17067
|
+
let passportErrorType = PassportErrorType.AUTHENTICATION_ERROR;
|
|
17068
|
+
let errorMessage = 'Failed to refresh token';
|
|
17069
|
+
if (err instanceof oidcClientTs.ErrorTimeout) {
|
|
17070
|
+
passportErrorType = PassportErrorType.SILENT_LOGIN_ERROR;
|
|
17071
|
+
}
|
|
17072
|
+
else if (err instanceof oidcClientTs.ErrorResponse) {
|
|
17073
|
+
passportErrorType = PassportErrorType.NOT_LOGGED_IN_ERROR;
|
|
17074
|
+
errorMessage = `${err.message}: ${err.error_description}`;
|
|
17075
|
+
}
|
|
17076
|
+
else if (err instanceof Error) {
|
|
17077
|
+
errorMessage = err.message;
|
|
17078
|
+
}
|
|
17079
|
+
reject(new PassportError(errorMessage, passportErrorType));
|
|
17055
17080
|
}
|
|
17056
17081
|
finally {
|
|
17057
17082
|
this.refreshingPromise = null; // Reset the promise after completion
|
|
@@ -17060,22 +17085,56 @@ class AuthManager {
|
|
|
17060
17085
|
return this.refreshingPromise;
|
|
17061
17086
|
}
|
|
17062
17087
|
/**
|
|
17063
|
-
*
|
|
17064
|
-
*
|
|
17065
|
-
|
|
17066
|
-
|
|
17067
|
-
|
|
17068
|
-
|
|
17069
|
-
|
|
17070
|
-
|
|
17071
|
-
|
|
17072
|
-
|
|
17073
|
-
|
|
17074
|
-
|
|
17075
|
-
|
|
17088
|
+
*
|
|
17089
|
+
* @param typeAssertion {(user: User) => boolean} - Optional. If provided, then the User will be checked against
|
|
17090
|
+
* the typeAssertion. If the user meets the requirements, then it will be typed as T and returned. If the User
|
|
17091
|
+
* does NOT meet the type assertion, then execution will continue, and we will attempt to obtain a User that does
|
|
17092
|
+
* meet the type assertion.
|
|
17093
|
+
*
|
|
17094
|
+
* This function will attempt to obtain a User in the following order:
|
|
17095
|
+
* 1. If the User is currently refreshing, wait for the refresh to complete.
|
|
17096
|
+
* 2. Attempt to obtain a User from storage that has not expired.
|
|
17097
|
+
* 3. Attempt to refresh the User if a refresh token is present.
|
|
17098
|
+
* 4. Return null if no valid User can be obtained.
|
|
17099
|
+
*/
|
|
17100
|
+
async getUser(typeAssertion = (user) => true) {
|
|
17101
|
+
if (this.refreshingPromise) {
|
|
17102
|
+
const user = await this.refreshingPromise;
|
|
17103
|
+
if (user && typeAssertion(user)) {
|
|
17104
|
+
return user;
|
|
17076
17105
|
}
|
|
17077
17106
|
return null;
|
|
17078
|
-
}
|
|
17107
|
+
}
|
|
17108
|
+
const oidcUser = await this.userManager.getUser();
|
|
17109
|
+
if (!oidcUser)
|
|
17110
|
+
return null;
|
|
17111
|
+
if (!isTokenExpired(oidcUser)) {
|
|
17112
|
+
const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
17113
|
+
if (user && typeAssertion(user)) {
|
|
17114
|
+
return user;
|
|
17115
|
+
}
|
|
17116
|
+
}
|
|
17117
|
+
if (oidcUser.refresh_token) {
|
|
17118
|
+
const user = await this.refreshTokenAndUpdatePromise();
|
|
17119
|
+
if (user && typeAssertion(user)) {
|
|
17120
|
+
return user;
|
|
17121
|
+
}
|
|
17122
|
+
}
|
|
17123
|
+
return null;
|
|
17124
|
+
}
|
|
17125
|
+
async getUserZkEvm() {
|
|
17126
|
+
const user = await this.getUser(isUserZkEvm);
|
|
17127
|
+
if (!user) {
|
|
17128
|
+
throw new Error('Failed to obtain a User with the required ZkEvm attributes');
|
|
17129
|
+
}
|
|
17130
|
+
return user;
|
|
17131
|
+
}
|
|
17132
|
+
async getUserImx() {
|
|
17133
|
+
const user = await this.getUser(isUserImx);
|
|
17134
|
+
if (!user) {
|
|
17135
|
+
throw new Error('Failed to obtain a User with the required IMX attributes');
|
|
17136
|
+
}
|
|
17137
|
+
return user;
|
|
17079
17138
|
}
|
|
17080
17139
|
}
|
|
17081
17140
|
|
|
@@ -17144,11 +17203,6 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
|
17144
17203
|
return coreSdk.createStarkSigner(privateKey);
|
|
17145
17204
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
17146
17205
|
|
|
17147
|
-
var PassportEvents;
|
|
17148
|
-
(function (PassportEvents) {
|
|
17149
|
-
PassportEvents["LOGGED_OUT"] = "loggedOut";
|
|
17150
|
-
})(PassportEvents || (PassportEvents = {}));
|
|
17151
|
-
|
|
17152
17206
|
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
17153
17207
|
return withPassportError(async () => {
|
|
17154
17208
|
const { ethAddress } = user.imx;
|
|
@@ -17535,7 +17589,7 @@ class PassportImxProvider {
|
|
|
17535
17589
|
* @see getAuthenticatedUserAndSigners
|
|
17536
17590
|
*
|
|
17537
17591
|
*/
|
|
17538
|
-
|
|
17592
|
+
initialiseSigners() {
|
|
17539
17593
|
const generateSigners = async () => {
|
|
17540
17594
|
const user = await this.authManager.getUser();
|
|
17541
17595
|
// The user will be present because the factory validates it
|
|
@@ -17574,7 +17628,6 @@ class PassportImxProvider {
|
|
|
17574
17628
|
}
|
|
17575
17629
|
async getRegisteredImxUserAndSigners() {
|
|
17576
17630
|
const { user, starkSigner, ethSigner } = await this.getAuthenticatedUserAndSigners();
|
|
17577
|
-
const isUserImx = (oidcUser) => oidcUser?.imx !== undefined;
|
|
17578
17631
|
if (!isUserImx(user)) {
|
|
17579
17632
|
throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
|
|
17580
17633
|
}
|
|
@@ -18144,11 +18197,11 @@ class RelayerClient {
|
|
|
18144
18197
|
jsonrpc: '2.0',
|
|
18145
18198
|
...request,
|
|
18146
18199
|
};
|
|
18147
|
-
const user = await this.authManager.
|
|
18200
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18148
18201
|
const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
|
|
18149
18202
|
method: 'POST',
|
|
18150
18203
|
headers: {
|
|
18151
|
-
Authorization: `Bearer ${user
|
|
18204
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
18152
18205
|
'Content-Type': 'application/json',
|
|
18153
18206
|
},
|
|
18154
18207
|
body: JSON.stringify(body),
|
|
@@ -18254,7 +18307,7 @@ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients
|
|
|
18254
18307
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
|
|
18255
18308
|
}
|
|
18256
18309
|
try {
|
|
18257
|
-
await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
18310
|
+
const registrationResponse = await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
18258
18311
|
chainName,
|
|
18259
18312
|
createCounterfactualAddressRequest: {
|
|
18260
18313
|
ethereum_address: ethereumAddress,
|
|
@@ -18263,15 +18316,12 @@ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients
|
|
|
18263
18316
|
}, {
|
|
18264
18317
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
18265
18318
|
});
|
|
18319
|
+
authManager.forceUserRefreshInBackground();
|
|
18320
|
+
return registrationResponse.data.counterfactual_address;
|
|
18266
18321
|
}
|
|
18267
18322
|
catch (error) {
|
|
18268
18323
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
|
|
18269
18324
|
}
|
|
18270
|
-
const user = await authManager.forceUserRefresh();
|
|
18271
|
-
if (!user?.zkEvm) {
|
|
18272
|
-
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
18273
|
-
}
|
|
18274
|
-
return user;
|
|
18275
18325
|
}
|
|
18276
18326
|
|
|
18277
18327
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
@@ -18333,7 +18383,7 @@ class GuardianClient {
|
|
|
18333
18383
|
const finallyFn = () => {
|
|
18334
18384
|
this.confirmationScreen.closeWindow();
|
|
18335
18385
|
};
|
|
18336
|
-
const user = await this.authManager.
|
|
18386
|
+
const user = await this.authManager.getUserImx();
|
|
18337
18387
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
18338
18388
|
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
18339
18389
|
transactionID: payloadHash,
|
|
@@ -18363,7 +18413,7 @@ class GuardianClient {
|
|
|
18363
18413
|
}
|
|
18364
18414
|
}
|
|
18365
18415
|
async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
|
|
18366
|
-
const user = await this.authManager.
|
|
18416
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18367
18417
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
18368
18418
|
const guardianTransactions = transformGuardianTransactions(metaTransactions);
|
|
18369
18419
|
try {
|
|
@@ -18397,7 +18447,7 @@ class GuardianClient {
|
|
|
18397
18447
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
18398
18448
|
}
|
|
18399
18449
|
if (confirmationRequired && !!transactionId) {
|
|
18400
|
-
const user = await this.authManager.
|
|
18450
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18401
18451
|
const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
|
|
18402
18452
|
if (!confirmationResult.confirmed) {
|
|
18403
18453
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
|
|
@@ -18409,7 +18459,7 @@ class GuardianClient {
|
|
|
18409
18459
|
}
|
|
18410
18460
|
async evaluateMessage({ chainID, payload }) {
|
|
18411
18461
|
try {
|
|
18412
|
-
const user = await this.authManager.
|
|
18462
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18413
18463
|
if (user === null) {
|
|
18414
18464
|
throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
18415
18465
|
}
|
|
@@ -18427,7 +18477,7 @@ class GuardianClient {
|
|
|
18427
18477
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
18428
18478
|
}
|
|
18429
18479
|
if (confirmationRequired && !!messageId) {
|
|
18430
|
-
const user = await this.authManager.
|
|
18480
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18431
18481
|
const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
|
|
18432
18482
|
if (!confirmationResult.confirmed) {
|
|
18433
18483
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
|
|
@@ -18644,7 +18694,7 @@ class ZkEvmProvider {
|
|
|
18644
18694
|
* @see #getSigner
|
|
18645
18695
|
*
|
|
18646
18696
|
*/
|
|
18647
|
-
|
|
18697
|
+
#initialiseEthSigner(user) {
|
|
18648
18698
|
const generateSigner = async () => {
|
|
18649
18699
|
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
18650
18700
|
const web3Provider = new providers.Web3Provider(magicRpcProvider);
|
|
@@ -18683,14 +18733,13 @@ class ZkEvmProvider {
|
|
|
18683
18733
|
this.#initialiseEthSigner(user);
|
|
18684
18734
|
if (!isZkEvmUser(user)) {
|
|
18685
18735
|
const ethSigner = await this.#getSigner();
|
|
18686
|
-
|
|
18736
|
+
this.#zkEvmAddress = await registerZkEvmUser({
|
|
18687
18737
|
ethSigner,
|
|
18688
18738
|
authManager: this.#authManager,
|
|
18689
18739
|
multiRollupApiClients: this.#multiRollupApiClients,
|
|
18690
18740
|
accessToken: user.accessToken,
|
|
18691
18741
|
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18692
18742
|
});
|
|
18693
|
-
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
18694
18743
|
}
|
|
18695
18744
|
else {
|
|
18696
18745
|
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
@@ -37808,7 +37857,7 @@ const flattenProperties = (properties) => {
|
|
|
37808
37857
|
};
|
|
37809
37858
|
|
|
37810
37859
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37811
|
-
const SDK_VERSION = '1.
|
|
37860
|
+
const SDK_VERSION = '1.13.0';
|
|
37812
37861
|
const getReferrer = () => {
|
|
37813
37862
|
if (isNode()) {
|
|
37814
37863
|
return '';
|
|
@@ -42984,7 +43033,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42984
43033
|
maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
|
|
42985
43034
|
};
|
|
42986
43035
|
|
|
42987
|
-
const SDK_VERSION_MARKER = '1.
|
|
43036
|
+
const SDK_VERSION_MARKER = '1.13.0';
|
|
42988
43037
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42989
43038
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42990
43039
|
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import globalAxios$1, { isAxiosError as isAxiosError$2, HttpStatusCode as HttpSt
|
|
|
2
2
|
import { memorise } from 'lru-memorise';
|
|
3
3
|
import { getGlobalisedValue as getGlobalisedValue$3 } from 'global-const';
|
|
4
4
|
import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, TransfersApi as TransfersApi$1, OrdersApi as OrdersApi$2, UsersApi as UsersApi$1, Contracts, TradesApi as TradesApi$1, ExchangesApi as ExchangesApi$1, WithdrawalsApi as WithdrawalsApi$1, MintsApi as MintsApi$1, DepositsApi as DepositsApi$1, EncodingApi as EncodingApi$1, TokensApi as TokensApi$2, IMXError } from '@imtbl/core-sdk';
|
|
5
|
-
import { UserManager, User, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
|
|
5
|
+
import { UserManager, User, ErrorTimeout, ErrorResponse, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
|
|
6
6
|
import jwt_decode from 'jwt-decode';
|
|
7
7
|
import * as crypto from 'crypto';
|
|
8
8
|
import { Magic } from 'magic-sdk';
|
|
@@ -152,7 +152,7 @@ const flattenProperties$1 = (properties) => {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
155
|
-
const SDK_VERSION$1 = '1.
|
|
155
|
+
const SDK_VERSION$1 = '1.13.0';
|
|
156
156
|
const getReferrer$1 = () => {
|
|
157
157
|
if (isNode$1()) {
|
|
158
158
|
return '';
|
|
@@ -11549,7 +11549,7 @@ class MultiRollupApiClients {
|
|
|
11549
11549
|
}
|
|
11550
11550
|
|
|
11551
11551
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11552
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.
|
|
11552
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.13.0' };
|
|
11553
11553
|
const createConfig = ({ basePath, headers, }) => {
|
|
11554
11554
|
if (!basePath.trim()) {
|
|
11555
11555
|
throw Error('basePath can not be empty');
|
|
@@ -11621,7 +11621,7 @@ class APIError extends Error {
|
|
|
11621
11621
|
|
|
11622
11622
|
/* eslint-disable implicit-arrow-linebreak */
|
|
11623
11623
|
const defaultHeaders = {
|
|
11624
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.
|
|
11624
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.13.0',
|
|
11625
11625
|
};
|
|
11626
11626
|
/**
|
|
11627
11627
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -12104,7 +12104,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
12104
12104
|
chainID,
|
|
12105
12105
|
coreContractAddress,
|
|
12106
12106
|
registrationContractAddress,
|
|
12107
|
-
sdkVersion: 'ts-immutable-sdk-1.
|
|
12107
|
+
sdkVersion: 'ts-immutable-sdk-1.13.0',
|
|
12108
12108
|
});
|
|
12109
12109
|
/**
|
|
12110
12110
|
* Sets `sdkVersion` at the time of build
|
|
@@ -16726,6 +16726,13 @@ function isTokenExpired(oidcUser) {
|
|
|
16726
16726
|
return isIdTokenExpired(idToken);
|
|
16727
16727
|
}
|
|
16728
16728
|
|
|
16729
|
+
var PassportEvents;
|
|
16730
|
+
(function (PassportEvents) {
|
|
16731
|
+
PassportEvents["LOGGED_OUT"] = "loggedOut";
|
|
16732
|
+
})(PassportEvents || (PassportEvents = {}));
|
|
16733
|
+
const isUserZkEvm = (user) => !!user.zkEvm;
|
|
16734
|
+
const isUserImx = (user) => !!user.imx;
|
|
16735
|
+
|
|
16729
16736
|
const formUrlEncodedHeader = {
|
|
16730
16737
|
headers: {
|
|
16731
16738
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -16777,8 +16784,8 @@ function sha256(buffer) {
|
|
|
16777
16784
|
}
|
|
16778
16785
|
class AuthManager {
|
|
16779
16786
|
userManager;
|
|
16780
|
-
config;
|
|
16781
16787
|
deviceCredentialsManager;
|
|
16788
|
+
config;
|
|
16782
16789
|
logoutMode;
|
|
16783
16790
|
/**
|
|
16784
16791
|
* Promise that is used to prevent multiple concurrent calls to the refresh token endpoint.
|
|
@@ -17008,6 +17015,12 @@ class AuthManager {
|
|
|
17008
17015
|
async logoutSilentCallback(url) {
|
|
17009
17016
|
return this.userManager.signoutSilentCallback(url);
|
|
17010
17017
|
}
|
|
17018
|
+
forceUserRefreshInBackground() {
|
|
17019
|
+
this.refreshTokenAndUpdatePromise().catch((error) => {
|
|
17020
|
+
// eslint-disable-next-line no-console
|
|
17021
|
+
console.warn('Failed to refresh user token', error);
|
|
17022
|
+
});
|
|
17023
|
+
}
|
|
17011
17024
|
async forceUserRefresh() {
|
|
17012
17025
|
return this.refreshTokenAndUpdatePromise();
|
|
17013
17026
|
}
|
|
@@ -17029,7 +17042,19 @@ class AuthManager {
|
|
|
17029
17042
|
resolve(null);
|
|
17030
17043
|
}
|
|
17031
17044
|
catch (err) {
|
|
17032
|
-
|
|
17045
|
+
let passportErrorType = PassportErrorType.AUTHENTICATION_ERROR;
|
|
17046
|
+
let errorMessage = 'Failed to refresh token';
|
|
17047
|
+
if (err instanceof ErrorTimeout) {
|
|
17048
|
+
passportErrorType = PassportErrorType.SILENT_LOGIN_ERROR;
|
|
17049
|
+
}
|
|
17050
|
+
else if (err instanceof ErrorResponse) {
|
|
17051
|
+
passportErrorType = PassportErrorType.NOT_LOGGED_IN_ERROR;
|
|
17052
|
+
errorMessage = `${err.message}: ${err.error_description}`;
|
|
17053
|
+
}
|
|
17054
|
+
else if (err instanceof Error) {
|
|
17055
|
+
errorMessage = err.message;
|
|
17056
|
+
}
|
|
17057
|
+
reject(new PassportError(errorMessage, passportErrorType));
|
|
17033
17058
|
}
|
|
17034
17059
|
finally {
|
|
17035
17060
|
this.refreshingPromise = null; // Reset the promise after completion
|
|
@@ -17038,22 +17063,56 @@ class AuthManager {
|
|
|
17038
17063
|
return this.refreshingPromise;
|
|
17039
17064
|
}
|
|
17040
17065
|
/**
|
|
17041
|
-
*
|
|
17042
|
-
*
|
|
17043
|
-
|
|
17044
|
-
|
|
17045
|
-
|
|
17046
|
-
|
|
17047
|
-
|
|
17048
|
-
|
|
17049
|
-
|
|
17050
|
-
|
|
17051
|
-
|
|
17052
|
-
|
|
17053
|
-
|
|
17066
|
+
*
|
|
17067
|
+
* @param typeAssertion {(user: User) => boolean} - Optional. If provided, then the User will be checked against
|
|
17068
|
+
* the typeAssertion. If the user meets the requirements, then it will be typed as T and returned. If the User
|
|
17069
|
+
* does NOT meet the type assertion, then execution will continue, and we will attempt to obtain a User that does
|
|
17070
|
+
* meet the type assertion.
|
|
17071
|
+
*
|
|
17072
|
+
* This function will attempt to obtain a User in the following order:
|
|
17073
|
+
* 1. If the User is currently refreshing, wait for the refresh to complete.
|
|
17074
|
+
* 2. Attempt to obtain a User from storage that has not expired.
|
|
17075
|
+
* 3. Attempt to refresh the User if a refresh token is present.
|
|
17076
|
+
* 4. Return null if no valid User can be obtained.
|
|
17077
|
+
*/
|
|
17078
|
+
async getUser(typeAssertion = (user) => true) {
|
|
17079
|
+
if (this.refreshingPromise) {
|
|
17080
|
+
const user = await this.refreshingPromise;
|
|
17081
|
+
if (user && typeAssertion(user)) {
|
|
17082
|
+
return user;
|
|
17054
17083
|
}
|
|
17055
17084
|
return null;
|
|
17056
|
-
}
|
|
17085
|
+
}
|
|
17086
|
+
const oidcUser = await this.userManager.getUser();
|
|
17087
|
+
if (!oidcUser)
|
|
17088
|
+
return null;
|
|
17089
|
+
if (!isTokenExpired(oidcUser)) {
|
|
17090
|
+
const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
17091
|
+
if (user && typeAssertion(user)) {
|
|
17092
|
+
return user;
|
|
17093
|
+
}
|
|
17094
|
+
}
|
|
17095
|
+
if (oidcUser.refresh_token) {
|
|
17096
|
+
const user = await this.refreshTokenAndUpdatePromise();
|
|
17097
|
+
if (user && typeAssertion(user)) {
|
|
17098
|
+
return user;
|
|
17099
|
+
}
|
|
17100
|
+
}
|
|
17101
|
+
return null;
|
|
17102
|
+
}
|
|
17103
|
+
async getUserZkEvm() {
|
|
17104
|
+
const user = await this.getUser(isUserZkEvm);
|
|
17105
|
+
if (!user) {
|
|
17106
|
+
throw new Error('Failed to obtain a User with the required ZkEvm attributes');
|
|
17107
|
+
}
|
|
17108
|
+
return user;
|
|
17109
|
+
}
|
|
17110
|
+
async getUserImx() {
|
|
17111
|
+
const user = await this.getUser(isUserImx);
|
|
17112
|
+
if (!user) {
|
|
17113
|
+
throw new Error('Failed to obtain a User with the required IMX attributes');
|
|
17114
|
+
}
|
|
17115
|
+
return user;
|
|
17057
17116
|
}
|
|
17058
17117
|
}
|
|
17059
17118
|
|
|
@@ -17122,11 +17181,6 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
|
|
|
17122
17181
|
return createStarkSigner(privateKey);
|
|
17123
17182
|
}, PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
17124
17183
|
|
|
17125
|
-
var PassportEvents;
|
|
17126
|
-
(function (PassportEvents) {
|
|
17127
|
-
PassportEvents["LOGGED_OUT"] = "loggedOut";
|
|
17128
|
-
})(PassportEvents || (PassportEvents = {}));
|
|
17129
|
-
|
|
17130
17184
|
async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
|
|
17131
17185
|
return withPassportError(async () => {
|
|
17132
17186
|
const { ethAddress } = user.imx;
|
|
@@ -17513,7 +17567,7 @@ class PassportImxProvider {
|
|
|
17513
17567
|
* @see getAuthenticatedUserAndSigners
|
|
17514
17568
|
*
|
|
17515
17569
|
*/
|
|
17516
|
-
|
|
17570
|
+
initialiseSigners() {
|
|
17517
17571
|
const generateSigners = async () => {
|
|
17518
17572
|
const user = await this.authManager.getUser();
|
|
17519
17573
|
// The user will be present because the factory validates it
|
|
@@ -17552,7 +17606,6 @@ class PassportImxProvider {
|
|
|
17552
17606
|
}
|
|
17553
17607
|
async getRegisteredImxUserAndSigners() {
|
|
17554
17608
|
const { user, starkSigner, ethSigner } = await this.getAuthenticatedUserAndSigners();
|
|
17555
|
-
const isUserImx = (oidcUser) => oidcUser?.imx !== undefined;
|
|
17556
17609
|
if (!isUserImx(user)) {
|
|
17557
17610
|
throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
|
|
17558
17611
|
}
|
|
@@ -18122,11 +18175,11 @@ class RelayerClient {
|
|
|
18122
18175
|
jsonrpc: '2.0',
|
|
18123
18176
|
...request,
|
|
18124
18177
|
};
|
|
18125
|
-
const user = await this.authManager.
|
|
18178
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18126
18179
|
const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
|
|
18127
18180
|
method: 'POST',
|
|
18128
18181
|
headers: {
|
|
18129
|
-
Authorization: `Bearer ${user
|
|
18182
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
18130
18183
|
'Content-Type': 'application/json',
|
|
18131
18184
|
},
|
|
18132
18185
|
body: JSON.stringify(body),
|
|
@@ -18232,7 +18285,7 @@ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients
|
|
|
18232
18285
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
|
|
18233
18286
|
}
|
|
18234
18287
|
try {
|
|
18235
|
-
await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
18288
|
+
const registrationResponse = await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
|
|
18236
18289
|
chainName,
|
|
18237
18290
|
createCounterfactualAddressRequest: {
|
|
18238
18291
|
ethereum_address: ethereumAddress,
|
|
@@ -18241,15 +18294,12 @@ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients
|
|
|
18241
18294
|
}, {
|
|
18242
18295
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
18243
18296
|
});
|
|
18297
|
+
authManager.forceUserRefreshInBackground();
|
|
18298
|
+
return registrationResponse.data.counterfactual_address;
|
|
18244
18299
|
}
|
|
18245
18300
|
catch (error) {
|
|
18246
18301
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
|
|
18247
18302
|
}
|
|
18248
|
-
const user = await authManager.forceUserRefresh();
|
|
18249
|
-
if (!user?.zkEvm) {
|
|
18250
|
-
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
18251
|
-
}
|
|
18252
|
-
return user;
|
|
18253
18303
|
}
|
|
18254
18304
|
|
|
18255
18305
|
const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
|
|
@@ -18311,7 +18361,7 @@ class GuardianClient {
|
|
|
18311
18361
|
const finallyFn = () => {
|
|
18312
18362
|
this.confirmationScreen.closeWindow();
|
|
18313
18363
|
};
|
|
18314
|
-
const user = await this.authManager.
|
|
18364
|
+
const user = await this.authManager.getUserImx();
|
|
18315
18365
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
18316
18366
|
const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
|
|
18317
18367
|
transactionID: payloadHash,
|
|
@@ -18341,7 +18391,7 @@ class GuardianClient {
|
|
|
18341
18391
|
}
|
|
18342
18392
|
}
|
|
18343
18393
|
async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
|
|
18344
|
-
const user = await this.authManager.
|
|
18394
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18345
18395
|
const headers = { Authorization: `Bearer ${user.accessToken}` };
|
|
18346
18396
|
const guardianTransactions = transformGuardianTransactions(metaTransactions);
|
|
18347
18397
|
try {
|
|
@@ -18375,7 +18425,7 @@ class GuardianClient {
|
|
|
18375
18425
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
18376
18426
|
}
|
|
18377
18427
|
if (confirmationRequired && !!transactionId) {
|
|
18378
|
-
const user = await this.authManager.
|
|
18428
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18379
18429
|
const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
|
|
18380
18430
|
if (!confirmationResult.confirmed) {
|
|
18381
18431
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
|
|
@@ -18387,7 +18437,7 @@ class GuardianClient {
|
|
|
18387
18437
|
}
|
|
18388
18438
|
async evaluateMessage({ chainID, payload }) {
|
|
18389
18439
|
try {
|
|
18390
|
-
const user = await this.authManager.
|
|
18440
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18391
18441
|
if (user === null) {
|
|
18392
18442
|
throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
18393
18443
|
}
|
|
@@ -18405,7 +18455,7 @@ class GuardianClient {
|
|
|
18405
18455
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
|
|
18406
18456
|
}
|
|
18407
18457
|
if (confirmationRequired && !!messageId) {
|
|
18408
|
-
const user = await this.authManager.
|
|
18458
|
+
const user = await this.authManager.getUserZkEvm();
|
|
18409
18459
|
const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
|
|
18410
18460
|
if (!confirmationResult.confirmed) {
|
|
18411
18461
|
throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
|
|
@@ -18622,7 +18672,7 @@ class ZkEvmProvider {
|
|
|
18622
18672
|
* @see #getSigner
|
|
18623
18673
|
*
|
|
18624
18674
|
*/
|
|
18625
|
-
|
|
18675
|
+
#initialiseEthSigner(user) {
|
|
18626
18676
|
const generateSigner = async () => {
|
|
18627
18677
|
const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
|
|
18628
18678
|
const web3Provider = new Web3Provider(magicRpcProvider);
|
|
@@ -18661,14 +18711,13 @@ class ZkEvmProvider {
|
|
|
18661
18711
|
this.#initialiseEthSigner(user);
|
|
18662
18712
|
if (!isZkEvmUser(user)) {
|
|
18663
18713
|
const ethSigner = await this.#getSigner();
|
|
18664
|
-
|
|
18714
|
+
this.#zkEvmAddress = await registerZkEvmUser({
|
|
18665
18715
|
ethSigner,
|
|
18666
18716
|
authManager: this.#authManager,
|
|
18667
18717
|
multiRollupApiClients: this.#multiRollupApiClients,
|
|
18668
18718
|
accessToken: user.accessToken,
|
|
18669
18719
|
jsonRpcProvider: this.#jsonRpcProvider,
|
|
18670
18720
|
});
|
|
18671
|
-
this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
|
|
18672
18721
|
}
|
|
18673
18722
|
else {
|
|
18674
18723
|
this.#zkEvmAddress = user.zkEvm.ethAddress;
|
|
@@ -37786,7 +37835,7 @@ const flattenProperties = (properties) => {
|
|
|
37786
37835
|
};
|
|
37787
37836
|
|
|
37788
37837
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
37789
|
-
const SDK_VERSION = '1.
|
|
37838
|
+
const SDK_VERSION = '1.13.0';
|
|
37790
37839
|
const getReferrer = () => {
|
|
37791
37840
|
if (isNode()) {
|
|
37792
37841
|
return '';
|
|
@@ -42962,7 +43011,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
42962
43011
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
42963
43012
|
};
|
|
42964
43013
|
|
|
42965
|
-
const SDK_VERSION_MARKER = '1.
|
|
43014
|
+
const SDK_VERSION_MARKER = '1.13.0';
|
|
42966
43015
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
42967
43016
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
42968
43017
|
|
package/dist/orderbook.js
CHANGED
|
@@ -131,7 +131,7 @@ const flattenProperties = (properties) => {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
|
|
134
|
-
const SDK_VERSION = '1.
|
|
134
|
+
const SDK_VERSION = '1.13.0';
|
|
135
135
|
const getReferrer = () => {
|
|
136
136
|
if (isNode()) {
|
|
137
137
|
return '';
|