@imtbl/sdk 0.32.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/orderbook.js CHANGED
@@ -429,7 +429,7 @@ class OrdersService {
429
429
  * @returns ListListingsResult OK response.
430
430
  * @throws ApiError
431
431
  */
432
- listListings({ chainName, status, sellItemContractAddress, buyItemContractAddress, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, }) {
432
+ listListings({ chainName, status, sellItemContractAddress, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, }) {
433
433
  return this.httpRequest.request({
434
434
  method: 'GET',
435
435
  url: '/v1/chains/{chain_name}/orders/listings',
@@ -440,6 +440,8 @@ class OrdersService {
440
440
  'status': status,
441
441
  'sell_item_contract_address': sellItemContractAddress,
442
442
  'buy_item_contract_address': buyItemContractAddress,
443
+ 'account_address': accountAddress,
444
+ 'sell_item_metadata_id': sellItemMetadataId,
443
445
  'sell_item_token_id': sellItemTokenId,
444
446
  'from_updated_at': fromUpdatedAt,
445
447
  'page_size': pageSize,
@@ -10203,7 +10203,7 @@ declare enum Networks {
10203
10203
  }
10204
10204
  interface OidcConfiguration {
10205
10205
  clientId: string;
10206
- logoutRedirectUri: string;
10206
+ logoutRedirectUri?: string;
10207
10207
  logoutMode?: 'redirect' | 'silent';
10208
10208
  redirectUri: string;
10209
10209
  scope?: string;
@@ -10337,14 +10337,8 @@ declare class Passport {
10337
10337
  */
10338
10338
  connectImxSilent(): Promise<IMXProvider | null>;
10339
10339
  connectImx(): Promise<IMXProvider>;
10340
- connectImxDeviceFlow(deviceCode: string, interval: number, timeoutMs?: number): Promise<IMXProvider | null>;
10341
10340
  getPKCEAuthorizationUrl(): string;
10342
10341
  connectImxPKCEFlow(authorizationCode: string, state: string): Promise<IMXProvider | null>;
10343
- /**
10344
- * @returns {boolean} the stored device flow credentials if they exist
10345
- */
10346
- checkStoredDeviceFlowCredentials(): DeviceTokenResponse | null;
10347
- connectImxWithCredentials(tokenResponse: DeviceTokenResponse): Promise<IMXProvider | null>;
10348
10342
  connectEvm(): Provider;
10349
10343
  /**
10350
10344
  *
@@ -10357,17 +10351,23 @@ declare class Passport {
10357
10351
  login(options?: {
10358
10352
  useCachedSession: boolean;
10359
10353
  }): Promise<UserProfile | null>;
10360
- loginWithDeviceFlow(): Promise<DeviceConnectResponse>;
10361
10354
  loginCallback(): Promise<void>;
10355
+ loginWithDeviceFlow(): Promise<DeviceConnectResponse>;
10356
+ loginWithDeviceFlowCallback(deviceCode: string, interval: number, timeoutMs?: number): Promise<UserProfile>;
10362
10357
  logout(): Promise<void>;
10358
+ /**
10359
+ * Logs the user out of Passport when using device flow authentication.
10360
+ *
10361
+ * @returns {Promise<string>} The device flow end session endpoint. Consumers are responsible for
10362
+ * opening this URL in the same browser that was used to log the user in.
10363
+ */
10364
+ logoutDeviceFlow(): Promise<string>;
10363
10365
  /**
10364
10366
  * This method should only be called from the logout redirect uri
10365
10367
  * when logout mode is 'silent'.
10366
10368
  */
10367
10369
  logoutSilentCallback(url: string): Promise<void>;
10368
- logoutDeviceFlow(): Promise<void>;
10369
10370
  getUserInfo(): Promise<UserProfile | undefined>;
10370
- getUserInfoDeviceFlow(): Promise<UserProfile | undefined>;
10371
10371
  getIdToken(): Promise<string | undefined>;
10372
10372
  getAccessToken(): Promise<string | undefined>;
10373
10373
  getLinkedAddresses(): Promise<string[]>;
package/dist/passport.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import globalAxios$1, { isAxiosError as isAxiosError$1 } from 'axios';
2
2
  import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
3
- import { UserManager, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
3
+ import { UserManager, User, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
4
4
  import jwt_decode from 'jwt-decode';
5
5
  import * as crypto from 'crypto';
6
6
  import { Magic } from 'magic-sdk';
@@ -2191,7 +2191,7 @@ class MultiRollupApiClients {
2191
2191
  }
2192
2192
 
2193
2193
  // eslint-disable-next-line @typescript-eslint/naming-convention
2194
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.32.0' };
2194
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.34.0' };
2195
2195
  const createConfig = ({ basePath, headers, }) => {
2196
2196
  if (!basePath.trim()) {
2197
2197
  throw Error('basePath can not be empty');
@@ -2247,7 +2247,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2247
2247
  chainID,
2248
2248
  coreContractAddress,
2249
2249
  registrationContractAddress,
2250
- sdkVersion: 'ts-immutable-sdk-0.32.0',
2250
+ sdkVersion: 'ts-immutable-sdk-0.34.0',
2251
2251
  });
2252
2252
  /**
2253
2253
  * Sets `sdkVersion` at the time of build
@@ -6780,26 +6780,10 @@ var ChainName;
6780
6780
  ChainName["IMTBL_ZKEVM_MAINNET"] = "Immutable zkEVM";
6781
6781
  })(ChainName || (ChainName = {}));
6782
6782
 
6783
- const keyCrendentials = 'passport_credentials';
6784
6783
  const KEY_PKCE_STATE = 'pkce_state';
6785
6784
  const KEY_PKCE_VERIFIER = 'pkce_verifier';
6786
6785
  const validCredentialsMinTtlSec = 3600; // 1 hour
6787
6786
  class DeviceCredentialsManager {
6788
- saveCredentials(tokenResponse) {
6789
- if (this.areValid(tokenResponse)) {
6790
- localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
6791
- }
6792
- else {
6793
- throw Error('Invalid credentials.');
6794
- }
6795
- }
6796
- getCredentials() {
6797
- const credentialsJson = localStorage.getItem(keyCrendentials);
6798
- if (credentialsJson) {
6799
- return JSON.parse(credentialsJson);
6800
- }
6801
- return null;
6802
- }
6803
6787
  areValid(tokenResponse) {
6804
6788
  if (tokenResponse) {
6805
6789
  const accessTokenValid = this.isTokenValid(tokenResponse.access_token);
@@ -6819,9 +6803,6 @@ class DeviceCredentialsManager {
6819
6803
  return false;
6820
6804
  }
6821
6805
  }
6822
- clearCredentials() {
6823
- localStorage.removeItem(keyCrendentials);
6824
- }
6825
6806
  savePKCEData(data) {
6826
6807
  localStorage.setItem(KEY_PKCE_STATE, data.state);
6827
6808
  localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
@@ -6857,9 +6838,14 @@ const formUrlEncodedHeader = {
6857
6838
  'Content-Type': 'application/x-www-form-urlencoded',
6858
6839
  },
6859
6840
  };
6860
- const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
6841
+ const getAuthConfiguration = (config) => {
6842
+ const { authenticationDomain, oidcConfiguration } = config;
6861
6843
  const store = typeof window !== 'undefined' ? window.localStorage : new InMemoryWebStorage();
6862
6844
  const userStore = new WebStorageStateStore({ store });
6845
+ let endSessionEndpoint = `${authenticationDomain}/v2/logout?client_id=${oidcConfiguration.clientId}`;
6846
+ if (oidcConfiguration.logoutRedirectUri) {
6847
+ endSessionEndpoint += `&returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`;
6848
+ }
6863
6849
  const baseConfiguration = {
6864
6850
  authority: authenticationDomain,
6865
6851
  redirect_uri: oidcConfiguration.redirectUri,
@@ -6869,9 +6855,7 @@ const getAuthConfiguration = ({ oidcConfiguration, authenticationDomain, }) => {
6869
6855
  authorization_endpoint: `${authenticationDomain}/authorize`,
6870
6856
  token_endpoint: `${authenticationDomain}/oauth/token`,
6871
6857
  userinfo_endpoint: `${authenticationDomain}/userinfo`,
6872
- end_session_endpoint: `${authenticationDomain}/v2/logout`
6873
- + `?returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`
6874
- + `&client_id=${oidcConfiguration.clientId}`,
6858
+ end_session_endpoint: endSessionEndpoint,
6875
6859
  },
6876
6860
  mergeClaims: true,
6877
6861
  loadUserInfo: true,
@@ -6890,6 +6874,15 @@ function wait$1(ms) {
6890
6874
  setTimeout(resolve, ms);
6891
6875
  });
6892
6876
  }
6877
+ function base64URLEncode(str) {
6878
+ return str.toString('base64')
6879
+ .replace(/\+/g, '-')
6880
+ .replace(/\//g, '_')
6881
+ .replace(/=/g, '');
6882
+ }
6883
+ function sha256(buffer) {
6884
+ return crypto.createHash('sha256').update(buffer).digest();
6885
+ }
6893
6886
  class AuthManager {
6894
6887
  userManager;
6895
6888
  config;
@@ -6933,32 +6926,24 @@ class AuthManager {
6933
6926
  }
6934
6927
  return user;
6935
6928
  };
6936
- static mapDeviceTokenResponseToDomainUserModel = (tokenResponse) => {
6929
+ static mapDeviceTokenResponseToOidcUser = (tokenResponse) => {
6937
6930
  const idTokenPayload = jwt_decode(tokenResponse.id_token);
6938
- const user = {
6939
- idToken: tokenResponse.id_token,
6940
- accessToken: tokenResponse.access_token,
6941
- refreshToken: tokenResponse.refresh_token,
6931
+ return new User({
6932
+ id_token: tokenResponse.id_token,
6933
+ access_token: tokenResponse.access_token,
6934
+ refresh_token: tokenResponse.refresh_token,
6935
+ token_type: tokenResponse.token_type,
6942
6936
  profile: {
6943
6937
  sub: idTokenPayload.sub,
6938
+ iss: idTokenPayload.iss,
6939
+ aud: idTokenPayload.aud,
6940
+ exp: idTokenPayload.exp,
6941
+ iat: idTokenPayload.iat,
6944
6942
  email: idTokenPayload.email,
6945
6943
  nickname: idTokenPayload.nickname,
6944
+ passport: idTokenPayload.passport,
6946
6945
  },
6947
- };
6948
- if (idTokenPayload?.passport?.imx_eth_address) {
6949
- user.imx = {
6950
- ethAddress: idTokenPayload.passport.imx_eth_address,
6951
- starkAddress: idTokenPayload.passport.imx_stark_address,
6952
- userAdminAddress: idTokenPayload.passport.imx_user_admin_address,
6953
- };
6954
- }
6955
- if (idTokenPayload?.passport?.zkevm_eth_address) {
6956
- user.zkEvm = {
6957
- ethAddress: idTokenPayload?.passport?.zkevm_eth_address,
6958
- userAdminAddress: idTokenPayload?.passport?.zkevm_user_admin_address,
6959
- };
6960
- }
6961
- return user;
6946
+ });
6962
6947
  };
6963
6948
  async login() {
6964
6949
  return withPassportError(async () => {
@@ -6988,7 +6973,7 @@ class AuthManager {
6988
6973
  }, PassportErrorType.AUTHENTICATION_ERROR);
6989
6974
  }
6990
6975
  /* eslint-disable no-await-in-loop */
6991
- async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
6976
+ async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
6992
6977
  return withPassportError(async () => {
6993
6978
  const startTime = Date.now();
6994
6979
  const loopCondition = true;
@@ -6999,8 +6984,9 @@ class AuthManager {
6999
6984
  await wait$1(interval * 1000);
7000
6985
  try {
7001
6986
  const tokenResponse = await this.getDeviceFlowToken(deviceCode);
7002
- const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
7003
- this.deviceCredentialsManager.saveCredentials(tokenResponse);
6987
+ const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
6988
+ const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
6989
+ await this.userManager.storeUser(oidcUser);
7004
6990
  return user;
7005
6991
  }
7006
6992
  catch (error) {
@@ -7036,20 +7022,11 @@ class AuthManager {
7036
7022
  }, formUrlEncodedHeader);
7037
7023
  return response.data;
7038
7024
  }
7039
- static base64URLEncode(str) {
7040
- return str.toString('base64')
7041
- .replace(/\+/g, '-')
7042
- .replace(/\//g, '_')
7043
- .replace(/=/g, '');
7044
- }
7045
- static sha256(buffer) {
7046
- return crypto.createHash('sha256').update(buffer).digest();
7047
- }
7048
7025
  getPKCEAuthorizationUrl() {
7049
- const verifier = AuthManager.base64URLEncode(crypto.randomBytes(32));
7050
- const challenge = AuthManager.base64URLEncode(AuthManager.sha256(verifier));
7026
+ const verifier = base64URLEncode(crypto.randomBytes(32));
7027
+ const challenge = base64URLEncode(sha256(verifier));
7051
7028
  // https://auth0.com/docs/secure/attack-protection/state-parameters
7052
- const state = AuthManager.base64URLEncode(crypto.randomBytes(32));
7029
+ const state = base64URLEncode(crypto.randomBytes(32));
7053
7030
  this.deviceCredentialsManager.savePKCEData({ state, verifier });
7054
7031
  return `${this.config.authenticationDomain}/authorize?`
7055
7032
  + 'response_type=code'
@@ -7071,8 +7048,9 @@ class AuthManager {
7071
7048
  throw new Error('Provided state does not match stored state');
7072
7049
  }
7073
7050
  const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
7074
- const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
7075
- this.deviceCredentialsManager.saveCredentials(tokenResponse);
7051
+ const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
7052
+ const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
7053
+ await this.userManager.storeUser(oidcUser);
7076
7054
  return user;
7077
7055
  }, PassportErrorType.AUTHENTICATION_ERROR);
7078
7056
  }
@@ -7086,31 +7064,6 @@ class AuthManager {
7086
7064
  }, formUrlEncodedHeader);
7087
7065
  return response.data;
7088
7066
  }
7089
- async connectImxWithCredentials(tokenResponse) {
7090
- return withPassportError(async () => {
7091
- if (this.deviceCredentialsManager.areValid(tokenResponse)) {
7092
- // Credentials exist and are still valid
7093
- return AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
7094
- }
7095
- const refreshToken = tokenResponse?.refresh_token ?? null;
7096
- if (refreshToken) {
7097
- // Token is no longer valid, but refresh token can be used to a new one
7098
- const user = await this.refreshToken(refreshToken);
7099
- return user;
7100
- }
7101
- return null;
7102
- }, PassportErrorType.AUTHENTICATION_ERROR);
7103
- }
7104
- async refreshToken(refreshToken) {
7105
- const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
7106
- client_id: this.config.oidcConfiguration.clientId,
7107
- grant_type: 'refresh_token',
7108
- refresh_token: refreshToken,
7109
- }, formUrlEncodedHeader);
7110
- const newTokenResponse = response.data;
7111
- this.deviceCredentialsManager.saveCredentials(newTokenResponse);
7112
- return AuthManager.mapDeviceTokenResponseToDomainUserModel(newTokenResponse);
7113
- }
7114
7067
  async logout() {
7115
7068
  return withPassportError(async () => {
7116
7069
  if (this.logoutMode === 'silent') {
@@ -7119,29 +7072,20 @@ class AuthManager {
7119
7072
  return this.userManager.signoutRedirect();
7120
7073
  }, PassportErrorType.LOGOUT_ERROR);
7121
7074
  }
7122
- async logoutSilentCallback(url) {
7123
- return this.userManager.signoutSilentCallback(url);
7075
+ async removeUser() {
7076
+ return this.userManager.removeUser();
7124
7077
  }
7125
- async logoutDeviceFlow() {
7126
- return withPassportError(async () => {
7127
- this.deviceCredentialsManager.clearCredentials();
7128
- }, PassportErrorType.LOGOUT_ERROR);
7129
- }
7130
- /**
7131
- * Get the user from the cache or refresh the token if it's expired.
7132
- * return null if there's no refresh token.
7133
- */
7134
- async getAuthenticatedUser() {
7135
- const oidcUser = await this.userManager.getUser();
7136
- if (!oidcUser)
7137
- return null;
7138
- if (!isTokenExpired(oidcUser)) {
7139
- return AuthManager.mapOidcUserToDomainModel(oidcUser);
7140
- }
7141
- if (oidcUser.refresh_token) {
7142
- return this.refreshTokenAndUpdatePromise();
7078
+ getDeviceFlowEndSessionEndpoint() {
7079
+ const { authenticationDomain, oidcConfiguration } = this.config;
7080
+ let endSessionEndpoint = `${authenticationDomain}/v2/logout`;
7081
+ if (oidcConfiguration.logoutRedirectUri) {
7082
+ endSessionEndpoint += `?client_id=${oidcConfiguration.clientId}`
7083
+ + `&returnTo=${encodeURIComponent(oidcConfiguration.logoutRedirectUri)}`;
7143
7084
  }
7144
- return null;
7085
+ return endSessionEndpoint;
7086
+ }
7087
+ async logoutSilentCallback(url) {
7088
+ return this.userManager.signoutSilentCallback(url);
7145
7089
  }
7146
7090
  async forceUserRefresh() {
7147
7091
  return this.refreshTokenAndUpdatePromise();
@@ -7156,25 +7100,10 @@ class AuthManager {
7156
7100
  // eslint-disable-next-line no-async-promise-executor
7157
7101
  this.refreshingPromise = new Promise(async (resolve, reject) => {
7158
7102
  try {
7159
- if (this.config.crossSdkBridgeEnabled) {
7160
- const tokenResponse = this.checkStoredDeviceFlowCredentials();
7161
- if (tokenResponse) {
7162
- const refreshToken = tokenResponse?.refresh_token ?? null;
7163
- if (refreshToken) {
7164
- const newUser = await this.refreshToken(refreshToken);
7165
- if (newUser) {
7166
- resolve(newUser);
7167
- return;
7168
- }
7169
- }
7170
- }
7171
- }
7172
- else {
7173
- const newOidcUser = await this.userManager.signinSilent();
7174
- if (newOidcUser) {
7175
- resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
7176
- return;
7177
- }
7103
+ const newOidcUser = await this.userManager.signinSilent();
7104
+ if (newOidcUser) {
7105
+ resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
7106
+ return;
7178
7107
  }
7179
7108
  resolve(null);
7180
7109
  }
@@ -7187,30 +7116,24 @@ class AuthManager {
7187
7116
  });
7188
7117
  return this.refreshingPromise;
7189
7118
  }
7119
+ /**
7120
+ * Get the user from the cache or refresh the token if it's expired.
7121
+ * return null if there's no refresh token.
7122
+ */
7190
7123
  async getUser() {
7191
7124
  return withPassportError(async () => {
7192
- const user = await this.getAuthenticatedUser();
7193
- if (user)
7194
- return user;
7195
- const deviceToken = this.deviceCredentialsManager.getCredentials();
7196
- if (deviceToken) {
7197
- return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
7125
+ const oidcUser = await this.userManager.getUser();
7126
+ if (!oidcUser)
7127
+ return null;
7128
+ if (!isTokenExpired(oidcUser)) {
7129
+ return AuthManager.mapOidcUserToDomainModel(oidcUser);
7198
7130
  }
7199
- return null;
7200
- }, PassportErrorType.NOT_LOGGED_IN_ERROR);
7201
- }
7202
- async getUserDeviceFlow() {
7203
- return withPassportError(async () => {
7204
- const deviceToken = this.deviceCredentialsManager.getCredentials();
7205
- if (deviceToken) {
7206
- return AuthManager.mapDeviceTokenResponseToDomainUserModel(deviceToken);
7131
+ if (oidcUser.refresh_token) {
7132
+ return this.refreshTokenAndUpdatePromise();
7207
7133
  }
7208
7134
  return null;
7209
7135
  }, PassportErrorType.NOT_LOGGED_IN_ERROR);
7210
7136
  }
7211
- checkStoredDeviceFlowCredentials() {
7212
- return this.deviceCredentialsManager.getCredentials();
7213
- }
7214
7137
  }
7215
7138
 
7216
7139
  const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
@@ -8045,21 +7968,10 @@ class PassportImxProviderFactory {
8045
7968
  }
8046
7969
  return this.createProviderInstance(user);
8047
7970
  }
8048
- async getProviderWithDeviceFlow(deviceCode, interval, timeoutMs) {
8049
- const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
8050
- return this.createProviderInstance(user);
8051
- }
8052
7971
  async getProviderWithPKCEFlow(authorizationCode, state) {
8053
7972
  const user = await this.authManager.connectImxPKCEFlow(authorizationCode, state);
8054
7973
  return this.createProviderInstance(user);
8055
7974
  }
8056
- async getProviderWithCredentials(tokenResponse) {
8057
- const user = await this.authManager.connectImxWithCredentials(tokenResponse);
8058
- if (!user) {
8059
- return null;
8060
- }
8061
- return this.createProviderInstance(user);
8062
- }
8063
7975
  async createProviderInstance(user) {
8064
7976
  if (!user.idToken) {
8065
7977
  throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
@@ -8103,7 +8015,6 @@ class PassportConfiguration {
8103
8015
  constructor({ baseConfig, overrides, crossSdkBridgeEnabled, ...oidcConfiguration }) {
8104
8016
  validateConfiguration(oidcConfiguration, [
8105
8017
  'clientId',
8106
- 'logoutRedirectUri',
8107
8018
  'redirectUri',
8108
8019
  ]);
8109
8020
  this.oidcConfiguration = oidcConfiguration;
@@ -8578,7 +8489,7 @@ const CHAIN_NAME_MAP = new Map([
8578
8489
  ]);
8579
8490
 
8580
8491
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
8581
- async function registerZkEvmUser({ authManager, config, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
8492
+ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
8582
8493
  const web3Provider = new Web3Provider(magicProvider);
8583
8494
  const ethSigner = web3Provider.getSigner();
8584
8495
  const ethereumAddress = await ethSigner.getAddress();
@@ -8601,24 +8512,14 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
8601
8512
  catch (error) {
8602
8513
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
8603
8514
  }
8604
- let user;
8605
- if (config.crossSdkBridgeEnabled) {
8606
- const credentials = authManager.checkStoredDeviceFlowCredentials();
8607
- if (!credentials || !credentials.refresh_token) {
8608
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Cross SDK bridge: Failed to refresh user details');
8609
- }
8610
- user = await authManager.refreshToken(credentials.refresh_token);
8611
- }
8612
- else {
8613
- user = await authManager.forceUserRefresh();
8614
- }
8515
+ const user = await authManager.forceUserRefresh();
8615
8516
  if (!user?.zkEvm) {
8616
8517
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
8617
8518
  }
8618
8519
  return user;
8619
8520
  }
8620
8521
 
8621
- const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
8522
+ const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
8622
8523
  let user = null;
8623
8524
  try {
8624
8525
  user = await authManager.getUser();
@@ -8628,7 +8529,7 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8628
8529
  console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
8629
8530
  }
8630
8531
  if (!user) {
8631
- user = await authManager.getUserDeviceFlow() || await authManager.login();
8532
+ user = await authManager.login();
8632
8533
  }
8633
8534
  if (!user.idToken) {
8634
8535
  throw new Error('User is missing idToken');
@@ -8638,7 +8539,6 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8638
8539
  // Generate counterfactual address and retrieve updated Auth0 user
8639
8540
  const userZkevm = await registerZkEvmUser({
8640
8541
  authManager,
8641
- config,
8642
8542
  magicProvider,
8643
8543
  multiRollupApiClients,
8644
8544
  accessToken: user.accessToken,
@@ -9062,24 +8962,12 @@ class Passport {
9062
8962
  async connectImx() {
9063
8963
  return this.passportImxProviderFactory.getProvider();
9064
8964
  }
9065
- async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
9066
- return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
9067
- }
9068
8965
  getPKCEAuthorizationUrl() {
9069
8966
  return this.authManager.getPKCEAuthorizationUrl();
9070
8967
  }
9071
8968
  async connectImxPKCEFlow(authorizationCode, state) {
9072
8969
  return this.passportImxProviderFactory.getProviderWithPKCEFlow(authorizationCode, state);
9073
8970
  }
9074
- /**
9075
- * @returns {boolean} the stored device flow credentials if they exist
9076
- */
9077
- checkStoredDeviceFlowCredentials() {
9078
- return this.authManager.checkStoredDeviceFlowCredentials();
9079
- }
9080
- async connectImxWithCredentials(tokenResponse) {
9081
- return this.passportImxProviderFactory.getProviderWithCredentials(tokenResponse);
9082
- }
9083
8971
  connectEvm() {
9084
8972
  if (this.config.network === Networks.PRODUCTION) {
9085
8973
  throw new Error('EVM is not supported on production network');
@@ -9119,19 +9007,35 @@ class Passport {
9119
9007
  }
9120
9008
  return user ? user.profile : null;
9121
9009
  }
9010
+ async loginCallback() {
9011
+ return this.authManager.loginCallback();
9012
+ }
9122
9013
  async loginWithDeviceFlow() {
9123
9014
  return this.authManager.loginWithDeviceFlow();
9124
9015
  }
9125
- async loginCallback() {
9126
- return this.authManager.loginCallback();
9016
+ async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
9017
+ const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
9018
+ return user.profile;
9127
9019
  }
9128
9020
  async logout() {
9129
- await this.authManager.logout();
9130
9021
  await this.confirmationScreen.logout();
9022
+ await this.authManager.logout();
9131
9023
  // Code after this point is only executed if the logout mode is silent
9132
9024
  await this.magicAdapter.logout();
9133
9025
  this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
9134
9026
  }
9027
+ /**
9028
+ * Logs the user out of Passport when using device flow authentication.
9029
+ *
9030
+ * @returns {Promise<string>} The device flow end session endpoint. Consumers are responsible for
9031
+ * opening this URL in the same browser that was used to log the user in.
9032
+ */
9033
+ async logoutDeviceFlow() {
9034
+ await this.authManager.removeUser();
9035
+ await this.magicAdapter.logout();
9036
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
9037
+ return this.authManager.getDeviceFlowEndSessionEndpoint();
9038
+ }
9135
9039
  /**
9136
9040
  * This method should only be called from the logout redirect uri
9137
9041
  * when logout mode is 'silent'.
@@ -9139,17 +9043,10 @@ class Passport {
9139
9043
  async logoutSilentCallback(url) {
9140
9044
  return this.authManager.logoutSilentCallback(url);
9141
9045
  }
9142
- async logoutDeviceFlow() {
9143
- return this.authManager.logoutDeviceFlow();
9144
- }
9145
9046
  async getUserInfo() {
9146
9047
  const user = await this.authManager.getUser();
9147
9048
  return user?.profile;
9148
9049
  }
9149
- async getUserInfoDeviceFlow() {
9150
- const user = await this.authManager.getUserDeviceFlow();
9151
- return user?.profile;
9152
- }
9153
9050
  async getIdToken() {
9154
9051
  const user = await this.authManager.getUser();
9155
9052
  return user?.idToken;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.32.0",
4
+ "version": "0.34.0",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",