@imtbl/sdk 0.30.1 → 0.30.2

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/index.cjs CHANGED
@@ -13,7 +13,7 @@ var BN$2 = require('bn.js');
13
13
  var encUtils = require('enc-utils');
14
14
  var events = require('events');
15
15
  var abi = require('@0xsequence/abi');
16
- var config$1 = require('@0xsequence/config');
16
+ var core = require('@0xsequence/core');
17
17
  var FormData$2 = require('form-data');
18
18
  var seaportJs = require('@opensea/seaport-js');
19
19
  var units = require('@ethersproject/units');
@@ -3792,7 +3792,7 @@ class MultiRollupApiClients {
3792
3792
  }
3793
3793
 
3794
3794
  // eslint-disable-next-line @typescript-eslint/naming-convention
3795
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.1' };
3795
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.2' };
3796
3796
  const createConfig = ({ basePath, headers, }) => {
3797
3797
  if (!basePath.trim()) {
3798
3798
  throw Error('basePath can not be empty');
@@ -3852,7 +3852,7 @@ class APIError extends Error {
3852
3852
 
3853
3853
  /* eslint-disable implicit-arrow-linebreak */
3854
3854
  const defaultHeaders = {
3855
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.1',
3855
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.2',
3856
3856
  };
3857
3857
  /**
3858
3858
  * createAPIConfiguration to create a custom Configuration
@@ -4263,7 +4263,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4263
4263
  chainID,
4264
4264
  coreContractAddress,
4265
4265
  registrationContractAddress,
4266
- sdkVersion: 'ts-immutable-sdk-0.30.1',
4266
+ sdkVersion: 'ts-immutable-sdk-0.30.2',
4267
4267
  });
4268
4268
  /**
4269
4269
  * Sets `sdkVersion` at the time of build
@@ -8978,7 +8978,7 @@ class AuthManager {
8978
8978
  nickname: idTokenPayload.nickname,
8979
8979
  },
8980
8980
  };
8981
- if (idTokenPayload?.passport.imx_eth_address) {
8981
+ if (idTokenPayload?.passport?.imx_eth_address) {
8982
8982
  user.imx = {
8983
8983
  ethAddress: idTokenPayload.passport.imx_eth_address,
8984
8984
  starkAddress: idTokenPayload.passport.imx_stark_address,
@@ -9165,21 +9165,11 @@ class AuthManager {
9165
9165
  this.deviceCredentialsManager.clearCredentials();
9166
9166
  }, PassportErrorType.LOGOUT_ERROR);
9167
9167
  }
9168
- async loginSilent({ forceRefresh } = { forceRefresh: false }) {
9169
- // eslint-disable-next-line arrow-body-style
9170
- return withPassportError(async () => {
9171
- return this.getUser({ forceRefresh });
9172
- }, PassportErrorType.SILENT_LOGIN_ERROR);
9173
- }
9174
9168
  /**
9175
9169
  * Get the user from the cache or refresh the token if it's expired.
9176
- * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
9177
- * throw an error if there's no refresh token.
9170
+ * return null if there's no refresh token.
9178
9171
  */
9179
- async getAuthenticatedUser({ forceRefresh = false }) {
9180
- if (forceRefresh) {
9181
- return this.refreshTokenAndUpdatePromise();
9182
- }
9172
+ async getAuthenticatedUser() {
9183
9173
  const oidcUser = await this.userManager.getUser();
9184
9174
  if (!oidcUser)
9185
9175
  return null;
@@ -9191,6 +9181,9 @@ class AuthManager {
9191
9181
  }
9192
9182
  return null;
9193
9183
  }
9184
+ async forceUserRefresh() {
9185
+ return this.refreshTokenAndUpdatePromise();
9186
+ }
9194
9187
  /**
9195
9188
  * Refreshes the token and returns the user.
9196
9189
  * If the token is already being refreshed, returns the existing promise.
@@ -9217,9 +9210,9 @@ class AuthManager {
9217
9210
  });
9218
9211
  return this.refreshingPromise;
9219
9212
  }
9220
- async getUser({ forceRefresh } = { forceRefresh: false }) {
9213
+ async getUser() {
9221
9214
  return withPassportError(async () => {
9222
- const user = await this.getAuthenticatedUser({ forceRefresh });
9215
+ const user = await this.getAuthenticatedUser();
9223
9216
  if (user)
9224
9217
  return user;
9225
9218
  const deviceToken = this.deviceCredentialsManager.getCredentials();
@@ -9830,7 +9823,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
9830
9823
  async function forceUserRefresh(authManager) {
9831
9824
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
9832
9825
  await retryWithDelay(async () => {
9833
- const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
9826
+ const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
9834
9827
  if (user?.imx)
9835
9828
  return user;
9836
9829
  return Promise.reject(new Error('user wallet addresses not exist'));
@@ -10057,7 +10050,7 @@ class PassportImxProviderFactory {
10057
10050
  async getProvider() {
10058
10051
  let user = null;
10059
10052
  try {
10060
- user = await this.authManager.loginSilent();
10053
+ user = await this.authManager.getUser();
10061
10054
  }
10062
10055
  catch (e) {
10063
10056
  // eslint-disable-next-line no-console
@@ -10069,7 +10062,7 @@ class PassportImxProviderFactory {
10069
10062
  return this.createProviderInstance(user);
10070
10063
  }
10071
10064
  async getProviderSilent() {
10072
- const user = await this.authManager.loginSilent();
10065
+ const user = await this.authManager.getUser();
10073
10066
  if (!user) {
10074
10067
  return null;
10075
10068
  }
@@ -10452,10 +10445,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
10452
10445
  const ethsigNoType = await signer.signMessage(hashArray);
10453
10446
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
10454
10447
  // Add metadata
10455
- const encodedSignature = config$1.encodeSignature({
10448
+ const encodedSignature = core.v1.signature.encodeSignature({
10449
+ version: 1,
10456
10450
  threshold: TRANSACTION_SIGNATURE_THRESHOLD,
10457
10451
  signers: [
10458
10452
  {
10453
+ isDynamic: false,
10454
+ unrecovered: true,
10459
10455
  weight: SIGNATURE_WEIGHT,
10460
10456
  signature: signedDigest,
10461
10457
  },
@@ -10470,8 +10466,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
10470
10466
  ]);
10471
10467
  };
10472
10468
  const decodeRelayerTypedDataSignature = (relayerSignature) => {
10473
- const signatureWithThreshold = `0000${relayerSignature}`;
10474
- return config$1.decodeSignature(signatureWithThreshold);
10469
+ const signatureWithThreshold = `0x0000${relayerSignature}`;
10470
+ return core.v1.signature.decodeSignature(signatureWithThreshold);
10475
10471
  };
10476
10472
  const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
10477
10473
  // Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
@@ -10487,11 +10483,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
10487
10483
  const ethsigNoType = await signer.signMessage(hashArray);
10488
10484
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
10489
10485
  const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
10490
- return config$1.encodeSignature({
10486
+ return core.v1.signature.encodeSignature({
10487
+ version: 1,
10491
10488
  threshold: EIP712_SIGNATURE_THRESHOLD,
10492
10489
  signers: [
10493
10490
  ...signers,
10494
10491
  {
10492
+ isDynamic: false,
10493
+ unrecovered: true,
10495
10494
  weight: SIGNATURE_WEIGHT,
10496
10495
  signature: signedDigest,
10497
10496
  },
@@ -10634,7 +10633,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
10634
10633
  user = await authManager.refreshToken(credentials.refresh_token);
10635
10634
  }
10636
10635
  else {
10637
- user = await authManager.loginSilent({ forceRefresh: true });
10636
+ user = await authManager.forceUserRefresh();
10638
10637
  }
10639
10638
  if (!user?.zkEvm) {
10640
10639
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
@@ -10643,7 +10642,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
10643
10642
  }
10644
10643
 
10645
10644
  const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
10646
- const user = await authManager.getUser() || await authManager.getUserDeviceFlow() || await authManager.login();
10645
+ let user = null;
10646
+ try {
10647
+ user = await authManager.getUser();
10648
+ }
10649
+ catch (err) {
10650
+ // eslint-disable-next-line no-console
10651
+ console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
10652
+ }
10653
+ if (!user) {
10654
+ user = await authManager.getUserDeviceFlow() || await authManager.login();
10655
+ }
10647
10656
  if (!user.idToken) {
10648
10657
  throw new Error('User is missing idToken');
10649
10658
  }
@@ -11119,11 +11128,14 @@ class Passport {
11119
11128
  const { useCachedSession = false } = options || {};
11120
11129
  let user = null;
11121
11130
  try {
11122
- user = await this.authManager.loginSilent();
11131
+ user = await this.authManager.getUser();
11123
11132
  }
11124
11133
  catch (error) {
11134
+ if (useCachedSession) {
11135
+ throw error;
11136
+ }
11125
11137
  // eslint-disable-next-line no-console
11126
- console.warn('loginSilent failed with error:', error);
11138
+ console.warn('login failed to retrieve a cached user session', error);
11127
11139
  }
11128
11140
  if (!user && !useCachedSession) {
11129
11141
  user = await this.authManager.login();
@@ -34018,7 +34030,7 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
34018
34030
  return itemRequirements;
34019
34031
  }
34020
34032
 
34021
- const SDK_VERSION_MARKER = '0.30.1';
34033
+ const SDK_VERSION_MARKER = '0.30.2';
34022
34034
  // This SDK version is replaced by the `yarn build` command ran on the root level
34023
34035
  const globalPackageVersion = () => SDK_VERSION_MARKER;
34024
34036
 
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import BN$2 from 'bn.js';
11
11
  import * as encUtils from 'enc-utils';
12
12
  import { EventEmitter } from 'events';
13
13
  import { walletContracts } from '@0xsequence/abi';
14
- import { encodeSignature, decodeSignature } from '@0xsequence/config';
14
+ import { v1 } from '@0xsequence/core';
15
15
  import FormData$2 from 'form-data';
16
16
  import { Seaport as Seaport$1 } from '@opensea/seaport-js';
17
17
  import { parseUnits } from '@ethersproject/units';
@@ -3770,7 +3770,7 @@ class MultiRollupApiClients {
3770
3770
  }
3771
3771
 
3772
3772
  // eslint-disable-next-line @typescript-eslint/naming-convention
3773
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.1' };
3773
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.30.2' };
3774
3774
  const createConfig = ({ basePath, headers, }) => {
3775
3775
  if (!basePath.trim()) {
3776
3776
  throw Error('basePath can not be empty');
@@ -3830,7 +3830,7 @@ class APIError extends Error {
3830
3830
 
3831
3831
  /* eslint-disable implicit-arrow-linebreak */
3832
3832
  const defaultHeaders = {
3833
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.1',
3833
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.30.2',
3834
3834
  };
3835
3835
  /**
3836
3836
  * createAPIConfiguration to create a custom Configuration
@@ -4241,7 +4241,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4241
4241
  chainID,
4242
4242
  coreContractAddress,
4243
4243
  registrationContractAddress,
4244
- sdkVersion: 'ts-immutable-sdk-0.30.1',
4244
+ sdkVersion: 'ts-immutable-sdk-0.30.2',
4245
4245
  });
4246
4246
  /**
4247
4247
  * Sets `sdkVersion` at the time of build
@@ -8956,7 +8956,7 @@ class AuthManager {
8956
8956
  nickname: idTokenPayload.nickname,
8957
8957
  },
8958
8958
  };
8959
- if (idTokenPayload?.passport.imx_eth_address) {
8959
+ if (idTokenPayload?.passport?.imx_eth_address) {
8960
8960
  user.imx = {
8961
8961
  ethAddress: idTokenPayload.passport.imx_eth_address,
8962
8962
  starkAddress: idTokenPayload.passport.imx_stark_address,
@@ -9143,21 +9143,11 @@ class AuthManager {
9143
9143
  this.deviceCredentialsManager.clearCredentials();
9144
9144
  }, PassportErrorType.LOGOUT_ERROR);
9145
9145
  }
9146
- async loginSilent({ forceRefresh } = { forceRefresh: false }) {
9147
- // eslint-disable-next-line arrow-body-style
9148
- return withPassportError(async () => {
9149
- return this.getUser({ forceRefresh });
9150
- }, PassportErrorType.SILENT_LOGIN_ERROR);
9151
- }
9152
9146
  /**
9153
9147
  * Get the user from the cache or refresh the token if it's expired.
9154
- * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
9155
- * throw an error if there's no refresh token.
9148
+ * return null if there's no refresh token.
9156
9149
  */
9157
- async getAuthenticatedUser({ forceRefresh = false }) {
9158
- if (forceRefresh) {
9159
- return this.refreshTokenAndUpdatePromise();
9160
- }
9150
+ async getAuthenticatedUser() {
9161
9151
  const oidcUser = await this.userManager.getUser();
9162
9152
  if (!oidcUser)
9163
9153
  return null;
@@ -9169,6 +9159,9 @@ class AuthManager {
9169
9159
  }
9170
9160
  return null;
9171
9161
  }
9162
+ async forceUserRefresh() {
9163
+ return this.refreshTokenAndUpdatePromise();
9164
+ }
9172
9165
  /**
9173
9166
  * Refreshes the token and returns the user.
9174
9167
  * If the token is already being refreshed, returns the existing promise.
@@ -9195,9 +9188,9 @@ class AuthManager {
9195
9188
  });
9196
9189
  return this.refreshingPromise;
9197
9190
  }
9198
- async getUser({ forceRefresh } = { forceRefresh: false }) {
9191
+ async getUser() {
9199
9192
  return withPassportError(async () => {
9200
- const user = await this.getAuthenticatedUser({ forceRefresh });
9193
+ const user = await this.getAuthenticatedUser();
9201
9194
  if (user)
9202
9195
  return user;
9203
9196
  const deviceToken = this.deviceCredentialsManager.getCredentials();
@@ -9808,7 +9801,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
9808
9801
  async function forceUserRefresh(authManager) {
9809
9802
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
9810
9803
  await retryWithDelay(async () => {
9811
- const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
9804
+ const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
9812
9805
  if (user?.imx)
9813
9806
  return user;
9814
9807
  return Promise.reject(new Error('user wallet addresses not exist'));
@@ -10035,7 +10028,7 @@ class PassportImxProviderFactory {
10035
10028
  async getProvider() {
10036
10029
  let user = null;
10037
10030
  try {
10038
- user = await this.authManager.loginSilent();
10031
+ user = await this.authManager.getUser();
10039
10032
  }
10040
10033
  catch (e) {
10041
10034
  // eslint-disable-next-line no-console
@@ -10047,7 +10040,7 @@ class PassportImxProviderFactory {
10047
10040
  return this.createProviderInstance(user);
10048
10041
  }
10049
10042
  async getProviderSilent() {
10050
- const user = await this.authManager.loginSilent();
10043
+ const user = await this.authManager.getUser();
10051
10044
  if (!user) {
10052
10045
  return null;
10053
10046
  }
@@ -10430,10 +10423,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
10430
10423
  const ethsigNoType = await signer.signMessage(hashArray);
10431
10424
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
10432
10425
  // Add metadata
10433
- const encodedSignature = encodeSignature({
10426
+ const encodedSignature = v1.signature.encodeSignature({
10427
+ version: 1,
10434
10428
  threshold: TRANSACTION_SIGNATURE_THRESHOLD,
10435
10429
  signers: [
10436
10430
  {
10431
+ isDynamic: false,
10432
+ unrecovered: true,
10437
10433
  weight: SIGNATURE_WEIGHT,
10438
10434
  signature: signedDigest,
10439
10435
  },
@@ -10448,8 +10444,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
10448
10444
  ]);
10449
10445
  };
10450
10446
  const decodeRelayerTypedDataSignature = (relayerSignature) => {
10451
- const signatureWithThreshold = `0000${relayerSignature}`;
10452
- return decodeSignature(signatureWithThreshold);
10447
+ const signatureWithThreshold = `0x0000${relayerSignature}`;
10448
+ return v1.signature.decodeSignature(signatureWithThreshold);
10453
10449
  };
10454
10450
  const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
10455
10451
  // Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
@@ -10465,11 +10461,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
10465
10461
  const ethsigNoType = await signer.signMessage(hashArray);
10466
10462
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
10467
10463
  const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
10468
- return encodeSignature({
10464
+ return v1.signature.encodeSignature({
10465
+ version: 1,
10469
10466
  threshold: EIP712_SIGNATURE_THRESHOLD,
10470
10467
  signers: [
10471
10468
  ...signers,
10472
10469
  {
10470
+ isDynamic: false,
10471
+ unrecovered: true,
10473
10472
  weight: SIGNATURE_WEIGHT,
10474
10473
  signature: signedDigest,
10475
10474
  },
@@ -10612,7 +10611,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
10612
10611
  user = await authManager.refreshToken(credentials.refresh_token);
10613
10612
  }
10614
10613
  else {
10615
- user = await authManager.loginSilent({ forceRefresh: true });
10614
+ user = await authManager.forceUserRefresh();
10616
10615
  }
10617
10616
  if (!user?.zkEvm) {
10618
10617
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
@@ -10621,7 +10620,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
10621
10620
  }
10622
10621
 
10623
10622
  const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
10624
- const user = await authManager.getUser() || await authManager.getUserDeviceFlow() || await authManager.login();
10623
+ let user = null;
10624
+ try {
10625
+ user = await authManager.getUser();
10626
+ }
10627
+ catch (err) {
10628
+ // eslint-disable-next-line no-console
10629
+ console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
10630
+ }
10631
+ if (!user) {
10632
+ user = await authManager.getUserDeviceFlow() || await authManager.login();
10633
+ }
10625
10634
  if (!user.idToken) {
10626
10635
  throw new Error('User is missing idToken');
10627
10636
  }
@@ -11097,11 +11106,14 @@ class Passport {
11097
11106
  const { useCachedSession = false } = options || {};
11098
11107
  let user = null;
11099
11108
  try {
11100
- user = await this.authManager.loginSilent();
11109
+ user = await this.authManager.getUser();
11101
11110
  }
11102
11111
  catch (error) {
11112
+ if (useCachedSession) {
11113
+ throw error;
11114
+ }
11103
11115
  // eslint-disable-next-line no-console
11104
- console.warn('loginSilent failed with error:', error);
11116
+ console.warn('login failed to retrieve a cached user session', error);
11105
11117
  }
11106
11118
  if (!user && !useCachedSession) {
11107
11119
  user = await this.authManager.login();
@@ -33996,7 +34008,7 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
33996
34008
  return itemRequirements;
33997
34009
  }
33998
34010
 
33999
- const SDK_VERSION_MARKER = '0.30.1';
34011
+ const SDK_VERSION_MARKER = '0.30.2';
34000
34012
  // This SDK version is replaced by the `yarn build` command ran on the root level
34001
34013
  const globalPackageVersion = () => SDK_VERSION_MARKER;
34002
34014
 
package/dist/passport.js CHANGED
@@ -11,7 +11,7 @@ import BN from 'bn.js';
11
11
  import * as encUtils from 'enc-utils';
12
12
  import { EventEmitter } from 'events';
13
13
  import { walletContracts } from '@0xsequence/abi';
14
- import { encodeSignature, decodeSignature } from '@0xsequence/config';
14
+ import { v1 } from '@0xsequence/core';
15
15
 
16
16
  /* tslint:disable */
17
17
  /* eslint-disable */
@@ -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.30.1' };
2194
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.30.2' };
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.30.1',
2250
+ sdkVersion: 'ts-immutable-sdk-0.30.2',
2251
2251
  });
2252
2252
  /**
2253
2253
  * Sets `sdkVersion` at the time of build
@@ -6945,7 +6945,7 @@ class AuthManager {
6945
6945
  nickname: idTokenPayload.nickname,
6946
6946
  },
6947
6947
  };
6948
- if (idTokenPayload?.passport.imx_eth_address) {
6948
+ if (idTokenPayload?.passport?.imx_eth_address) {
6949
6949
  user.imx = {
6950
6950
  ethAddress: idTokenPayload.passport.imx_eth_address,
6951
6951
  starkAddress: idTokenPayload.passport.imx_stark_address,
@@ -7132,21 +7132,11 @@ class AuthManager {
7132
7132
  this.deviceCredentialsManager.clearCredentials();
7133
7133
  }, PassportErrorType.LOGOUT_ERROR);
7134
7134
  }
7135
- async loginSilent({ forceRefresh } = { forceRefresh: false }) {
7136
- // eslint-disable-next-line arrow-body-style
7137
- return withPassportError(async () => {
7138
- return this.getUser({ forceRefresh });
7139
- }, PassportErrorType.SILENT_LOGIN_ERROR);
7140
- }
7141
7135
  /**
7142
7136
  * Get the user from the cache or refresh the token if it's expired.
7143
- * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
7144
- * throw an error if there's no refresh token.
7137
+ * return null if there's no refresh token.
7145
7138
  */
7146
- async getAuthenticatedUser({ forceRefresh = false }) {
7147
- if (forceRefresh) {
7148
- return this.refreshTokenAndUpdatePromise();
7149
- }
7139
+ async getAuthenticatedUser() {
7150
7140
  const oidcUser = await this.userManager.getUser();
7151
7141
  if (!oidcUser)
7152
7142
  return null;
@@ -7158,6 +7148,9 @@ class AuthManager {
7158
7148
  }
7159
7149
  return null;
7160
7150
  }
7151
+ async forceUserRefresh() {
7152
+ return this.refreshTokenAndUpdatePromise();
7153
+ }
7161
7154
  /**
7162
7155
  * Refreshes the token and returns the user.
7163
7156
  * If the token is already being refreshed, returns the existing promise.
@@ -7184,9 +7177,9 @@ class AuthManager {
7184
7177
  });
7185
7178
  return this.refreshingPromise;
7186
7179
  }
7187
- async getUser({ forceRefresh } = { forceRefresh: false }) {
7180
+ async getUser() {
7188
7181
  return withPassportError(async () => {
7189
- const user = await this.getAuthenticatedUser({ forceRefresh });
7182
+ const user = await this.getAuthenticatedUser();
7190
7183
  if (user)
7191
7184
  return user;
7192
7185
  const deviceToken = this.deviceCredentialsManager.getCredentials();
@@ -7797,7 +7790,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7797
7790
  async function forceUserRefresh(authManager) {
7798
7791
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
7799
7792
  await retryWithDelay(async () => {
7800
- const user = await authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
7793
+ const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
7801
7794
  if (user?.imx)
7802
7795
  return user;
7803
7796
  return Promise.reject(new Error('user wallet addresses not exist'));
@@ -8024,7 +8017,7 @@ class PassportImxProviderFactory {
8024
8017
  async getProvider() {
8025
8018
  let user = null;
8026
8019
  try {
8027
- user = await this.authManager.loginSilent();
8020
+ user = await this.authManager.getUser();
8028
8021
  }
8029
8022
  catch (e) {
8030
8023
  // eslint-disable-next-line no-console
@@ -8036,7 +8029,7 @@ class PassportImxProviderFactory {
8036
8029
  return this.createProviderInstance(user);
8037
8030
  }
8038
8031
  async getProviderSilent() {
8039
- const user = await this.authManager.loginSilent();
8032
+ const user = await this.authManager.getUser();
8040
8033
  if (!user) {
8041
8034
  return null;
8042
8035
  }
@@ -8419,10 +8412,13 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
8419
8412
  const ethsigNoType = await signer.signMessage(hashArray);
8420
8413
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8421
8414
  // Add metadata
8422
- const encodedSignature = encodeSignature({
8415
+ const encodedSignature = v1.signature.encodeSignature({
8416
+ version: 1,
8423
8417
  threshold: TRANSACTION_SIGNATURE_THRESHOLD,
8424
8418
  signers: [
8425
8419
  {
8420
+ isDynamic: false,
8421
+ unrecovered: true,
8426
8422
  weight: SIGNATURE_WEIGHT,
8427
8423
  signature: signedDigest,
8428
8424
  },
@@ -8437,8 +8433,8 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
8437
8433
  ]);
8438
8434
  };
8439
8435
  const decodeRelayerTypedDataSignature = (relayerSignature) => {
8440
- const signatureWithThreshold = `0000${relayerSignature}`;
8441
- return decodeSignature(signatureWithThreshold);
8436
+ const signatureWithThreshold = `0x0000${relayerSignature}`;
8437
+ return v1.signature.decodeSignature(signatureWithThreshold);
8442
8438
  };
8443
8439
  const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
8444
8440
  // Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
@@ -8454,11 +8450,14 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
8454
8450
  const ethsigNoType = await signer.signMessage(hashArray);
8455
8451
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
8456
8452
  const { signers } = decodeRelayerTypedDataSignature(relayerSignature);
8457
- return encodeSignature({
8453
+ return v1.signature.encodeSignature({
8454
+ version: 1,
8458
8455
  threshold: EIP712_SIGNATURE_THRESHOLD,
8459
8456
  signers: [
8460
8457
  ...signers,
8461
8458
  {
8459
+ isDynamic: false,
8460
+ unrecovered: true,
8462
8461
  weight: SIGNATURE_WEIGHT,
8463
8462
  signature: signedDigest,
8464
8463
  },
@@ -8601,7 +8600,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
8601
8600
  user = await authManager.refreshToken(credentials.refresh_token);
8602
8601
  }
8603
8602
  else {
8604
- user = await authManager.loginSilent({ forceRefresh: true });
8603
+ user = await authManager.forceUserRefresh();
8605
8604
  }
8606
8605
  if (!user?.zkEvm) {
8607
8606
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
@@ -8610,7 +8609,17 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
8610
8609
  }
8611
8610
 
8612
8611
  const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
8613
- const user = await authManager.getUser() || await authManager.getUserDeviceFlow() || await authManager.login();
8612
+ let user = null;
8613
+ try {
8614
+ user = await authManager.getUser();
8615
+ }
8616
+ catch (err) {
8617
+ // eslint-disable-next-line no-console
8618
+ console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
8619
+ }
8620
+ if (!user) {
8621
+ user = await authManager.getUserDeviceFlow() || await authManager.login();
8622
+ }
8614
8623
  if (!user.idToken) {
8615
8624
  throw new Error('User is missing idToken');
8616
8625
  }
@@ -9086,11 +9095,14 @@ class Passport {
9086
9095
  const { useCachedSession = false } = options || {};
9087
9096
  let user = null;
9088
9097
  try {
9089
- user = await this.authManager.loginSilent();
9098
+ user = await this.authManager.getUser();
9090
9099
  }
9091
9100
  catch (error) {
9101
+ if (useCachedSession) {
9102
+ throw error;
9103
+ }
9092
9104
  // eslint-disable-next-line no-console
9093
- console.warn('loginSilent failed with error:', error);
9105
+ console.warn('login failed to retrieve a cached user session', error);
9094
9106
  }
9095
9107
  if (!user && !useCachedSession) {
9096
9108
  user = await this.authManager.login();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.30.1",
4
+ "version": "0.30.2",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
8
8
  "dependencies": {
9
- "@0xsequence/abi": "^0.43.34",
10
- "@0xsequence/config": "^0.43.34",
9
+ "@0xsequence/abi": "^1.4.3",
10
+ "@0xsequence/core": "^1.4.3",
11
11
  "@biom3/design-tokens": "0.2.4-beta",
12
12
  "@biom3/react": "^0.10.12",
13
13
  "@ethersproject/abi": "^5.7.0",