@imtbl/sdk 0.33.0 → 0.34.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 +1 -1
- package/dist/browser/checkout/sdk.js +3 -3
- package/dist/browser/checkout/widgets.js +56 -56
- package/dist/checkout.d.ts +11 -18
- package/dist/checkout.js +26 -23
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +11 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +116 -216
- package/dist/index.d.ts +23 -11
- package/dist/index.js +117 -217
- package/dist/orderbook.d.ts +9 -1
- package/dist/orderbook.js +3 -1
- package/dist/passport.d.ts +10 -10
- package/dist/passport.js +91 -194
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3791,7 +3791,7 @@ class MultiRollupApiClients {
|
|
|
3791
3791
|
}
|
|
3792
3792
|
|
|
3793
3793
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3794
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
3794
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.34.0' };
|
|
3795
3795
|
const createConfig = ({ basePath, headers, }) => {
|
|
3796
3796
|
if (!basePath.trim()) {
|
|
3797
3797
|
throw Error('basePath can not be empty');
|
|
@@ -3851,7 +3851,7 @@ class APIError extends Error {
|
|
|
3851
3851
|
|
|
3852
3852
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3853
3853
|
const defaultHeaders = {
|
|
3854
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
3854
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.34.0',
|
|
3855
3855
|
};
|
|
3856
3856
|
/**
|
|
3857
3857
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4262,7 +4262,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4262
4262
|
chainID,
|
|
4263
4263
|
coreContractAddress,
|
|
4264
4264
|
registrationContractAddress,
|
|
4265
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
4265
|
+
sdkVersion: 'ts-immutable-sdk-0.34.0',
|
|
4266
4266
|
});
|
|
4267
4267
|
/**
|
|
4268
4268
|
* Sets `sdkVersion` at the time of build
|
|
@@ -8812,26 +8812,10 @@ var ChainName$1;
|
|
|
8812
8812
|
ChainName["IMTBL_ZKEVM_MAINNET"] = "Immutable zkEVM";
|
|
8813
8813
|
})(ChainName$1 || (ChainName$1 = {}));
|
|
8814
8814
|
|
|
8815
|
-
const keyCrendentials = 'passport_credentials';
|
|
8816
8815
|
const KEY_PKCE_STATE = 'pkce_state';
|
|
8817
8816
|
const KEY_PKCE_VERIFIER = 'pkce_verifier';
|
|
8818
8817
|
const validCredentialsMinTtlSec = 3600; // 1 hour
|
|
8819
8818
|
class DeviceCredentialsManager {
|
|
8820
|
-
saveCredentials(tokenResponse) {
|
|
8821
|
-
if (this.areValid(tokenResponse)) {
|
|
8822
|
-
localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
|
|
8823
|
-
}
|
|
8824
|
-
else {
|
|
8825
|
-
throw Error('Invalid credentials.');
|
|
8826
|
-
}
|
|
8827
|
-
}
|
|
8828
|
-
getCredentials() {
|
|
8829
|
-
const credentialsJson = localStorage.getItem(keyCrendentials);
|
|
8830
|
-
if (credentialsJson) {
|
|
8831
|
-
return JSON.parse(credentialsJson);
|
|
8832
|
-
}
|
|
8833
|
-
return null;
|
|
8834
|
-
}
|
|
8835
8819
|
areValid(tokenResponse) {
|
|
8836
8820
|
if (tokenResponse) {
|
|
8837
8821
|
const accessTokenValid = this.isTokenValid(tokenResponse.access_token);
|
|
@@ -8851,9 +8835,6 @@ class DeviceCredentialsManager {
|
|
|
8851
8835
|
return false;
|
|
8852
8836
|
}
|
|
8853
8837
|
}
|
|
8854
|
-
clearCredentials() {
|
|
8855
|
-
localStorage.removeItem(keyCrendentials);
|
|
8856
|
-
}
|
|
8857
8838
|
savePKCEData(data) {
|
|
8858
8839
|
localStorage.setItem(KEY_PKCE_STATE, data.state);
|
|
8859
8840
|
localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
|
|
@@ -8889,9 +8870,14 @@ const formUrlEncodedHeader = {
|
|
|
8889
8870
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
8890
8871
|
},
|
|
8891
8872
|
};
|
|
8892
|
-
const getAuthConfiguration = (
|
|
8873
|
+
const getAuthConfiguration = (config) => {
|
|
8874
|
+
const { authenticationDomain, oidcConfiguration } = config;
|
|
8893
8875
|
const store = typeof window !== 'undefined' ? window.localStorage : new oidcClientTs.InMemoryWebStorage();
|
|
8894
8876
|
const userStore = new oidcClientTs.WebStorageStateStore({ store });
|
|
8877
|
+
let endSessionEndpoint = `${authenticationDomain}/v2/logout?client_id=${oidcConfiguration.clientId}`;
|
|
8878
|
+
if (oidcConfiguration.logoutRedirectUri) {
|
|
8879
|
+
endSessionEndpoint += `&returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`;
|
|
8880
|
+
}
|
|
8895
8881
|
const baseConfiguration = {
|
|
8896
8882
|
authority: authenticationDomain,
|
|
8897
8883
|
redirect_uri: oidcConfiguration.redirectUri,
|
|
@@ -8901,9 +8887,7 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
|
|
|
8901
8887
|
authorization_endpoint: `${authenticationDomain}/authorize`,
|
|
8902
8888
|
token_endpoint: `${authenticationDomain}/oauth/token`,
|
|
8903
8889
|
userinfo_endpoint: `${authenticationDomain}/userinfo`,
|
|
8904
|
-
end_session_endpoint:
|
|
8905
|
-
+ `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`
|
|
8906
|
-
+ `&client_id=${oidcConfiguration.clientId}`,
|
|
8890
|
+
end_session_endpoint: endSessionEndpoint,
|
|
8907
8891
|
},
|
|
8908
8892
|
mergeClaims: true,
|
|
8909
8893
|
loadUserInfo: true,
|
|
@@ -8922,6 +8906,15 @@ function wait$1(ms) {
|
|
|
8922
8906
|
setTimeout(resolve, ms);
|
|
8923
8907
|
});
|
|
8924
8908
|
}
|
|
8909
|
+
function base64URLEncode(str) {
|
|
8910
|
+
return str.toString('base64')
|
|
8911
|
+
.replace(/\+/g, '-')
|
|
8912
|
+
.replace(/\//g, '_')
|
|
8913
|
+
.replace(/=/g, '');
|
|
8914
|
+
}
|
|
8915
|
+
function sha256(buffer) {
|
|
8916
|
+
return crypto__namespace.createHash('sha256').update(buffer).digest();
|
|
8917
|
+
}
|
|
8925
8918
|
class AuthManager {
|
|
8926
8919
|
userManager;
|
|
8927
8920
|
config;
|
|
@@ -8965,32 +8958,24 @@ class AuthManager {
|
|
|
8965
8958
|
}
|
|
8966
8959
|
return user;
|
|
8967
8960
|
};
|
|
8968
|
-
static
|
|
8961
|
+
static mapDeviceTokenResponseToOidcUser = (tokenResponse) => {
|
|
8969
8962
|
const idTokenPayload = jwt_decode(tokenResponse.id_token);
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8963
|
+
return new oidcClientTs.User({
|
|
8964
|
+
id_token: tokenResponse.id_token,
|
|
8965
|
+
access_token: tokenResponse.access_token,
|
|
8966
|
+
refresh_token: tokenResponse.refresh_token,
|
|
8967
|
+
token_type: tokenResponse.token_type,
|
|
8974
8968
|
profile: {
|
|
8975
8969
|
sub: idTokenPayload.sub,
|
|
8970
|
+
iss: idTokenPayload.iss,
|
|
8971
|
+
aud: idTokenPayload.aud,
|
|
8972
|
+
exp: idTokenPayload.exp,
|
|
8973
|
+
iat: idTokenPayload.iat,
|
|
8976
8974
|
email: idTokenPayload.email,
|
|
8977
8975
|
nickname: idTokenPayload.nickname,
|
|
8976
|
+
passport: idTokenPayload.passport,
|
|
8978
8977
|
},
|
|
8979
|
-
};
|
|
8980
|
-
if (idTokenPayload?.passport?.imx_eth_address) {
|
|
8981
|
-
user.imx = {
|
|
8982
|
-
ethAddress: idTokenPayload.passport.imx_eth_address,
|
|
8983
|
-
starkAddress: idTokenPayload.passport.imx_stark_address,
|
|
8984
|
-
userAdminAddress: idTokenPayload.passport.imx_user_admin_address,
|
|
8985
|
-
};
|
|
8986
|
-
}
|
|
8987
|
-
if (idTokenPayload?.passport?.zkevm_eth_address) {
|
|
8988
|
-
user.zkEvm = {
|
|
8989
|
-
ethAddress: idTokenPayload?.passport?.zkevm_eth_address,
|
|
8990
|
-
userAdminAddress: idTokenPayload?.passport?.zkevm_user_admin_address,
|
|
8991
|
-
};
|
|
8992
|
-
}
|
|
8993
|
-
return user;
|
|
8978
|
+
});
|
|
8994
8979
|
};
|
|
8995
8980
|
async login() {
|
|
8996
8981
|
return withPassportError(async () => {
|
|
@@ -9020,7 +9005,7 @@ class AuthManager {
|
|
|
9020
9005
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
9021
9006
|
}
|
|
9022
9007
|
/* eslint-disable no-await-in-loop */
|
|
9023
|
-
async
|
|
9008
|
+
async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
|
|
9024
9009
|
return withPassportError(async () => {
|
|
9025
9010
|
const startTime = Date.now();
|
|
9026
9011
|
const loopCondition = true;
|
|
@@ -9031,8 +9016,9 @@ class AuthManager {
|
|
|
9031
9016
|
await wait$1(interval * 1000);
|
|
9032
9017
|
try {
|
|
9033
9018
|
const tokenResponse = await this.getDeviceFlowToken(deviceCode);
|
|
9034
|
-
const
|
|
9035
|
-
|
|
9019
|
+
const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
|
|
9020
|
+
const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
9021
|
+
await this.userManager.storeUser(oidcUser);
|
|
9036
9022
|
return user;
|
|
9037
9023
|
}
|
|
9038
9024
|
catch (error) {
|
|
@@ -9068,20 +9054,11 @@ class AuthManager {
|
|
|
9068
9054
|
}, formUrlEncodedHeader);
|
|
9069
9055
|
return response.data;
|
|
9070
9056
|
}
|
|
9071
|
-
static base64URLEncode(str) {
|
|
9072
|
-
return str.toString('base64')
|
|
9073
|
-
.replace(/\+/g, '-')
|
|
9074
|
-
.replace(/\//g, '_')
|
|
9075
|
-
.replace(/=/g, '');
|
|
9076
|
-
}
|
|
9077
|
-
static sha256(buffer) {
|
|
9078
|
-
return crypto__namespace.createHash('sha256').update(buffer).digest();
|
|
9079
|
-
}
|
|
9080
9057
|
getPKCEAuthorizationUrl() {
|
|
9081
|
-
const verifier =
|
|
9082
|
-
const challenge =
|
|
9058
|
+
const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
9059
|
+
const challenge = base64URLEncode(sha256(verifier));
|
|
9083
9060
|
// https://auth0.com/docs/secure/attack-protection/state-parameters
|
|
9084
|
-
const state =
|
|
9061
|
+
const state = base64URLEncode(crypto__namespace.randomBytes(32));
|
|
9085
9062
|
this.deviceCredentialsManager.savePKCEData({ state, verifier });
|
|
9086
9063
|
return `${this.config.authenticationDomain}/authorize?`
|
|
9087
9064
|
+ 'response_type=code'
|
|
@@ -9103,8 +9080,9 @@ class AuthManager {
|
|
|
9103
9080
|
throw new Error('Provided state does not match stored state');
|
|
9104
9081
|
}
|
|
9105
9082
|
const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
|
|
9106
|
-
const
|
|
9107
|
-
|
|
9083
|
+
const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
|
|
9084
|
+
const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
9085
|
+
await this.userManager.storeUser(oidcUser);
|
|
9108
9086
|
return user;
|
|
9109
9087
|
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
9110
9088
|
}
|
|
@@ -9118,31 +9096,6 @@ class AuthManager {
|
|
|
9118
9096
|
}, formUrlEncodedHeader);
|
|
9119
9097
|
return response.data;
|
|
9120
9098
|
}
|
|
9121
|
-
async connectImxWithCredentials(tokenResponse) {
|
|
9122
|
-
return withPassportError(async () => {
|
|
9123
|
-
if (this.deviceCredentialsManager.areValid(tokenResponse)) {
|
|
9124
|
-
// Credentials exist and are still valid
|
|
9125
|
-
return AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
|
|
9126
|
-
}
|
|
9127
|
-
const refreshToken = tokenResponse?.refresh_token ?? null;
|
|
9128
|
-
if (refreshToken) {
|
|
9129
|
-
// Token is no longer valid, but refresh token can be used to a new one
|
|
9130
|
-
const user = await this.refreshToken(refreshToken);
|
|
9131
|
-
return user;
|
|
9132
|
-
}
|
|
9133
|
-
return null;
|
|
9134
|
-
}, PassportErrorType.AUTHENTICATION_ERROR);
|
|
9135
|
-
}
|
|
9136
|
-
async refreshToken(refreshToken) {
|
|
9137
|
-
const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
|
|
9138
|
-
client_id: this.config.oidcConfiguration.clientId,
|
|
9139
|
-
grant_type: 'refresh_token',
|
|
9140
|
-
refresh_token: refreshToken,
|
|
9141
|
-
}, formUrlEncodedHeader);
|
|
9142
|
-
const newTokenResponse = response.data;
|
|
9143
|
-
this.deviceCredentialsManager.saveCredentials(newTokenResponse);
|
|
9144
|
-
return AuthManager.mapDeviceTokenResponseToDomainUserModel(newTokenResponse);
|
|
9145
|
-
}
|
|
9146
9099
|
async logout() {
|
|
9147
9100
|
return withPassportError(async () => {
|
|
9148
9101
|
if (this.logoutMode === 'silent') {
|
|
@@ -9151,29 +9104,20 @@ class AuthManager {
|
|
|
9151
9104
|
return this.userManager.signoutRedirect();
|
|
9152
9105
|
}, PassportErrorType.LOGOUT_ERROR);
|
|
9153
9106
|
}
|
|
9154
|
-
async
|
|
9155
|
-
return this.userManager.
|
|
9156
|
-
}
|
|
9157
|
-
async logoutDeviceFlow() {
|
|
9158
|
-
return withPassportError(async () => {
|
|
9159
|
-
this.deviceCredentialsManager.clearCredentials();
|
|
9160
|
-
}, PassportErrorType.LOGOUT_ERROR);
|
|
9107
|
+
async removeUser() {
|
|
9108
|
+
return this.userManager.removeUser();
|
|
9161
9109
|
}
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
if (!oidcUser)
|
|
9169
|
-
return null;
|
|
9170
|
-
if (!isTokenExpired(oidcUser)) {
|
|
9171
|
-
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
9110
|
+
getDeviceFlowEndSessionEndpoint() {
|
|
9111
|
+
const { authenticationDomain, oidcConfiguration } = this.config;
|
|
9112
|
+
let endSessionEndpoint = `${authenticationDomain}/v2/logout`;
|
|
9113
|
+
if (oidcConfiguration.logoutRedirectUri) {
|
|
9114
|
+
endSessionEndpoint += `?client_id=${oidcConfiguration.clientId}`
|
|
9115
|
+
+ `&returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`;
|
|
9172
9116
|
}
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
return
|
|
9117
|
+
return endSessionEndpoint;
|
|
9118
|
+
}
|
|
9119
|
+
async logoutSilentCallback(url) {
|
|
9120
|
+
return this.userManager.signoutSilentCallback(url);
|
|
9177
9121
|
}
|
|
9178
9122
|
async forceUserRefresh() {
|
|
9179
9123
|
return this.refreshTokenAndUpdatePromise();
|
|
@@ -9188,25 +9132,10 @@ class AuthManager {
|
|
|
9188
9132
|
// eslint-disable-next-line no-async-promise-executor
|
|
9189
9133
|
this.refreshingPromise = new Promise(async (resolve, reject) => {
|
|
9190
9134
|
try {
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
if (refreshToken) {
|
|
9196
|
-
const newUser = await this.refreshToken(refreshToken);
|
|
9197
|
-
if (newUser) {
|
|
9198
|
-
resolve(newUser);
|
|
9199
|
-
return;
|
|
9200
|
-
}
|
|
9201
|
-
}
|
|
9202
|
-
}
|
|
9203
|
-
}
|
|
9204
|
-
else {
|
|
9205
|
-
const newOidcUser = await this.userManager.signinSilent();
|
|
9206
|
-
if (newOidcUser) {
|
|
9207
|
-
resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
|
|
9208
|
-
return;
|
|
9209
|
-
}
|
|
9135
|
+
const newOidcUser = await this.userManager.signinSilent();
|
|
9136
|
+
if (newOidcUser) {
|
|
9137
|
+
resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
|
|
9138
|
+
return;
|
|
9210
9139
|
}
|
|
9211
9140
|
resolve(null);
|
|
9212
9141
|
}
|
|
@@ -9219,30 +9148,24 @@ class AuthManager {
|
|
|
9219
9148
|
});
|
|
9220
9149
|
return this.refreshingPromise;
|
|
9221
9150
|
}
|
|
9151
|
+
/**
|
|
9152
|
+
* Get the user from the cache or refresh the token if it's expired.
|
|
9153
|
+
* return null if there's no refresh token.
|
|
9154
|
+
*/
|
|
9222
9155
|
async getUser() {
|
|
9223
9156
|
return withPassportError(async () => {
|
|
9224
|
-
const
|
|
9225
|
-
if (
|
|
9226
|
-
return
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
|
|
9157
|
+
const oidcUser = await this.userManager.getUser();
|
|
9158
|
+
if (!oidcUser)
|
|
9159
|
+
return null;
|
|
9160
|
+
if (!isTokenExpired(oidcUser)) {
|
|
9161
|
+
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
9230
9162
|
}
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
}
|
|
9234
|
-
async getUserDeviceFlow() {
|
|
9235
|
-
return withPassportError(async () => {
|
|
9236
|
-
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
9237
|
-
if (deviceToken) {
|
|
9238
|
-
return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
|
|
9163
|
+
if (oidcUser.refresh_token) {
|
|
9164
|
+
return this.refreshTokenAndUpdatePromise();
|
|
9239
9165
|
}
|
|
9240
9166
|
return null;
|
|
9241
9167
|
}, PassportErrorType.NOT_LOGGED_IN_ERROR);
|
|
9242
9168
|
}
|
|
9243
|
-
checkStoredDeviceFlowCredentials() {
|
|
9244
|
-
return this.deviceCredentialsManager.getCredentials();
|
|
9245
|
-
}
|
|
9246
9169
|
}
|
|
9247
9170
|
|
|
9248
9171
|
const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
|
|
@@ -10077,21 +10000,10 @@ class PassportImxProviderFactory {
|
|
|
10077
10000
|
}
|
|
10078
10001
|
return this.createProviderInstance(user);
|
|
10079
10002
|
}
|
|
10080
|
-
async getProviderWithDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
10081
|
-
const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
|
|
10082
|
-
return this.createProviderInstance(user);
|
|
10083
|
-
}
|
|
10084
10003
|
async getProviderWithPKCEFlow(authorizationCode, state) {
|
|
10085
10004
|
const user = await this.authManager.connectImxPKCEFlow(authorizationCode, state);
|
|
10086
10005
|
return this.createProviderInstance(user);
|
|
10087
10006
|
}
|
|
10088
|
-
async getProviderWithCredentials(tokenResponse) {
|
|
10089
|
-
const user = await this.authManager.connectImxWithCredentials(tokenResponse);
|
|
10090
|
-
if (!user) {
|
|
10091
|
-
return null;
|
|
10092
|
-
}
|
|
10093
|
-
return this.createProviderInstance(user);
|
|
10094
|
-
}
|
|
10095
10007
|
async createProviderInstance(user) {
|
|
10096
10008
|
if (!user.idToken) {
|
|
10097
10009
|
throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
|
|
@@ -10135,7 +10047,6 @@ class PassportConfiguration {
|
|
|
10135
10047
|
constructor({ baseConfig, overrides, crossSdkBridgeEnabled, ...oidcConfiguration }) {
|
|
10136
10048
|
validateConfiguration(oidcConfiguration, [
|
|
10137
10049
|
'clientId',
|
|
10138
|
-
'logoutRedirectUri',
|
|
10139
10050
|
'redirectUri',
|
|
10140
10051
|
]);
|
|
10141
10052
|
this.oidcConfiguration = oidcConfiguration;
|
|
@@ -10610,7 +10521,7 @@ const CHAIN_NAME_MAP = new Map([
|
|
|
10610
10521
|
]);
|
|
10611
10522
|
|
|
10612
10523
|
const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
|
|
10613
|
-
async function registerZkEvmUser({ authManager,
|
|
10524
|
+
async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
|
|
10614
10525
|
const web3Provider = new providers.Web3Provider(magicProvider);
|
|
10615
10526
|
const ethSigner = web3Provider.getSigner();
|
|
10616
10527
|
const ethereumAddress = await ethSigner.getAddress();
|
|
@@ -10633,24 +10544,14 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
|
|
|
10633
10544
|
catch (error) {
|
|
10634
10545
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
|
|
10635
10546
|
}
|
|
10636
|
-
|
|
10637
|
-
if (config.crossSdkBridgeEnabled) {
|
|
10638
|
-
const credentials = authManager.checkStoredDeviceFlowCredentials();
|
|
10639
|
-
if (!credentials || !credentials.refresh_token) {
|
|
10640
|
-
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Cross SDK bridge: Failed to refresh user details');
|
|
10641
|
-
}
|
|
10642
|
-
user = await authManager.refreshToken(credentials.refresh_token);
|
|
10643
|
-
}
|
|
10644
|
-
else {
|
|
10645
|
-
user = await authManager.forceUserRefresh();
|
|
10646
|
-
}
|
|
10547
|
+
const user = await authManager.forceUserRefresh();
|
|
10647
10548
|
if (!user?.zkEvm) {
|
|
10648
10549
|
throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
|
|
10649
10550
|
}
|
|
10650
10551
|
return user;
|
|
10651
10552
|
}
|
|
10652
10553
|
|
|
10653
|
-
const loginZkEvmUser = async ({ authManager,
|
|
10554
|
+
const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
|
|
10654
10555
|
let user = null;
|
|
10655
10556
|
try {
|
|
10656
10557
|
user = await authManager.getUser();
|
|
@@ -10660,7 +10561,7 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
|
|
|
10660
10561
|
console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
|
|
10661
10562
|
}
|
|
10662
10563
|
if (!user) {
|
|
10663
|
-
user = await authManager.
|
|
10564
|
+
user = await authManager.login();
|
|
10664
10565
|
}
|
|
10665
10566
|
if (!user.idToken) {
|
|
10666
10567
|
throw new Error('User is missing idToken');
|
|
@@ -10670,7 +10571,6 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
|
|
|
10670
10571
|
// Generate counterfactual address and retrieve updated Auth0 user
|
|
10671
10572
|
const userZkevm = await registerZkEvmUser({
|
|
10672
10573
|
authManager,
|
|
10673
|
-
config,
|
|
10674
10574
|
magicProvider,
|
|
10675
10575
|
multiRollupApiClients,
|
|
10676
10576
|
accessToken: user.accessToken,
|
|
@@ -11094,24 +10994,12 @@ class Passport {
|
|
|
11094
10994
|
async connectImx() {
|
|
11095
10995
|
return this.passportImxProviderFactory.getProvider();
|
|
11096
10996
|
}
|
|
11097
|
-
async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
|
|
11098
|
-
return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
|
|
11099
|
-
}
|
|
11100
10997
|
getPKCEAuthorizationUrl() {
|
|
11101
10998
|
return this.authManager.getPKCEAuthorizationUrl();
|
|
11102
10999
|
}
|
|
11103
11000
|
async connectImxPKCEFlow(authorizationCode, state) {
|
|
11104
11001
|
return this.passportImxProviderFactory.getProviderWithPKCEFlow(authorizationCode, state);
|
|
11105
11002
|
}
|
|
11106
|
-
/**
|
|
11107
|
-
* @returns {boolean} the stored device flow credentials if they exist
|
|
11108
|
-
*/
|
|
11109
|
-
checkStoredDeviceFlowCredentials() {
|
|
11110
|
-
return this.authManager.checkStoredDeviceFlowCredentials();
|
|
11111
|
-
}
|
|
11112
|
-
async connectImxWithCredentials(tokenResponse) {
|
|
11113
|
-
return this.passportImxProviderFactory.getProviderWithCredentials(tokenResponse);
|
|
11114
|
-
}
|
|
11115
11003
|
connectEvm() {
|
|
11116
11004
|
if (this.config.network === Networks.PRODUCTION) {
|
|
11117
11005
|
throw new Error('EVM is not supported on production network');
|
|
@@ -11151,19 +11039,35 @@ class Passport {
|
|
|
11151
11039
|
}
|
|
11152
11040
|
return user ? user.profile : null;
|
|
11153
11041
|
}
|
|
11042
|
+
async loginCallback() {
|
|
11043
|
+
return this.authManager.loginCallback();
|
|
11044
|
+
}
|
|
11154
11045
|
async loginWithDeviceFlow() {
|
|
11155
11046
|
return this.authManager.loginWithDeviceFlow();
|
|
11156
11047
|
}
|
|
11157
|
-
async
|
|
11158
|
-
|
|
11048
|
+
async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
|
|
11049
|
+
const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
|
|
11050
|
+
return user.profile;
|
|
11159
11051
|
}
|
|
11160
11052
|
async logout() {
|
|
11161
|
-
await this.authManager.logout();
|
|
11162
11053
|
await this.confirmationScreen.logout();
|
|
11054
|
+
await this.authManager.logout();
|
|
11163
11055
|
// Code after this point is only executed if the logout mode is silent
|
|
11164
11056
|
await this.magicAdapter.logout();
|
|
11165
11057
|
this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
|
|
11166
11058
|
}
|
|
11059
|
+
/**
|
|
11060
|
+
* Logs the user out of Passport when using device flow authentication.
|
|
11061
|
+
*
|
|
11062
|
+
* @returns {Promise<string>} The device flow end session endpoint. Consumers are responsible for
|
|
11063
|
+
* opening this URL in the same browser that was used to log the user in.
|
|
11064
|
+
*/
|
|
11065
|
+
async logoutDeviceFlow() {
|
|
11066
|
+
await this.authManager.removeUser();
|
|
11067
|
+
await this.magicAdapter.logout();
|
|
11068
|
+
this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
|
|
11069
|
+
return this.authManager.getDeviceFlowEndSessionEndpoint();
|
|
11070
|
+
}
|
|
11167
11071
|
/**
|
|
11168
11072
|
* This method should only be called from the logout redirect uri
|
|
11169
11073
|
* when logout mode is 'silent'.
|
|
@@ -11171,17 +11075,10 @@ class Passport {
|
|
|
11171
11075
|
async logoutSilentCallback(url) {
|
|
11172
11076
|
return this.authManager.logoutSilentCallback(url);
|
|
11173
11077
|
}
|
|
11174
|
-
async logoutDeviceFlow() {
|
|
11175
|
-
return this.authManager.logoutDeviceFlow();
|
|
11176
|
-
}
|
|
11177
11078
|
async getUserInfo() {
|
|
11178
11079
|
const user = await this.authManager.getUser();
|
|
11179
11080
|
return user?.profile;
|
|
11180
11081
|
}
|
|
11181
|
-
async getUserInfoDeviceFlow() {
|
|
11182
|
-
const user = await this.authManager.getUserDeviceFlow();
|
|
11183
|
-
return user?.profile;
|
|
11184
|
-
}
|
|
11185
11082
|
async getIdToken() {
|
|
11186
11083
|
const user = await this.authManager.getUser();
|
|
11187
11084
|
return user?.idToken;
|
|
@@ -11635,7 +11532,7 @@ class OrdersService {
|
|
|
11635
11532
|
* @returns ListListingsResult OK response.
|
|
11636
11533
|
* @throws ApiError
|
|
11637
11534
|
*/
|
|
11638
|
-
listListings({ chainName, status, sellItemContractAddress, buyItemContractAddress, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, }) {
|
|
11535
|
+
listListings({ chainName, status, sellItemContractAddress, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, }) {
|
|
11639
11536
|
return this.httpRequest.request({
|
|
11640
11537
|
method: 'GET',
|
|
11641
11538
|
url: '/v1/chains/{chain_name}/orders/listings',
|
|
@@ -11646,6 +11543,8 @@ class OrdersService {
|
|
|
11646
11543
|
'status': status,
|
|
11647
11544
|
'sell_item_contract_address': sellItemContractAddress,
|
|
11648
11545
|
'buy_item_contract_address': buyItemContractAddress,
|
|
11546
|
+
'account_address': accountAddress,
|
|
11547
|
+
'sell_item_metadata_id': sellItemMetadataId,
|
|
11649
11548
|
'sell_item_token_id': sellItemTokenId,
|
|
11650
11549
|
'from_updated_at': fromUpdatedAt,
|
|
11651
11550
|
'page_size': pageSize,
|
|
@@ -28572,6 +28471,21 @@ const getCallData = (methodName, contractInterface) => {
|
|
|
28572
28471
|
return fragment ? contractInterface?.encodeFunctionData(fragment) : undefined;
|
|
28573
28472
|
};
|
|
28574
28473
|
|
|
28474
|
+
// 0.1% default slippage
|
|
28475
|
+
const DEFAULT_SLIPPAGE = 0.1;
|
|
28476
|
+
// 15 minutes from the time the transaction was prepared
|
|
28477
|
+
const DEFAULT_DEADLINE_SECONDS = 60 * 15;
|
|
28478
|
+
// most swaps will be able to resolve with 2 hops
|
|
28479
|
+
const DEFAULT_MAX_HOPS = 2;
|
|
28480
|
+
// after 10 hops, it is very unlikely a route will be available
|
|
28481
|
+
const MAX_MAX_HOPS = 10;
|
|
28482
|
+
// a max hop of 1 will require a direct swap with no intermediary pools
|
|
28483
|
+
const MIN_MAX_HOPS = 1;
|
|
28484
|
+
// precision used to calculate percentage from basis points
|
|
28485
|
+
const BASIS_POINT_PRECISION = 10000;
|
|
28486
|
+
// 10% maximum secondary fee
|
|
28487
|
+
const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;
|
|
28488
|
+
|
|
28575
28489
|
const quoteReturnMapping = {
|
|
28576
28490
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28577
28491
|
'0xcdca1753': ['uint256', 'uint160[]', 'uint32[]', 'uint256'],
|
|
@@ -28706,6 +28620,7 @@ const toPublicAmount = (amount) => ({
|
|
|
28706
28620
|
token: toPublicTokenType(amount.token),
|
|
28707
28621
|
value: amount.value,
|
|
28708
28622
|
});
|
|
28623
|
+
const getDefaultDeadlineSeconds = () => Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS;
|
|
28709
28624
|
|
|
28710
28625
|
const amountIndex = 0;
|
|
28711
28626
|
const gasEstimateIndex = 3;
|
|
@@ -29204,21 +29119,6 @@ fees, tradeType, nativeTokenService) {
|
|
|
29204
29119
|
return nativeTokenService.maybeWrapAmount(fees.amountLessFees());
|
|
29205
29120
|
}
|
|
29206
29121
|
|
|
29207
|
-
// 0.1% default slippage
|
|
29208
|
-
const DEFAULT_SLIPPAGE = 0.1;
|
|
29209
|
-
// 15 minutes from the current Unix time
|
|
29210
|
-
const DEFAULT_DEADLINE = Math.floor(Date.now() / 1000) + 60 * 15;
|
|
29211
|
-
// most swaps will be able to resolve with 2 hops
|
|
29212
|
-
const DEFAULT_MAX_HOPS = 2;
|
|
29213
|
-
// after 10 hops, it is very unlikely a route will be available
|
|
29214
|
-
const MAX_MAX_HOPS = 10;
|
|
29215
|
-
// a max hop of 1 will require a direct swap with no intermediary pools
|
|
29216
|
-
const MIN_MAX_HOPS = 1;
|
|
29217
|
-
// precision used to calculate percentage from basis points
|
|
29218
|
-
const BASIS_POINT_PRECISION = 10000;
|
|
29219
|
-
// 10% maximum secondary fee
|
|
29220
|
-
const MAX_SECONDARY_FEE_BASIS_POINTS = 1000;
|
|
29221
|
-
|
|
29222
29122
|
class Fees {
|
|
29223
29123
|
secondaryFees;
|
|
29224
29124
|
amount;
|
|
@@ -29763,7 +29663,7 @@ class Exchange {
|
|
|
29763
29663
|
* @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes
|
|
29764
29664
|
* @return {TransactionResponse} The result containing the unsigned transaction and details of the swap
|
|
29765
29665
|
*/
|
|
29766
|
-
async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline =
|
|
29666
|
+
async getUnsignedSwapTxFromAmountIn(fromAddress, tokenInAddress, tokenOutAddress, amountIn, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = getDefaultDeadlineSeconds()) {
|
|
29767
29667
|
return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountIn), slippagePercent, maxHops, deadline, Uniswap.TradeType.EXACT_INPUT);
|
|
29768
29668
|
}
|
|
29769
29669
|
/**
|
|
@@ -29779,7 +29679,7 @@ class Exchange {
|
|
|
29779
29679
|
* @param {number} deadline (optional) Latest time swap can execute. Default is 15 minutes
|
|
29780
29680
|
* @return {TransactionResponse} The result containing the unsigned transaction and details of the swap
|
|
29781
29681
|
*/
|
|
29782
|
-
async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline =
|
|
29682
|
+
async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = getDefaultDeadlineSeconds()) {
|
|
29783
29683
|
return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, ethers.ethers.BigNumber.from(amountOut), slippagePercent, maxHops, deadline, Uniswap.TradeType.EXACT_OUTPUT);
|
|
29784
29684
|
}
|
|
29785
29685
|
}
|
|
@@ -30672,7 +30572,7 @@ const GAS_OVERRIDES = {
|
|
|
30672
30572
|
maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
|
|
30673
30573
|
};
|
|
30674
30574
|
|
|
30675
|
-
const SDK_VERSION_MARKER = '0.
|
|
30575
|
+
const SDK_VERSION_MARKER = '0.34.0';
|
|
30676
30576
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
30677
30577
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
30678
30578
|
|
|
@@ -31031,8 +30931,8 @@ const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
|
|
|
31031
30931
|
const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
31032
30932
|
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
31033
30933
|
// for faster access to tokens config objects.
|
|
31034
|
-
const shouldFilter = filterTokens
|
|
31035
|
-
const mapFilterTokens = Object.assign({}, ...(filterTokens.map((t) => ({ [t.address || NATIVE]: t }))));
|
|
30934
|
+
const shouldFilter = filterTokens !== undefined;
|
|
30935
|
+
const mapFilterTokens = Object.assign({}, ...((filterTokens ?? []).map((t) => ({ [t.address || NATIVE]: t }))));
|
|
31036
30936
|
// Get blockscout client for the given chain
|
|
31037
30937
|
let blockscoutClient = blockscoutClientMap.get(chainId);
|
|
31038
30938
|
if (!blockscoutClient) {
|
|
@@ -31152,7 +31052,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
|
|
|
31152
31052
|
// Please remove this hack once https://immutable.atlassian.net/browse/WT-1710
|
|
31153
31053
|
// is done.
|
|
31154
31054
|
const isL1Chain = getL1ChainId(config) === chainId;
|
|
31155
|
-
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(walletAddress, chainId, isL1Chain ? tokens :
|
|
31055
|
+
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(walletAddress, chainId, isL1Chain ? tokens : undefined));
|
|
31156
31056
|
}
|
|
31157
31057
|
// This fallback to use ERC20s calls which is a best effort solution
|
|
31158
31058
|
// Fails in fetching data from the RCP calls might result in some
|