@imtbl/sdk 1.13.5 → 1.13.6-alpha

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
@@ -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.13.5';
177
+ const SDK_VERSION$1 = '1.13.6-alpha';
178
178
  const getReferrer$1 = () => {
179
179
  if (isNode$1()) {
180
180
  return '';
@@ -10603,7 +10603,7 @@ class MultiRollupApiClients {
10603
10603
  }
10604
10604
 
10605
10605
  // eslint-disable-next-line @typescript-eslint/naming-convention
10606
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.13.5' };
10606
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.13.6-alpha' };
10607
10607
  const createConfig = ({ basePath, headers, }) => {
10608
10608
  if (!basePath.trim()) {
10609
10609
  throw Error('basePath can not be empty');
@@ -10675,7 +10675,7 @@ class APIError extends Error {
10675
10675
 
10676
10676
  /* eslint-disable implicit-arrow-linebreak */
10677
10677
  const defaultHeaders = {
10678
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.13.5',
10678
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.13.6-alpha',
10679
10679
  };
10680
10680
  /**
10681
10681
  * createAPIConfiguration to create a custom Configuration
@@ -11158,7 +11158,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11158
11158
  chainID,
11159
11159
  coreContractAddress,
11160
11160
  registrationContractAddress,
11161
- sdkVersion: 'ts-immutable-sdk-1.13.5',
11161
+ sdkVersion: 'ts-immutable-sdk-1.13.6-alpha',
11162
11162
  });
11163
11163
  /**
11164
11164
  * Sets `sdkVersion` at the time of build
@@ -15648,6 +15648,63 @@ const TransactionApprovalRequestChainTypeEnum = {
15648
15648
  Evm: 'evm'
15649
15649
  };
15650
15650
 
15651
+ /******************************************************************************
15652
+ Copyright (c) Microsoft Corporation.
15653
+
15654
+ Permission to use, copy, modify, and/or distribute this software for any
15655
+ purpose with or without fee is hereby granted.
15656
+
15657
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15658
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15659
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15660
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15661
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15662
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15663
+ PERFORMANCE OF THIS SOFTWARE.
15664
+ ***************************************************************************** */
15665
+ /* global Reflect, Promise, SuppressedError, Symbol */
15666
+
15667
+
15668
+ function __rest(s, e) {
15669
+ var t = {};
15670
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15671
+ t[p] = s[p];
15672
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15673
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15674
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
15675
+ t[p[i]] = s[p[i]];
15676
+ }
15677
+ return t;
15678
+ }
15679
+
15680
+ function __awaiter$4(thisArg, _arguments, P, generator) {
15681
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15682
+ return new (P || (P = Promise))(function (resolve, reject) {
15683
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15684
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15685
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15686
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15687
+ });
15688
+ }
15689
+
15690
+ function __classPrivateFieldGet(receiver, state, kind, f) {
15691
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15692
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
15693
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15694
+ }
15695
+
15696
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
15697
+ if (kind === "m") throw new TypeError("Private method is not writable");
15698
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15699
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15700
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15701
+ }
15702
+
15703
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
15704
+ var e = new Error(message);
15705
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
15706
+ };
15707
+
15651
15708
  var PassportErrorType;
15652
15709
  (function (PassportErrorType) {
15653
15710
  PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
@@ -15670,19 +15727,19 @@ function isAPIError(error) {
15670
15727
  return 'code' in error && 'message' in error;
15671
15728
  }
15672
15729
  class PassportError extends Error {
15673
- type;
15674
15730
  constructor(message, type) {
15675
15731
  super(message);
15676
15732
  this.type = type;
15677
15733
  }
15678
15734
  }
15679
- const withPassportError = async (fn, customErrorType) => {
15735
+ const withPassportError = (fn, customErrorType) => __awaiter$4(void 0, void 0, void 0, function* () {
15736
+ var _a;
15680
15737
  try {
15681
- return await fn();
15738
+ return yield fn();
15682
15739
  }
15683
15740
  catch (error) {
15684
15741
  let errorMessage;
15685
- if (globalAxios$1.isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
15742
+ if (globalAxios$1.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) && isAPIError(error.response.data)) {
15686
15743
  errorMessage = error.response.data.message;
15687
15744
  }
15688
15745
  else {
@@ -15690,7 +15747,7 @@ const withPassportError = async (fn, customErrorType) => {
15690
15747
  }
15691
15748
  throw new PassportError(errorMessage, customErrorType);
15692
15749
  }
15693
- };
15750
+ });
15694
15751
 
15695
15752
  /**
15696
15753
  * Enum representing different chain IDs.
@@ -15740,9 +15797,10 @@ class DeviceCredentialsManager {
15740
15797
  return false;
15741
15798
  }
15742
15799
  isTokenValid(jwt) {
15800
+ var _a;
15743
15801
  try {
15744
15802
  const tokenPayload = jwt_decode(jwt);
15745
- const expiresAt = tokenPayload.exp ?? 0;
15803
+ const expiresAt = (_a = tokenPayload.exp) !== null && _a !== void 0 ? _a : 0;
15746
15804
  const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
15747
15805
  return expiresAt > now;
15748
15806
  }
@@ -15764,7 +15822,8 @@ class DeviceCredentialsManager {
15764
15822
  }
15765
15823
  }
15766
15824
 
15767
- const shouldLog = process?.env?.JEST_WORKER_ID === undefined;
15825
+ var _a;
15826
+ const shouldLog = ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.JEST_WORKER_ID) === undefined;
15768
15827
  const warn = (...args) => {
15769
15828
  if (shouldLog) {
15770
15829
  // eslint-disable-next-line no-console
@@ -15848,171 +15907,127 @@ function sha256(buffer) {
15848
15907
  return crypto__namespace.createHash('sha256').update(buffer).digest();
15849
15908
  }
15850
15909
  class AuthManager {
15851
- userManager;
15852
- deviceCredentialsManager;
15853
- config;
15854
- logoutMode;
15855
- /**
15856
- * Promise that is used to prevent multiple concurrent calls to the refresh token endpoint.
15857
- */
15858
- refreshingPromise = null;
15859
15910
  constructor(config) {
15911
+ /**
15912
+ * Promise that is used to prevent multiple concurrent calls to the refresh token endpoint.
15913
+ */
15914
+ this.refreshingPromise = null;
15860
15915
  this.config = config;
15861
15916
  this.userManager = new oidcClientTs.UserManager(getAuthConfiguration(config));
15862
15917
  this.deviceCredentialsManager = new DeviceCredentialsManager();
15863
15918
  this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
15864
15919
  }
15865
- static mapOidcUserToDomainModel = (oidcUser) => {
15866
- let passport;
15867
- if (oidcUser.id_token) {
15868
- passport = jwt_decode(oidcUser.id_token)?.passport;
15869
- }
15870
- const user = {
15871
- expired: oidcUser.expired,
15872
- idToken: oidcUser.id_token,
15873
- accessToken: oidcUser.access_token,
15874
- refreshToken: oidcUser.refresh_token,
15875
- profile: {
15876
- sub: oidcUser.profile.sub,
15877
- email: oidcUser.profile.email,
15878
- nickname: oidcUser.profile.nickname,
15879
- },
15880
- };
15881
- if (passport?.imx_eth_address) {
15882
- user.imx = {
15883
- ethAddress: passport.imx_eth_address,
15884
- starkAddress: passport.imx_stark_address,
15885
- userAdminAddress: passport.imx_user_admin_address,
15886
- };
15887
- }
15888
- if (passport?.zkevm_eth_address) {
15889
- user.zkEvm = {
15890
- ethAddress: passport?.zkevm_eth_address,
15891
- userAdminAddress: passport?.zkevm_user_admin_address,
15892
- };
15893
- }
15894
- return user;
15895
- };
15896
- static mapDeviceTokenResponseToOidcUser = (tokenResponse) => {
15897
- const idTokenPayload = jwt_decode(tokenResponse.id_token);
15898
- return new oidcClientTs.User({
15899
- id_token: tokenResponse.id_token,
15900
- access_token: tokenResponse.access_token,
15901
- refresh_token: tokenResponse.refresh_token,
15902
- token_type: tokenResponse.token_type,
15903
- profile: {
15904
- sub: idTokenPayload.sub,
15905
- iss: idTokenPayload.iss,
15906
- aud: idTokenPayload.aud,
15907
- exp: idTokenPayload.exp,
15908
- iat: idTokenPayload.iat,
15909
- email: idTokenPayload.email,
15910
- nickname: idTokenPayload.nickname,
15911
- passport: idTokenPayload.passport,
15912
- },
15913
- });
15914
- };
15915
15920
  /**
15916
15921
  * login
15917
15922
  * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
15918
15923
  */
15919
- async login(anonymousId) {
15920
- return withPassportError(async () => {
15921
- const rid = getDetail(Detail$1.RUNTIME_ID);
15922
- const popupWindowFeatures = { width: 410, height: 450 };
15923
- const oidcUser = await this.userManager.signinPopup({
15924
- extraQueryParams: {
15925
- ...(this.userManager.settings?.extraQueryParams ?? {}),
15926
- rid: rid || '',
15927
- third_party_a_id: anonymousId || '',
15928
- },
15929
- popupWindowFeatures,
15930
- });
15931
- return AuthManager.mapOidcUserToDomainModel(oidcUser);
15932
- }, PassportErrorType.AUTHENTICATION_ERROR);
15924
+ login(anonymousId) {
15925
+ return __awaiter$4(this, void 0, void 0, function* () {
15926
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
15927
+ var _a, _b;
15928
+ const rid = getDetail(Detail$1.RUNTIME_ID);
15929
+ const popupWindowFeatures = { width: 410, height: 450 };
15930
+ const oidcUser = yield this.userManager.signinPopup({
15931
+ extraQueryParams: Object.assign(Object.assign({}, ((_b = (_a = this.userManager.settings) === null || _a === void 0 ? void 0 : _a.extraQueryParams) !== null && _b !== void 0 ? _b : {})), { rid: rid || '', third_party_a_id: anonymousId || '' }),
15932
+ popupWindowFeatures,
15933
+ });
15934
+ return AuthManager.mapOidcUserToDomainModel(oidcUser);
15935
+ }), PassportErrorType.AUTHENTICATION_ERROR);
15936
+ });
15933
15937
  }
15934
- async getUserOrLogin() {
15935
- let user = null;
15936
- try {
15937
- user = await this.getUser();
15938
- }
15939
- catch (err) {
15940
- logger$f.warn('Failed to retrieve a cached user session', err);
15941
- }
15942
- return user || this.login();
15938
+ getUserOrLogin() {
15939
+ return __awaiter$4(this, void 0, void 0, function* () {
15940
+ let user = null;
15941
+ try {
15942
+ user = yield this.getUser();
15943
+ }
15944
+ catch (err) {
15945
+ logger$f.warn('Failed to retrieve a cached user session', err);
15946
+ }
15947
+ return user || this.login();
15948
+ });
15943
15949
  }
15944
- async loginCallback() {
15945
- return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
15950
+ loginCallback() {
15951
+ return __awaiter$4(this, void 0, void 0, function* () {
15952
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () { return this.userManager.signinPopupCallback(); }), PassportErrorType.AUTHENTICATION_ERROR);
15953
+ });
15946
15954
  }
15947
15955
  /**
15948
15956
  * loginWithDeviceFlow
15949
15957
  * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
15950
15958
  */
15951
- async loginWithDeviceFlow(anonymousId) {
15952
- return withPassportError(async () => {
15953
- const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/device/code`, {
15954
- client_id: this.config.oidcConfiguration.clientId,
15955
- scope: this.config.oidcConfiguration.scope,
15956
- audience: this.config.oidcConfiguration.audience,
15957
- }, formUrlEncodedHeader);
15958
- const rid = getDetail(Detail$1.RUNTIME_ID);
15959
- return {
15960
- code: response.data.user_code,
15961
- deviceCode: response.data.device_code,
15962
- url: `${response.data.verification_uri_complete}${rid ? `&rid=${rid}` : ''}${anonymousId ? `&third_party_a_id=${anonymousId}` : ''}`,
15963
- interval: response.data.interval,
15964
- };
15965
- }, PassportErrorType.AUTHENTICATION_ERROR);
15959
+ loginWithDeviceFlow(anonymousId) {
15960
+ return __awaiter$4(this, void 0, void 0, function* () {
15961
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
15962
+ const response = yield globalAxios$1.post(`${this.config.authenticationDomain}/oauth/device/code`, {
15963
+ client_id: this.config.oidcConfiguration.clientId,
15964
+ scope: this.config.oidcConfiguration.scope,
15965
+ audience: this.config.oidcConfiguration.audience,
15966
+ }, formUrlEncodedHeader);
15967
+ const rid = getDetail(Detail$1.RUNTIME_ID);
15968
+ return {
15969
+ code: response.data.user_code,
15970
+ deviceCode: response.data.device_code,
15971
+ url: `${response.data.verification_uri_complete}${rid ? `&rid=${rid}` : ''}${anonymousId ? `&third_party_a_id=${anonymousId}` : ''}`,
15972
+ interval: response.data.interval,
15973
+ };
15974
+ }), PassportErrorType.AUTHENTICATION_ERROR);
15975
+ });
15966
15976
  }
15967
15977
  /* eslint-disable no-await-in-loop */
15968
- async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
15969
- return withPassportError(async () => {
15970
- const startTime = Date.now();
15971
- const loopCondition = true;
15972
- while (loopCondition) {
15973
- if (timeoutMs != null && Date.now() - startTime > timeoutMs) {
15974
- throw new Error('Timed out');
15975
- }
15976
- await wait$1(interval * 1000);
15977
- try {
15978
- const tokenResponse = await this.getDeviceFlowToken(deviceCode);
15979
- const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
15980
- const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
15981
- await this.userManager.storeUser(oidcUser);
15982
- return user;
15983
- }
15984
- catch (error) {
15985
- if (globalAxios$1.isAxiosError(error)) {
15986
- const responseError = error.response?.data;
15987
- switch (responseError.error) {
15988
- case 'authorization_pending':
15989
- break;
15990
- case 'slow_down':
15991
- break;
15992
- case 'expired_token':
15993
- throw new Error('Token expired, please log in again');
15994
- case 'access_denied':
15995
- throw new Error('User denied access');
15996
- default:
15997
- throw new Error('Error getting token');
15998
- }
15978
+ loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
15979
+ return __awaiter$4(this, void 0, void 0, function* () {
15980
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
15981
+ var _a;
15982
+ const startTime = Date.now();
15983
+ const loopCondition = true;
15984
+ while (loopCondition) {
15985
+ if (timeoutMs != null && Date.now() - startTime > timeoutMs) {
15986
+ throw new Error('Timed out');
15999
15987
  }
16000
- else {
16001
- throw error;
15988
+ yield wait$1(interval * 1000);
15989
+ try {
15990
+ const tokenResponse = yield this.getDeviceFlowToken(deviceCode);
15991
+ const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
15992
+ const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
15993
+ yield this.userManager.storeUser(oidcUser);
15994
+ return user;
15995
+ }
15996
+ catch (error) {
15997
+ if (globalAxios$1.isAxiosError(error)) {
15998
+ const responseError = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
15999
+ switch (responseError.error) {
16000
+ case 'authorization_pending':
16001
+ break;
16002
+ case 'slow_down':
16003
+ break;
16004
+ case 'expired_token':
16005
+ throw new Error('Token expired, please log in again');
16006
+ case 'access_denied':
16007
+ throw new Error('User denied access');
16008
+ default:
16009
+ throw new Error('Error getting token');
16010
+ }
16011
+ }
16012
+ else {
16013
+ throw error;
16014
+ }
16002
16015
  }
16003
16016
  }
16004
- }
16005
- throw new Error('Failed to get credentials');
16006
- }, PassportErrorType.AUTHENTICATION_ERROR);
16017
+ throw new Error('Failed to get credentials');
16018
+ }), PassportErrorType.AUTHENTICATION_ERROR);
16019
+ });
16007
16020
  }
16008
16021
  /* eslint-enable no-await-in-loop */
16009
- async getDeviceFlowToken(deviceCode) {
16010
- const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
16011
- client_id: this.config.oidcConfiguration.clientId,
16012
- grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
16013
- device_code: deviceCode,
16014
- }, formUrlEncodedHeader);
16015
- return response.data;
16022
+ getDeviceFlowToken(deviceCode) {
16023
+ return __awaiter$4(this, void 0, void 0, function* () {
16024
+ const response = yield globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
16025
+ client_id: this.config.oidcConfiguration.clientId,
16026
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
16027
+ device_code: deviceCode,
16028
+ }, formUrlEncodedHeader);
16029
+ return response.data;
16030
+ });
16016
16031
  }
16017
16032
  getPKCEAuthorizationUrl() {
16018
16033
  const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
@@ -16030,42 +16045,50 @@ class AuthManager {
16030
16045
  + `&state=${state}`
16031
16046
  + `&audience=${this.config.oidcConfiguration.audience}`;
16032
16047
  }
16033
- async loginWithPKCEFlowCallback(authorizationCode, state) {
16034
- return withPassportError(async () => {
16035
- const pkceData = this.deviceCredentialsManager.getPKCEData();
16036
- if (!pkceData) {
16037
- throw new Error('No code verifier or state for PKCE');
16038
- }
16039
- if (state !== pkceData.state) {
16040
- throw new Error('Provided state does not match stored state');
16041
- }
16042
- const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
16043
- const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
16044
- const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
16045
- await this.userManager.storeUser(oidcUser);
16046
- return user;
16047
- }, PassportErrorType.AUTHENTICATION_ERROR);
16048
- }
16049
- async getPKCEToken(authorizationCode, codeVerifier) {
16050
- const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
16051
- client_id: this.config.oidcConfiguration.clientId,
16052
- grant_type: 'authorization_code',
16053
- code_verifier: codeVerifier,
16054
- code: authorizationCode,
16055
- redirect_uri: this.config.oidcConfiguration.redirectUri,
16056
- }, formUrlEncodedHeader);
16057
- return response.data;
16048
+ loginWithPKCEFlowCallback(authorizationCode, state) {
16049
+ return __awaiter$4(this, void 0, void 0, function* () {
16050
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
16051
+ const pkceData = this.deviceCredentialsManager.getPKCEData();
16052
+ if (!pkceData) {
16053
+ throw new Error('No code verifier or state for PKCE');
16054
+ }
16055
+ if (state !== pkceData.state) {
16056
+ throw new Error('Provided state does not match stored state');
16057
+ }
16058
+ const tokenResponse = yield this.getPKCEToken(authorizationCode, pkceData.verifier);
16059
+ const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
16060
+ const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
16061
+ yield this.userManager.storeUser(oidcUser);
16062
+ return user;
16063
+ }), PassportErrorType.AUTHENTICATION_ERROR);
16064
+ });
16058
16065
  }
16059
- async logout() {
16060
- return withPassportError(async () => {
16061
- if (this.logoutMode === 'silent') {
16062
- return this.userManager.signoutSilent();
16063
- }
16064
- return this.userManager.signoutRedirect();
16065
- }, PassportErrorType.LOGOUT_ERROR);
16066
+ getPKCEToken(authorizationCode, codeVerifier) {
16067
+ return __awaiter$4(this, void 0, void 0, function* () {
16068
+ const response = yield globalAxios$1.post(`${this.config.authenticationDomain}/oauth/token`, {
16069
+ client_id: this.config.oidcConfiguration.clientId,
16070
+ grant_type: 'authorization_code',
16071
+ code_verifier: codeVerifier,
16072
+ code: authorizationCode,
16073
+ redirect_uri: this.config.oidcConfiguration.redirectUri,
16074
+ }, formUrlEncodedHeader);
16075
+ return response.data;
16076
+ });
16077
+ }
16078
+ logout() {
16079
+ return __awaiter$4(this, void 0, void 0, function* () {
16080
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
16081
+ if (this.logoutMode === 'silent') {
16082
+ return this.userManager.signoutSilent();
16083
+ }
16084
+ return this.userManager.signoutRedirect();
16085
+ }), PassportErrorType.LOGOUT_ERROR);
16086
+ });
16066
16087
  }
16067
- async removeUser() {
16068
- return this.userManager.removeUser();
16088
+ removeUser() {
16089
+ return __awaiter$4(this, void 0, void 0, function* () {
16090
+ return this.userManager.removeUser();
16091
+ });
16069
16092
  }
16070
16093
  getDeviceFlowEndSessionEndpoint() {
16071
16094
  const { authenticationDomain, oidcConfiguration } = this.config;
@@ -16076,54 +16099,60 @@ class AuthManager {
16076
16099
  }
16077
16100
  return endSessionEndpoint;
16078
16101
  }
16079
- async logoutSilentCallback(url) {
16080
- return this.userManager.signoutSilentCallback(url);
16102
+ logoutSilentCallback(url) {
16103
+ return __awaiter$4(this, void 0, void 0, function* () {
16104
+ return this.userManager.signoutSilentCallback(url);
16105
+ });
16081
16106
  }
16082
16107
  forceUserRefreshInBackground() {
16083
16108
  this.refreshTokenAndUpdatePromise().catch((error) => {
16084
16109
  logger$f.warn('Failed to refresh user token', error);
16085
16110
  });
16086
16111
  }
16087
- async forceUserRefresh() {
16088
- return this.refreshTokenAndUpdatePromise();
16112
+ forceUserRefresh() {
16113
+ return __awaiter$4(this, void 0, void 0, function* () {
16114
+ return this.refreshTokenAndUpdatePromise();
16115
+ });
16089
16116
  }
16090
16117
  /**
16091
16118
  * Refreshes the token and returns the user.
16092
16119
  * If the token is already being refreshed, returns the existing promise.
16093
16120
  */
16094
- async refreshTokenAndUpdatePromise() {
16095
- if (this.refreshingPromise)
16096
- return this.refreshingPromise;
16097
- // eslint-disable-next-line no-async-promise-executor
16098
- this.refreshingPromise = new Promise(async (resolve, reject) => {
16099
- try {
16100
- const newOidcUser = await this.userManager.signinSilent();
16101
- if (newOidcUser) {
16102
- resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
16103
- return;
16104
- }
16105
- resolve(null);
16106
- }
16107
- catch (err) {
16108
- let passportErrorType = PassportErrorType.AUTHENTICATION_ERROR;
16109
- let errorMessage = 'Failed to refresh token';
16110
- if (err instanceof oidcClientTs.ErrorTimeout) {
16111
- passportErrorType = PassportErrorType.SILENT_LOGIN_ERROR;
16121
+ refreshTokenAndUpdatePromise() {
16122
+ return __awaiter$4(this, void 0, void 0, function* () {
16123
+ if (this.refreshingPromise)
16124
+ return this.refreshingPromise;
16125
+ // eslint-disable-next-line no-async-promise-executor
16126
+ this.refreshingPromise = new Promise((resolve, reject) => __awaiter$4(this, void 0, void 0, function* () {
16127
+ try {
16128
+ const newOidcUser = yield this.userManager.signinSilent();
16129
+ if (newOidcUser) {
16130
+ resolve(AuthManager.mapOidcUserToDomainModel(newOidcUser));
16131
+ return;
16132
+ }
16133
+ resolve(null);
16112
16134
  }
16113
- else if (err instanceof oidcClientTs.ErrorResponse) {
16114
- passportErrorType = PassportErrorType.NOT_LOGGED_IN_ERROR;
16115
- errorMessage = `${err.message}: ${err.error_description}`;
16135
+ catch (err) {
16136
+ let passportErrorType = PassportErrorType.AUTHENTICATION_ERROR;
16137
+ let errorMessage = 'Failed to refresh token';
16138
+ if (err instanceof oidcClientTs.ErrorTimeout) {
16139
+ passportErrorType = PassportErrorType.SILENT_LOGIN_ERROR;
16140
+ }
16141
+ else if (err instanceof oidcClientTs.ErrorResponse) {
16142
+ passportErrorType = PassportErrorType.NOT_LOGGED_IN_ERROR;
16143
+ errorMessage = `${err.message}: ${err.error_description}`;
16144
+ }
16145
+ else if (err instanceof Error) {
16146
+ errorMessage = err.message;
16147
+ }
16148
+ reject(new PassportError(errorMessage, passportErrorType));
16116
16149
  }
16117
- else if (err instanceof Error) {
16118
- errorMessage = err.message;
16150
+ finally {
16151
+ this.refreshingPromise = null; // Reset the promise after completion
16119
16152
  }
16120
- reject(new PassportError(errorMessage, passportErrorType));
16121
- }
16122
- finally {
16123
- this.refreshingPromise = null; // Reset the promise after completion
16124
- }
16153
+ }));
16154
+ return this.refreshingPromise;
16125
16155
  });
16126
- return this.refreshingPromise;
16127
16156
  }
16128
16157
  /**
16129
16158
  *
@@ -16138,46 +16167,103 @@ class AuthManager {
16138
16167
  * 3. Attempt to refresh the User if a refresh token is present.
16139
16168
  * 4. Return null if no valid User can be obtained.
16140
16169
  */
16141
- async getUser(typeAssertion = (user) => true) {
16142
- if (this.refreshingPromise) {
16143
- const user = await this.refreshingPromise;
16144
- if (user && typeAssertion(user)) {
16145
- return user;
16170
+ getUser(typeAssertion = (user) => true) {
16171
+ return __awaiter$4(this, void 0, void 0, function* () {
16172
+ if (this.refreshingPromise) {
16173
+ const user = yield this.refreshingPromise;
16174
+ if (user && typeAssertion(user)) {
16175
+ return user;
16176
+ }
16177
+ return null;
16146
16178
  }
16147
- return null;
16148
- }
16149
- const oidcUser = await this.userManager.getUser();
16150
- if (!oidcUser)
16151
- return null;
16152
- if (!isTokenExpired(oidcUser)) {
16153
- const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
16154
- if (user && typeAssertion(user)) {
16155
- return user;
16179
+ const oidcUser = yield this.userManager.getUser();
16180
+ if (!oidcUser)
16181
+ return null;
16182
+ if (!isTokenExpired(oidcUser)) {
16183
+ const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
16184
+ if (user && typeAssertion(user)) {
16185
+ return user;
16186
+ }
16156
16187
  }
16157
- }
16158
- if (oidcUser.refresh_token) {
16159
- const user = await this.refreshTokenAndUpdatePromise();
16160
- if (user && typeAssertion(user)) {
16161
- return user;
16188
+ if (oidcUser.refresh_token) {
16189
+ const user = yield this.refreshTokenAndUpdatePromise();
16190
+ if (user && typeAssertion(user)) {
16191
+ return user;
16192
+ }
16162
16193
  }
16163
- }
16164
- return null;
16194
+ return null;
16195
+ });
16165
16196
  }
16166
- async getUserZkEvm() {
16167
- const user = await this.getUser(isUserZkEvm);
16168
- if (!user) {
16169
- throw new Error('Failed to obtain a User with the required ZkEvm attributes');
16170
- }
16171
- return user;
16197
+ getUserZkEvm() {
16198
+ return __awaiter$4(this, void 0, void 0, function* () {
16199
+ const user = yield this.getUser(isUserZkEvm);
16200
+ if (!user) {
16201
+ throw new Error('Failed to obtain a User with the required ZkEvm attributes');
16202
+ }
16203
+ return user;
16204
+ });
16172
16205
  }
16173
- async getUserImx() {
16174
- const user = await this.getUser(isUserImx);
16175
- if (!user) {
16176
- throw new Error('Failed to obtain a User with the required IMX attributes');
16177
- }
16178
- return user;
16206
+ getUserImx() {
16207
+ return __awaiter$4(this, void 0, void 0, function* () {
16208
+ const user = yield this.getUser(isUserImx);
16209
+ if (!user) {
16210
+ throw new Error('Failed to obtain a User with the required IMX attributes');
16211
+ }
16212
+ return user;
16213
+ });
16179
16214
  }
16180
16215
  }
16216
+ AuthManager.mapOidcUserToDomainModel = (oidcUser) => {
16217
+ var _a;
16218
+ let passport;
16219
+ if (oidcUser.id_token) {
16220
+ passport = (_a = jwt_decode(oidcUser.id_token)) === null || _a === void 0 ? void 0 : _a.passport;
16221
+ }
16222
+ const user = {
16223
+ expired: oidcUser.expired,
16224
+ idToken: oidcUser.id_token,
16225
+ accessToken: oidcUser.access_token,
16226
+ refreshToken: oidcUser.refresh_token,
16227
+ profile: {
16228
+ sub: oidcUser.profile.sub,
16229
+ email: oidcUser.profile.email,
16230
+ nickname: oidcUser.profile.nickname,
16231
+ },
16232
+ };
16233
+ if (passport === null || passport === void 0 ? void 0 : passport.imx_eth_address) {
16234
+ user.imx = {
16235
+ ethAddress: passport.imx_eth_address,
16236
+ starkAddress: passport.imx_stark_address,
16237
+ userAdminAddress: passport.imx_user_admin_address,
16238
+ };
16239
+ }
16240
+ if (passport === null || passport === void 0 ? void 0 : passport.zkevm_eth_address) {
16241
+ user.zkEvm = {
16242
+ ethAddress: passport === null || passport === void 0 ? void 0 : passport.zkevm_eth_address,
16243
+ userAdminAddress: passport === null || passport === void 0 ? void 0 : passport.zkevm_user_admin_address,
16244
+ };
16245
+ }
16246
+ return user;
16247
+ };
16248
+ AuthManager.mapDeviceTokenResponseToOidcUser = (tokenResponse) => {
16249
+ const idTokenPayload = jwt_decode(tokenResponse.id_token);
16250
+ return new oidcClientTs.User({
16251
+ id_token: tokenResponse.id_token,
16252
+ access_token: tokenResponse.access_token,
16253
+ refresh_token: tokenResponse.refresh_token,
16254
+ token_type: tokenResponse.token_type,
16255
+ profile: {
16256
+ sub: idTokenPayload.sub,
16257
+ iss: idTokenPayload.iss,
16258
+ aud: idTokenPayload.aud,
16259
+ exp: idTokenPayload.exp,
16260
+ iat: idTokenPayload.iat,
16261
+ email: idTokenPayload.email,
16262
+ nickname: idTokenPayload.nickname,
16263
+ passport: idTokenPayload.passport,
16264
+ },
16265
+ });
16266
+ };
16181
16267
 
16182
16268
  const lazyLoad = (promiseToAwait, initialiseFunction) => promiseToAwait().then(initialiseFunction);
16183
16269
  const lazyDocumentReady = (initialiseFunction) => {
@@ -16200,8 +16286,6 @@ const lazyDocumentReady = (initialiseFunction) => {
16200
16286
 
16201
16287
  const MAINNET = 'mainnet';
16202
16288
  class MagicAdapter {
16203
- config;
16204
- lazyMagicClient;
16205
16289
  constructor(config) {
16206
16290
  this.config = config;
16207
16291
  if (typeof window !== 'undefined') {
@@ -16221,320 +16305,341 @@ class MagicAdapter {
16221
16305
  }
16222
16306
  return this.lazyMagicClient;
16223
16307
  }
16224
- async login(idToken) {
16225
- return withPassportError(async () => {
16226
- const magicClient = await this.magicClient;
16227
- await magicClient.openid.loginWithOIDC({
16228
- jwt: idToken,
16229
- providerId: this.config.magicProviderId,
16230
- });
16231
- return magicClient.rpcProvider;
16232
- }, PassportErrorType.WALLET_CONNECTION_ERROR);
16308
+ login(idToken) {
16309
+ return __awaiter$4(this, void 0, void 0, function* () {
16310
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
16311
+ const magicClient = yield this.magicClient;
16312
+ yield magicClient.openid.loginWithOIDC({
16313
+ jwt: idToken,
16314
+ providerId: this.config.magicProviderId,
16315
+ });
16316
+ return magicClient.rpcProvider;
16317
+ }), PassportErrorType.WALLET_CONNECTION_ERROR);
16318
+ });
16233
16319
  }
16234
- async logout() {
16235
- const magicClient = await this.magicClient;
16236
- if (magicClient.user) {
16237
- await magicClient.user.logout();
16238
- }
16320
+ logout() {
16321
+ return __awaiter$4(this, void 0, void 0, function* () {
16322
+ const magicClient = yield this.magicClient;
16323
+ if (magicClient.user) {
16324
+ yield magicClient.user.logout();
16325
+ }
16326
+ });
16239
16327
  }
16240
16328
  }
16241
16329
 
16242
- const getStarkSigner = async (signer) => withPassportError(async () => {
16243
- const privateKey = await coreSdk.generateLegacyStarkPrivateKey(signer);
16244
- return coreSdk.createStarkSigner(privateKey);
16245
- }, PassportErrorType.WALLET_CONNECTION_ERROR);
16330
+ const getStarkSigner = (signer) => __awaiter$4(void 0, void 0, void 0, function* () {
16331
+ return withPassportError(() => __awaiter$4(void 0, void 0, void 0, function* () {
16332
+ const privateKey = yield coreSdk.generateLegacyStarkPrivateKey(signer);
16333
+ return coreSdk.createStarkSigner(privateKey);
16334
+ }), PassportErrorType.WALLET_CONNECTION_ERROR);
16335
+ });
16246
16336
 
16247
- async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
16248
- return withPassportError(async () => {
16249
- const { ethAddress } = user.imx;
16250
- const transferAmount = request.amount;
16251
- const signableResult = await exchangesApi.getExchangeSignableTransfer({
16252
- id: request.transactionID,
16253
- getSignableTransferRequest: {
16254
- sender: ethAddress,
16255
- token: convertToSignableToken(request),
16256
- amount: transferAmount,
16257
- receiver: request.receiver,
16258
- },
16259
- });
16260
- const starkAddress = await starkSigner.getAddress();
16261
- const { payload_hash: payloadHash } = signableResult.data;
16262
- const starkSignature = await starkSigner.signMessage(payloadHash);
16263
- const transferSigningParams = {
16264
- sender_stark_key: signableResult.data.sender_stark_key || starkAddress,
16265
- sender_vault_id: signableResult.data.sender_vault_id,
16266
- receiver_stark_key: signableResult.data.receiver_stark_key,
16267
- receiver_vault_id: signableResult.data.receiver_vault_id,
16268
- asset_id: signableResult.data.asset_id,
16269
- amount: signableResult.data.amount,
16270
- nonce: signableResult.data.nonce,
16271
- expiration_timestamp: signableResult.data.expiration_timestamp,
16272
- stark_signature: starkSignature,
16273
- };
16274
- const headers = {
16275
- // eslint-disable-next-line @typescript-eslint/naming-convention
16276
- Authorization: `Bearer ${user.accessToken}`,
16277
- };
16278
- const response = await exchangesApi.createExchangeTransfer({
16279
- id: request.transactionID,
16280
- createTransferRequest: transferSigningParams,
16281
- }, { headers });
16282
- return {
16283
- sent_signature: response?.data.sent_signature,
16284
- status: response?.data.status?.toString(),
16285
- time: response?.data.time,
16286
- transfer_id: response?.data.transfer_id,
16287
- };
16288
- }, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
16337
+ function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
16338
+ return __awaiter$4(this, void 0, void 0, function* () {
16339
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
16340
+ var _a;
16341
+ const { ethAddress } = user.imx;
16342
+ const transferAmount = request.amount;
16343
+ const signableResult = yield exchangesApi.getExchangeSignableTransfer({
16344
+ id: request.transactionID,
16345
+ getSignableTransferRequest: {
16346
+ sender: ethAddress,
16347
+ token: convertToSignableToken(request),
16348
+ amount: transferAmount,
16349
+ receiver: request.receiver,
16350
+ },
16351
+ });
16352
+ const starkAddress = yield starkSigner.getAddress();
16353
+ const { payload_hash: payloadHash } = signableResult.data;
16354
+ const starkSignature = yield starkSigner.signMessage(payloadHash);
16355
+ const transferSigningParams = {
16356
+ sender_stark_key: signableResult.data.sender_stark_key || starkAddress,
16357
+ sender_vault_id: signableResult.data.sender_vault_id,
16358
+ receiver_stark_key: signableResult.data.receiver_stark_key,
16359
+ receiver_vault_id: signableResult.data.receiver_vault_id,
16360
+ asset_id: signableResult.data.asset_id,
16361
+ amount: signableResult.data.amount,
16362
+ nonce: signableResult.data.nonce,
16363
+ expiration_timestamp: signableResult.data.expiration_timestamp,
16364
+ stark_signature: starkSignature,
16365
+ };
16366
+ const headers = {
16367
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16368
+ Authorization: `Bearer ${user.accessToken}`,
16369
+ };
16370
+ const response = yield exchangesApi.createExchangeTransfer({
16371
+ id: request.transactionID,
16372
+ createTransferRequest: transferSigningParams,
16373
+ }, { headers });
16374
+ return {
16375
+ sent_signature: response === null || response === void 0 ? void 0 : response.data.sent_signature,
16376
+ status: (_a = response === null || response === void 0 ? void 0 : response.data.status) === null || _a === void 0 ? void 0 : _a.toString(),
16377
+ time: response === null || response === void 0 ? void 0 : response.data.time,
16378
+ transfer_id: response === null || response === void 0 ? void 0 : response.data.transfer_id,
16379
+ };
16380
+ }), PassportErrorType.EXCHANGE_TRANSFER_ERROR);
16381
+ });
16289
16382
  }
16290
16383
 
16291
16384
  const ERC721$1 = 'ERC721';
16292
- async function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
16293
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
16294
- const { ethAddress } = user.imx;
16295
- const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
16296
- const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
16297
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16298
- const getSignableOrderRequestV3 = {
16299
- user: ethAddress,
16300
- amount_buy: amountBuy,
16301
- token_buy: convertToSignableToken(request.buy),
16302
- amount_sell: amountSell,
16303
- token_sell: convertToSignableToken(request.sell),
16304
- fees: request.fees,
16305
- split_fees: true,
16306
- expiration_timestamp: request.expiration_timestamp,
16307
- };
16308
- const getSignableOrderResponse = await ordersApi.getSignableOrder({
16309
- getSignableOrderRequestV3,
16310
- }, { headers });
16311
- await guardianClient.evaluateImxTransaction({
16312
- payloadHash: getSignableOrderResponse.data.payload_hash,
16313
- });
16314
- const { payload_hash: payloadHash } = getSignableOrderResponse.data;
16315
- const starkSignature = await starkSigner.signMessage(payloadHash);
16316
- const signableResultData = getSignableOrderResponse.data;
16317
- const orderParams = {
16318
- createOrderRequest: {
16319
- include_fees: true,
16385
+ function createOrder$1({ starkSigner, user, request, ordersApi, guardianClient, }) {
16386
+ return __awaiter$4(this, void 0, void 0, function* () {
16387
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(() => __awaiter$4(this, void 0, void 0, function* () {
16388
+ const { ethAddress } = user.imx;
16389
+ const amountSell = request.sell.type === ERC721$1 ? '1' : request.sell.amount;
16390
+ const amountBuy = request.buy.type === ERC721$1 ? '1' : request.buy.amount;
16391
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
16392
+ const getSignableOrderRequestV3 = {
16393
+ user: ethAddress,
16394
+ amount_buy: amountBuy,
16395
+ token_buy: convertToSignableToken(request.buy),
16396
+ amount_sell: amountSell,
16397
+ token_sell: convertToSignableToken(request.sell),
16320
16398
  fees: request.fees,
16321
- stark_signature: starkSignature,
16322
- amount_buy: signableResultData.amount_buy,
16323
- amount_sell: signableResultData.amount_sell,
16324
- asset_id_buy: signableResultData.asset_id_buy,
16325
- asset_id_sell: signableResultData.asset_id_sell,
16326
- expiration_timestamp: signableResultData.expiration_timestamp,
16327
- nonce: signableResultData.nonce,
16328
- stark_key: signableResultData.stark_key,
16329
- vault_id_buy: signableResultData.vault_id_buy,
16330
- vault_id_sell: signableResultData.vault_id_sell,
16331
- },
16332
- };
16333
- const createOrderResponse = await ordersApi.createOrderV3(orderParams, {
16334
- headers,
16335
- });
16336
- return {
16337
- ...createOrderResponse.data,
16338
- };
16339
- }), PassportErrorType.CREATE_ORDER_ERROR);
16399
+ split_fees: true,
16400
+ expiration_timestamp: request.expiration_timestamp,
16401
+ };
16402
+ const getSignableOrderResponse = yield ordersApi.getSignableOrder({
16403
+ getSignableOrderRequestV3,
16404
+ }, { headers });
16405
+ yield guardianClient.evaluateImxTransaction({
16406
+ payloadHash: getSignableOrderResponse.data.payload_hash,
16407
+ });
16408
+ const { payload_hash: payloadHash } = getSignableOrderResponse.data;
16409
+ const starkSignature = yield starkSigner.signMessage(payloadHash);
16410
+ const signableResultData = getSignableOrderResponse.data;
16411
+ const orderParams = {
16412
+ createOrderRequest: {
16413
+ include_fees: true,
16414
+ fees: request.fees,
16415
+ stark_signature: starkSignature,
16416
+ amount_buy: signableResultData.amount_buy,
16417
+ amount_sell: signableResultData.amount_sell,
16418
+ asset_id_buy: signableResultData.asset_id_buy,
16419
+ asset_id_sell: signableResultData.asset_id_sell,
16420
+ expiration_timestamp: signableResultData.expiration_timestamp,
16421
+ nonce: signableResultData.nonce,
16422
+ stark_key: signableResultData.stark_key,
16423
+ vault_id_buy: signableResultData.vault_id_buy,
16424
+ vault_id_sell: signableResultData.vault_id_sell,
16425
+ },
16426
+ };
16427
+ const createOrderResponse = yield ordersApi.createOrderV3(orderParams, {
16428
+ headers,
16429
+ });
16430
+ return Object.assign({}, createOrderResponse.data);
16431
+ })), PassportErrorType.CREATE_ORDER_ERROR);
16432
+ });
16340
16433
  }
16341
- async function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
16342
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
16343
- const getSignableCancelOrderRequest = {
16344
- order_id: request.order_id,
16345
- };
16346
- const headers = {
16347
- // eslint-disable-next-line @typescript-eslint/naming-convention
16348
- Authorization: `Bearer ${user.accessToken}`,
16349
- };
16350
- const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrderV3({
16351
- getSignableCancelOrderRequest,
16352
- }, { headers });
16353
- await guardianClient.evaluateImxTransaction({
16354
- payloadHash: getSignableCancelOrderResponse.data.payload_hash,
16355
- });
16356
- const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
16357
- const starkSignature = await starkSigner.signMessage(payloadHash);
16358
- const cancelOrderResponse = await ordersApi.cancelOrderV3({
16359
- id: request.order_id.toString(),
16360
- cancelOrderRequest: {
16434
+ function cancelOrder$1({ user, starkSigner, request, ordersApi, guardianClient, }) {
16435
+ return __awaiter$4(this, void 0, void 0, function* () {
16436
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(() => __awaiter$4(this, void 0, void 0, function* () {
16437
+ const getSignableCancelOrderRequest = {
16361
16438
  order_id: request.order_id,
16362
- stark_signature: starkSignature,
16363
- },
16364
- }, { headers });
16365
- return {
16366
- order_id: cancelOrderResponse.data.order_id,
16367
- status: cancelOrderResponse.data.status,
16368
- };
16369
- }), PassportErrorType.CANCEL_ORDER_ERROR);
16370
- }
16371
-
16372
- async function registerPassport({ ethSigner, starkSigner, imxApiClients }, authorization) {
16373
- const [userAddress, starkPublicKey] = await Promise.all([
16374
- ethSigner.getAddress(),
16375
- starkSigner.getAddress(),
16376
- ]);
16377
- const signableResult = await imxApiClients.usersApi.getSignableRegistrationOffchain({
16378
- getSignableRegistrationRequest: {
16379
- ether_key: userAddress,
16380
- stark_key: starkPublicKey,
16381
- },
16382
- });
16383
- const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
16384
- const [ethSignature, starkSignature] = await Promise.all([
16385
- signRaw(signableMessage, ethSigner),
16386
- starkSigner.signMessage(payloadHash),
16387
- ]);
16388
- const response = await imxApiClients.usersApi.registerPassportUserV2({
16389
- authorization: `Bearer ${authorization}`,
16390
- registerPassportUserRequest: {
16391
- eth_signature: ethSignature,
16392
- ether_key: userAddress,
16393
- stark_signature: starkSignature,
16394
- stark_key: starkPublicKey,
16395
- },
16439
+ };
16440
+ const headers = {
16441
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16442
+ Authorization: `Bearer ${user.accessToken}`,
16443
+ };
16444
+ const getSignableCancelOrderResponse = yield ordersApi.getSignableCancelOrderV3({
16445
+ getSignableCancelOrderRequest,
16446
+ }, { headers });
16447
+ yield guardianClient.evaluateImxTransaction({
16448
+ payloadHash: getSignableCancelOrderResponse.data.payload_hash,
16449
+ });
16450
+ const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
16451
+ const starkSignature = yield starkSigner.signMessage(payloadHash);
16452
+ const cancelOrderResponse = yield ordersApi.cancelOrderV3({
16453
+ id: request.order_id.toString(),
16454
+ cancelOrderRequest: {
16455
+ order_id: request.order_id,
16456
+ stark_signature: starkSignature,
16457
+ },
16458
+ }, { headers });
16459
+ return {
16460
+ order_id: cancelOrderResponse.data.order_id,
16461
+ status: cancelOrderResponse.data.status,
16462
+ };
16463
+ })), PassportErrorType.CANCEL_ORDER_ERROR);
16396
16464
  });
16397
- return response.data;
16398
16465
  }
16399
16466
 
16400
- async function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
16401
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
16402
- const { ethAddress } = user.imx;
16403
- const getSignableTradeRequest = {
16404
- expiration_timestamp: request.expiration_timestamp,
16405
- fees: request.fees,
16406
- order_id: request.order_id,
16407
- user: ethAddress,
16408
- };
16409
- // eslint-disable-next-line @typescript-eslint/naming-convention
16410
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16411
- const getSignableTradeResponse = await tradesApi.getSignableTrade({
16412
- getSignableTradeRequest,
16413
- }, { headers });
16414
- await guardianClient.evaluateImxTransaction({
16415
- payloadHash: getSignableTradeResponse.data.payload_hash,
16467
+ function registerPassport({ ethSigner, starkSigner, imxApiClients }, authorization) {
16468
+ return __awaiter$4(this, void 0, void 0, function* () {
16469
+ const [userAddress, starkPublicKey] = yield Promise.all([
16470
+ ethSigner.getAddress(),
16471
+ starkSigner.getAddress(),
16472
+ ]);
16473
+ const signableResult = yield imxApiClients.usersApi.getSignableRegistrationOffchain({
16474
+ getSignableRegistrationRequest: {
16475
+ ether_key: userAddress,
16476
+ stark_key: starkPublicKey,
16477
+ },
16416
16478
  });
16417
- const { payload_hash: payloadHash } = getSignableTradeResponse.data;
16418
- const starkSignature = await starkSigner.signMessage(payloadHash);
16419
- const { data: signableResultData } = getSignableTradeResponse;
16420
- const tradeParams = {
16421
- createTradeRequest: {
16422
- include_fees: true,
16423
- fees: request?.fees,
16479
+ const { signable_message: signableMessage, payload_hash: payloadHash } = signableResult.data;
16480
+ const [ethSignature, starkSignature] = yield Promise.all([
16481
+ signRaw(signableMessage, ethSigner),
16482
+ starkSigner.signMessage(payloadHash),
16483
+ ]);
16484
+ const response = yield imxApiClients.usersApi.registerPassportUserV2({
16485
+ authorization: `Bearer ${authorization}`,
16486
+ registerPassportUserRequest: {
16487
+ eth_signature: ethSignature,
16488
+ ether_key: userAddress,
16424
16489
  stark_signature: starkSignature,
16425
- order_id: request?.order_id,
16426
- fee_info: signableResultData.fee_info,
16427
- amount_buy: signableResultData.amount_buy,
16428
- amount_sell: signableResultData.amount_sell,
16429
- asset_id_buy: signableResultData.asset_id_buy,
16430
- asset_id_sell: signableResultData.asset_id_sell,
16431
- expiration_timestamp: signableResultData.expiration_timestamp,
16432
- nonce: signableResultData.nonce,
16433
- stark_key: signableResultData.stark_key,
16434
- vault_id_buy: signableResultData.vault_id_buy,
16435
- vault_id_sell: signableResultData.vault_id_sell,
16490
+ stark_key: starkPublicKey,
16436
16491
  },
16437
- };
16438
- const { data: createTradeResponse } = await tradesApi.createTradeV3(tradeParams, {
16439
- headers,
16440
16492
  });
16441
- return createTradeResponse;
16442
- }), PassportErrorType.CREATE_TRADE_ERROR);
16493
+ return response.data;
16494
+ });
16495
+ }
16496
+
16497
+ function createTrade$1({ request, tradesApi, user, starkSigner, guardianClient, }) {
16498
+ return __awaiter$4(this, void 0, void 0, function* () {
16499
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(() => __awaiter$4(this, void 0, void 0, function* () {
16500
+ const { ethAddress } = user.imx;
16501
+ const getSignableTradeRequest = {
16502
+ expiration_timestamp: request.expiration_timestamp,
16503
+ fees: request.fees,
16504
+ order_id: request.order_id,
16505
+ user: ethAddress,
16506
+ };
16507
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16508
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
16509
+ const getSignableTradeResponse = yield tradesApi.getSignableTrade({
16510
+ getSignableTradeRequest,
16511
+ }, { headers });
16512
+ yield guardianClient.evaluateImxTransaction({
16513
+ payloadHash: getSignableTradeResponse.data.payload_hash,
16514
+ });
16515
+ const { payload_hash: payloadHash } = getSignableTradeResponse.data;
16516
+ const starkSignature = yield starkSigner.signMessage(payloadHash);
16517
+ const { data: signableResultData } = getSignableTradeResponse;
16518
+ const tradeParams = {
16519
+ createTradeRequest: {
16520
+ include_fees: true,
16521
+ fees: request === null || request === void 0 ? void 0 : request.fees,
16522
+ stark_signature: starkSignature,
16523
+ order_id: request === null || request === void 0 ? void 0 : request.order_id,
16524
+ fee_info: signableResultData.fee_info,
16525
+ amount_buy: signableResultData.amount_buy,
16526
+ amount_sell: signableResultData.amount_sell,
16527
+ asset_id_buy: signableResultData.asset_id_buy,
16528
+ asset_id_sell: signableResultData.asset_id_sell,
16529
+ expiration_timestamp: signableResultData.expiration_timestamp,
16530
+ nonce: signableResultData.nonce,
16531
+ stark_key: signableResultData.stark_key,
16532
+ vault_id_buy: signableResultData.vault_id_buy,
16533
+ vault_id_sell: signableResultData.vault_id_sell,
16534
+ },
16535
+ };
16536
+ const { data: createTradeResponse } = yield tradesApi.createTradeV3(tradeParams, {
16537
+ headers,
16538
+ });
16539
+ return createTradeResponse;
16540
+ })), PassportErrorType.CREATE_TRADE_ERROR);
16541
+ });
16443
16542
  }
16444
16543
 
16445
16544
  const ERC721 = 'ERC721';
16446
- async function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
16447
- return withPassportError(guardianClient.withDefaultConfirmationScreenTask(async () => {
16448
- const transferAmount = request.type === ERC721 ? '1' : request.amount;
16449
- const getSignableTransferRequest = {
16450
- sender: user.imx.ethAddress,
16451
- token: convertToSignableToken(request),
16452
- amount: transferAmount,
16453
- receiver: request.receiver,
16454
- };
16455
- const headers = {
16456
- Authorization: `Bearer ${user.accessToken}`,
16457
- };
16458
- const signableResult = await transfersApi.getSignableTransferV1({
16459
- getSignableTransferRequest,
16460
- }, { headers });
16461
- await guardianClient.evaluateImxTransaction({
16462
- payloadHash: signableResult.data.payload_hash,
16463
- });
16464
- const signableResultData = signableResult.data;
16465
- const { payload_hash: payloadHash } = signableResultData;
16466
- const starkSignature = await starkSigner.signMessage(payloadHash);
16467
- const senderStarkKey = await starkSigner.getAddress();
16468
- const transferSigningParams = {
16469
- sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
16470
- sender_vault_id: signableResultData.sender_vault_id,
16471
- receiver_stark_key: signableResultData.receiver_stark_key,
16472
- receiver_vault_id: signableResultData.receiver_vault_id,
16473
- asset_id: signableResultData.asset_id,
16474
- amount: signableResultData.amount,
16475
- nonce: signableResultData.nonce,
16476
- expiration_timestamp: signableResultData.expiration_timestamp,
16477
- stark_signature: starkSignature,
16478
- };
16479
- const createTransferRequest = {
16480
- createTransferRequest: transferSigningParams,
16481
- };
16482
- const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
16483
- return {
16484
- sent_signature: responseData.sent_signature,
16485
- status: responseData.status?.toString(),
16486
- time: responseData.time,
16487
- transfer_id: responseData.transfer_id,
16488
- };
16489
- }), PassportErrorType.TRANSFER_ERROR);
16490
- }
16491
- async function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
16492
- // eslint-disable-next-line function-paren-newline
16493
- return withPassportError(guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(async () => {
16494
- const { ethAddress } = user.imx;
16495
- const signableRequests = request.map((nftTransfer) => ({
16496
- amount: '1',
16497
- token: convertToSignableToken({
16498
- type: ERC721,
16499
- tokenId: nftTransfer.tokenId,
16500
- tokenAddress: nftTransfer.tokenAddress,
16501
- }),
16502
- receiver: nftTransfer.receiver,
16503
- }));
16504
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16505
- const signableResult = await transfersApi.getSignableTransfer({
16506
- getSignableTransferRequestV2: {
16507
- sender_ether_key: ethAddress,
16508
- signable_requests: signableRequests,
16509
- },
16510
- }, { headers });
16511
- await guardianClient.evaluateImxTransaction({
16512
- payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
16513
- });
16514
- const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
16515
- const starkSignature = await starkSigner.signMessage(resp.payload_hash);
16516
- return {
16517
- sender_vault_id: resp.sender_vault_id,
16518
- receiver_stark_key: resp.receiver_stark_key,
16519
- receiver_vault_id: resp.receiver_vault_id,
16520
- asset_id: resp.asset_id,
16521
- amount: resp.amount,
16522
- nonce: resp.nonce,
16523
- expiration_timestamp: resp.expiration_timestamp,
16545
+ function transfer$1({ request, transfersApi, starkSigner, user, guardianClient, }) {
16546
+ return __awaiter$4(this, void 0, void 0, function* () {
16547
+ return withPassportError(guardianClient.withDefaultConfirmationScreenTask(() => __awaiter$4(this, void 0, void 0, function* () {
16548
+ var _a;
16549
+ const transferAmount = request.type === ERC721 ? '1' : request.amount;
16550
+ const getSignableTransferRequest = {
16551
+ sender: user.imx.ethAddress,
16552
+ token: convertToSignableToken(request),
16553
+ amount: transferAmount,
16554
+ receiver: request.receiver,
16555
+ };
16556
+ const headers = {
16557
+ Authorization: `Bearer ${user.accessToken}`,
16558
+ };
16559
+ const signableResult = yield transfersApi.getSignableTransferV1({
16560
+ getSignableTransferRequest,
16561
+ }, { headers });
16562
+ yield guardianClient.evaluateImxTransaction({
16563
+ payloadHash: signableResult.data.payload_hash,
16564
+ });
16565
+ const signableResultData = signableResult.data;
16566
+ const { payload_hash: payloadHash } = signableResultData;
16567
+ const starkSignature = yield starkSigner.signMessage(payloadHash);
16568
+ const senderStarkKey = yield starkSigner.getAddress();
16569
+ const transferSigningParams = {
16570
+ sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
16571
+ sender_vault_id: signableResultData.sender_vault_id,
16572
+ receiver_stark_key: signableResultData.receiver_stark_key,
16573
+ receiver_vault_id: signableResultData.receiver_vault_id,
16574
+ asset_id: signableResultData.asset_id,
16575
+ amount: signableResultData.amount,
16576
+ nonce: signableResultData.nonce,
16577
+ expiration_timestamp: signableResultData.expiration_timestamp,
16524
16578
  stark_signature: starkSignature,
16525
16579
  };
16526
- }));
16527
- const transferSigningParams = {
16528
- sender_stark_key: signableResult.data.sender_stark_key,
16529
- requests,
16530
- };
16531
- const response = await transfersApi.createTransfer({
16532
- createTransferRequestV2: transferSigningParams,
16533
- }, { headers });
16534
- return {
16535
- transfer_ids: response?.data.transfer_ids,
16536
- };
16537
- }), PassportErrorType.TRANSFER_ERROR);
16580
+ const createTransferRequest = {
16581
+ createTransferRequest: transferSigningParams,
16582
+ };
16583
+ const { data: responseData } = yield transfersApi.createTransferV1(createTransferRequest, { headers });
16584
+ return {
16585
+ sent_signature: responseData.sent_signature,
16586
+ status: (_a = responseData.status) === null || _a === void 0 ? void 0 : _a.toString(),
16587
+ time: responseData.time,
16588
+ transfer_id: responseData.transfer_id,
16589
+ };
16590
+ })), PassportErrorType.TRANSFER_ERROR);
16591
+ });
16592
+ }
16593
+ function batchNftTransfer({ user, starkSigner, request, transfersApi, guardianClient, }) {
16594
+ return __awaiter$4(this, void 0, void 0, function* () {
16595
+ // eslint-disable-next-line function-paren-newline
16596
+ return withPassportError(guardianClient.withConfirmationScreenTask({ width: 480, height: 784 })(() => __awaiter$4(this, void 0, void 0, function* () {
16597
+ var _a;
16598
+ const { ethAddress } = user.imx;
16599
+ const signableRequests = request.map((nftTransfer) => ({
16600
+ amount: '1',
16601
+ token: convertToSignableToken({
16602
+ type: ERC721,
16603
+ tokenId: nftTransfer.tokenId,
16604
+ tokenAddress: nftTransfer.tokenAddress,
16605
+ }),
16606
+ receiver: nftTransfer.receiver,
16607
+ }));
16608
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
16609
+ const signableResult = yield transfersApi.getSignableTransfer({
16610
+ getSignableTransferRequestV2: {
16611
+ sender_ether_key: ethAddress,
16612
+ signable_requests: signableRequests,
16613
+ },
16614
+ }, { headers });
16615
+ yield guardianClient.evaluateImxTransaction({
16616
+ payloadHash: (_a = signableResult.data.signable_responses[0]) === null || _a === void 0 ? void 0 : _a.payload_hash,
16617
+ });
16618
+ const requests = yield Promise.all(signableResult.data.signable_responses.map((resp) => __awaiter$4(this, void 0, void 0, function* () {
16619
+ const starkSignature = yield starkSigner.signMessage(resp.payload_hash);
16620
+ return {
16621
+ sender_vault_id: resp.sender_vault_id,
16622
+ receiver_stark_key: resp.receiver_stark_key,
16623
+ receiver_vault_id: resp.receiver_vault_id,
16624
+ asset_id: resp.asset_id,
16625
+ amount: resp.amount,
16626
+ nonce: resp.nonce,
16627
+ expiration_timestamp: resp.expiration_timestamp,
16628
+ stark_signature: starkSignature,
16629
+ };
16630
+ })));
16631
+ const transferSigningParams = {
16632
+ sender_stark_key: signableResult.data.sender_stark_key,
16633
+ requests,
16634
+ };
16635
+ const response = yield transfersApi.createTransfer({
16636
+ createTransferRequestV2: transferSigningParams,
16637
+ }, { headers });
16638
+ return {
16639
+ transfer_ids: response === null || response === void 0 ? void 0 : response.data.transfer_ids,
16640
+ };
16641
+ })), PassportErrorType.TRANSFER_ERROR);
16642
+ });
16538
16643
  }
16539
16644
 
16540
16645
  const POLL_INTERVAL = 1 * 1000; // every 1 second
@@ -16542,16 +16647,16 @@ const MAX_RETRIES = 3;
16542
16647
  const wait = (ms) => new Promise((resolve) => {
16543
16648
  setTimeout(() => resolve(), ms);
16544
16649
  });
16545
- const retryWithDelay = async (fn, options) => {
16650
+ const retryWithDelay = (fn, options) => __awaiter$4(void 0, void 0, void 0, function* () {
16546
16651
  const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
16547
16652
  try {
16548
- return await fn();
16653
+ return yield fn();
16549
16654
  }
16550
16655
  catch (err) {
16551
16656
  if (retries <= 0) {
16552
16657
  return Promise.reject(finalErr);
16553
16658
  }
16554
- await wait(interval);
16659
+ yield wait(interval);
16555
16660
  return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
16556
16661
  }
16557
16662
  finally {
@@ -16559,203 +16664,147 @@ const retryWithDelay = async (fn, options) => {
16559
16664
  finallyFn();
16560
16665
  }
16561
16666
  }
16562
- };
16667
+ });
16563
16668
 
16564
- async function forceUserRefresh(authManager) {
16565
- // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
16566
- await retryWithDelay(async () => {
16567
- const user = await authManager.forceUserRefresh(); // force refresh to get updated user info
16568
- if (user?.imx)
16569
- return user;
16570
- return Promise.reject(new Error('user wallet addresses not exist'));
16669
+ function forceUserRefresh(authManager) {
16670
+ return __awaiter$4(this, void 0, void 0, function* () {
16671
+ // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
16672
+ yield retryWithDelay(() => __awaiter$4(this, void 0, void 0, function* () {
16673
+ const user = yield authManager.forceUserRefresh(); // force refresh to get updated user info
16674
+ if (user === null || user === void 0 ? void 0 : user.imx)
16675
+ return user;
16676
+ return Promise.reject(new Error('user wallet addresses not exist'));
16677
+ }));
16571
16678
  });
16572
16679
  }
16573
- async function registerOffchain$1(userAdminKeySigner, starkSigner, unregisteredUser, authManager, imxApiClients) {
16574
- return withPassportError(async () => {
16575
- try {
16576
- const response = await registerPassport({
16577
- ethSigner: userAdminKeySigner,
16578
- starkSigner,
16579
- imxApiClients,
16580
- }, unregisteredUser.accessToken);
16581
- await forceUserRefresh(authManager);
16582
- return response;
16583
- }
16584
- catch (err) {
16585
- if (globalAxios$1.isAxiosError(err) && err.response?.status === 409) {
16586
- // The user already registered, but the user token is not updated yet.
16587
- await forceUserRefresh(authManager);
16588
- return { tx_hash: '' };
16680
+ function registerOffchain$1(userAdminKeySigner, starkSigner, unregisteredUser, authManager, imxApiClients) {
16681
+ return __awaiter$4(this, void 0, void 0, function* () {
16682
+ return withPassportError(() => __awaiter$4(this, void 0, void 0, function* () {
16683
+ var _a;
16684
+ try {
16685
+ const response = yield registerPassport({
16686
+ ethSigner: userAdminKeySigner,
16687
+ starkSigner,
16688
+ imxApiClients,
16689
+ }, unregisteredUser.accessToken);
16690
+ yield forceUserRefresh(authManager);
16691
+ return response;
16589
16692
  }
16590
- throw err;
16591
- }
16592
- }, PassportErrorType.USER_REGISTRATION_ERROR);
16693
+ catch (err) {
16694
+ if (globalAxios$1.isAxiosError(err) && ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 409) {
16695
+ // The user already registered, but the user token is not updated yet.
16696
+ yield forceUserRefresh(authManager);
16697
+ return { tx_hash: '' };
16698
+ }
16699
+ throw err;
16700
+ }
16701
+ }), PassportErrorType.USER_REGISTRATION_ERROR);
16702
+ });
16593
16703
  }
16594
16704
 
16705
+ var _PassportImxProvider_instances, _PassportImxProvider_initialiseSigners, _PassportImxProvider_getAuthenticatedUser, _PassportImxProvider_getSigners, _PassportImxProvider_getRegisteredImxUserAndSigners;
16595
16706
  class PassportImxProvider {
16596
- authManager;
16597
- immutableXClient;
16598
- guardianClient;
16599
- imxApiClients;
16600
- magicAdapter;
16601
- /**
16602
- * This property is set during initialisation and stores the signers in a promise.
16603
- * This property is not meant to be accessed directly, but through the
16604
- * `#getSigners` method.
16605
- * @see #getSigners
16606
- */
16607
- signers;
16608
- signerInitialisationError;
16609
16707
  constructor({ authManager, immutableXClient, passportEventEmitter, magicAdapter, imxApiClients, guardianClient, }) {
16708
+ _PassportImxProvider_instances.add(this);
16709
+ this.handleLogout = () => {
16710
+ this.signers = undefined;
16711
+ };
16610
16712
  this.authManager = authManager;
16611
16713
  this.immutableXClient = immutableXClient;
16612
16714
  this.magicAdapter = magicAdapter;
16613
16715
  this.imxApiClients = imxApiClients;
16614
16716
  this.guardianClient = guardianClient;
16615
- this.#initialiseSigners();
16717
+ __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_initialiseSigners).call(this);
16616
16718
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
16617
16719
  }
16618
- handleLogout = () => {
16619
- this.signers = undefined;
16620
- };
16621
- /**
16622
- * This method is called by the constructor and asynchronously initialises the signers.
16623
- * The signers are stored in a promise so that they can be retrieved by the provider
16624
- * when needed.
16625
- *
16626
- * If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
16627
- * so that it doesn't result in an unhandled promise rejection.
16628
- *
16629
- * This error is thrown when the signers are requested through:
16630
- * @see #getSigners
16631
- *
16632
- */
16633
- #initialiseSigners() {
16634
- const generateSigners = async () => {
16635
- const user = await this.authManager.getUser();
16636
- // The user will be present because the factory validates it
16637
- const magicRpcProvider = await this.magicAdapter.login(user.idToken);
16638
- const web3Provider = new providers.Web3Provider(magicRpcProvider);
16639
- const ethSigner = web3Provider.getSigner();
16640
- const starkSigner = await getStarkSigner(ethSigner);
16641
- return { ethSigner, starkSigner };
16642
- };
16643
- // eslint-disable-next-line no-async-promise-executor
16644
- this.signers = new Promise(async (resolve) => {
16645
- try {
16646
- resolve(await generateSigners());
16647
- }
16648
- catch (err) {
16649
- // Capture and store the initialization error
16650
- this.signerInitialisationError = err;
16651
- resolve(undefined);
16652
- }
16720
+ transfer(request) {
16721
+ return __awaiter$4(this, void 0, void 0, function* () {
16722
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16723
+ return transfer$1({
16724
+ request,
16725
+ user,
16726
+ starkSigner,
16727
+ transfersApi: this.immutableXClient.transfersApi,
16728
+ guardianClient: this.guardianClient,
16729
+ });
16653
16730
  });
16654
16731
  }
16655
- async #getAuthenticatedUser() {
16656
- const user = await this.authManager.getUser();
16657
- if (!user || !this.signers) {
16658
- throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
16659
- }
16660
- return user;
16661
- }
16662
- async #getSigners() {
16663
- const signers = await this.signers;
16664
- // Throw the stored error if the signers failed to initialise
16665
- if (typeof signers === 'undefined') {
16666
- if (typeof this.signerInitialisationError !== 'undefined') {
16667
- throw this.signerInitialisationError;
16668
- }
16669
- throw new Error('Signers failed to initialise');
16670
- }
16671
- return signers;
16672
- }
16673
- async #getRegisteredImxUserAndSigners() {
16674
- const [user, signers] = await Promise.all([
16675
- this.#getAuthenticatedUser(),
16676
- this.#getSigners(),
16677
- ]);
16678
- if (!isUserImx(user)) {
16679
- throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
16680
- }
16681
- return {
16682
- user,
16683
- starkSigner: signers.starkSigner,
16684
- ethSigner: signers.ethSigner,
16685
- };
16686
- }
16687
- async transfer(request) {
16688
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16689
- return transfer$1({
16690
- request,
16691
- user,
16692
- starkSigner,
16693
- transfersApi: this.immutableXClient.transfersApi,
16694
- guardianClient: this.guardianClient,
16732
+ registerOffchain() {
16733
+ return __awaiter$4(this, void 0, void 0, function* () {
16734
+ const [user, signers] = yield Promise.all([
16735
+ __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getAuthenticatedUser).call(this),
16736
+ __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getSigners).call(this),
16737
+ ]);
16738
+ return yield registerOffchain$1(signers.ethSigner, signers.starkSigner, user, this.authManager, this.imxApiClients);
16695
16739
  });
16696
16740
  }
16697
- async registerOffchain() {
16698
- const [user, signers] = await Promise.all([
16699
- this.#getAuthenticatedUser(),
16700
- this.#getSigners(),
16701
- ]);
16702
- return await registerOffchain$1(signers.ethSigner, signers.starkSigner, user, this.authManager, this.imxApiClients);
16703
- }
16704
- async isRegisteredOffchain() {
16705
- const user = await this.#getAuthenticatedUser();
16706
- return !!user.imx;
16741
+ isRegisteredOffchain() {
16742
+ return __awaiter$4(this, void 0, void 0, function* () {
16743
+ const user = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getAuthenticatedUser).call(this);
16744
+ return !!user.imx;
16745
+ });
16707
16746
  }
16708
16747
  // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
16709
16748
  isRegisteredOnchain() {
16710
16749
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
16711
16750
  }
16712
- async createOrder(request) {
16713
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16714
- return createOrder$1({
16715
- request,
16716
- user,
16717
- starkSigner,
16718
- ordersApi: this.immutableXClient.ordersApi,
16719
- guardianClient: this.guardianClient,
16751
+ createOrder(request) {
16752
+ return __awaiter$4(this, void 0, void 0, function* () {
16753
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16754
+ return createOrder$1({
16755
+ request,
16756
+ user,
16757
+ starkSigner,
16758
+ ordersApi: this.immutableXClient.ordersApi,
16759
+ guardianClient: this.guardianClient,
16760
+ });
16720
16761
  });
16721
16762
  }
16722
- async cancelOrder(request) {
16723
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16724
- return cancelOrder$1({
16725
- request,
16726
- user,
16727
- starkSigner,
16728
- ordersApi: this.immutableXClient.ordersApi,
16729
- guardianClient: this.guardianClient,
16763
+ cancelOrder(request) {
16764
+ return __awaiter$4(this, void 0, void 0, function* () {
16765
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16766
+ return cancelOrder$1({
16767
+ request,
16768
+ user,
16769
+ starkSigner,
16770
+ ordersApi: this.immutableXClient.ordersApi,
16771
+ guardianClient: this.guardianClient,
16772
+ });
16730
16773
  });
16731
16774
  }
16732
- async createTrade(request) {
16733
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16734
- return createTrade$1({
16735
- request,
16736
- user,
16737
- starkSigner,
16738
- tradesApi: this.immutableXClient.tradesApi,
16739
- guardianClient: this.guardianClient,
16775
+ createTrade(request) {
16776
+ return __awaiter$4(this, void 0, void 0, function* () {
16777
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16778
+ return createTrade$1({
16779
+ request,
16780
+ user,
16781
+ starkSigner,
16782
+ tradesApi: this.immutableXClient.tradesApi,
16783
+ guardianClient: this.guardianClient,
16784
+ });
16740
16785
  });
16741
16786
  }
16742
- async batchNftTransfer(request) {
16743
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16744
- return batchNftTransfer({
16745
- request,
16746
- user,
16747
- starkSigner,
16748
- transfersApi: this.immutableXClient.transfersApi,
16749
- guardianClient: this.guardianClient,
16787
+ batchNftTransfer(request) {
16788
+ return __awaiter$4(this, void 0, void 0, function* () {
16789
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16790
+ return batchNftTransfer({
16791
+ request,
16792
+ user,
16793
+ starkSigner,
16794
+ transfersApi: this.immutableXClient.transfersApi,
16795
+ guardianClient: this.guardianClient,
16796
+ });
16750
16797
  });
16751
16798
  }
16752
- async exchangeTransfer(request) {
16753
- const { user, starkSigner } = await this.#getRegisteredImxUserAndSigners();
16754
- return exchangeTransfer$1({
16755
- request,
16756
- user,
16757
- starkSigner,
16758
- exchangesApi: this.immutableXClient.exchangeApi,
16799
+ exchangeTransfer(request) {
16800
+ return __awaiter$4(this, void 0, void 0, function* () {
16801
+ const { user, starkSigner } = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getRegisteredImxUserAndSigners).call(this);
16802
+ return exchangeTransfer$1({
16803
+ request,
16804
+ user,
16805
+ starkSigner,
16806
+ exchangesApi: this.immutableXClient.exchangeApi,
16807
+ });
16759
16808
  });
16760
16809
  }
16761
16810
  // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
@@ -16774,22 +16823,75 @@ class PassportImxProvider {
16774
16823
  token) {
16775
16824
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
16776
16825
  }
16777
- async getAddress() {
16778
- const user = await this.#getAuthenticatedUser();
16826
+ getAddress() {
16827
+ return __awaiter$4(this, void 0, void 0, function* () {
16828
+ const user = yield __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getAuthenticatedUser).call(this);
16829
+ if (!isUserImx(user)) {
16830
+ throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
16831
+ }
16832
+ return Promise.resolve(user.imx.ethAddress);
16833
+ });
16834
+ }
16835
+ }
16836
+ _PassportImxProvider_instances = new WeakSet(), _PassportImxProvider_initialiseSigners = function _PassportImxProvider_initialiseSigners() {
16837
+ const generateSigners = () => __awaiter$4(this, void 0, void 0, function* () {
16838
+ const user = yield this.authManager.getUser();
16839
+ // The user will be present because the factory validates it
16840
+ const magicRpcProvider = yield this.magicAdapter.login(user.idToken);
16841
+ const web3Provider = new providers.Web3Provider(magicRpcProvider);
16842
+ const ethSigner = web3Provider.getSigner();
16843
+ const starkSigner = yield getStarkSigner(ethSigner);
16844
+ return { ethSigner, starkSigner };
16845
+ });
16846
+ // eslint-disable-next-line no-async-promise-executor
16847
+ this.signers = new Promise((resolve) => __awaiter$4(this, void 0, void 0, function* () {
16848
+ try {
16849
+ resolve(yield generateSigners());
16850
+ }
16851
+ catch (err) {
16852
+ // Capture and store the initialization error
16853
+ this.signerInitialisationError = err;
16854
+ resolve(undefined);
16855
+ }
16856
+ }));
16857
+ }, _PassportImxProvider_getAuthenticatedUser = function _PassportImxProvider_getAuthenticatedUser() {
16858
+ return __awaiter$4(this, void 0, void 0, function* () {
16859
+ const user = yield this.authManager.getUser();
16860
+ if (!user || !this.signers) {
16861
+ throw new PassportError('User has been logged out', PassportErrorType.NOT_LOGGED_IN_ERROR);
16862
+ }
16863
+ return user;
16864
+ });
16865
+ }, _PassportImxProvider_getSigners = function _PassportImxProvider_getSigners() {
16866
+ return __awaiter$4(this, void 0, void 0, function* () {
16867
+ const signers = yield this.signers;
16868
+ // Throw the stored error if the signers failed to initialise
16869
+ if (typeof signers === 'undefined') {
16870
+ if (typeof this.signerInitialisationError !== 'undefined') {
16871
+ throw this.signerInitialisationError;
16872
+ }
16873
+ throw new Error('Signers failed to initialise');
16874
+ }
16875
+ return signers;
16876
+ });
16877
+ }, _PassportImxProvider_getRegisteredImxUserAndSigners = function _PassportImxProvider_getRegisteredImxUserAndSigners() {
16878
+ return __awaiter$4(this, void 0, void 0, function* () {
16879
+ const [user, signers] = yield Promise.all([
16880
+ __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getAuthenticatedUser).call(this),
16881
+ __classPrivateFieldGet(this, _PassportImxProvider_instances, "m", _PassportImxProvider_getSigners).call(this),
16882
+ ]);
16779
16883
  if (!isUserImx(user)) {
16780
16884
  throw new PassportError('User has not been registered with StarkEx', PassportErrorType.USER_NOT_REGISTERED_ERROR);
16781
16885
  }
16782
- return Promise.resolve(user.imx.ethAddress);
16783
- }
16784
- }
16886
+ return {
16887
+ user,
16888
+ starkSigner: signers.starkSigner,
16889
+ ethSigner: signers.ethSigner,
16890
+ };
16891
+ });
16892
+ };
16785
16893
 
16786
16894
  class PassportImxProviderFactory {
16787
- authManager;
16788
- immutableXClient;
16789
- magicAdapter;
16790
- passportEventEmitter;
16791
- imxApiClients;
16792
- guardianClient;
16793
16895
  constructor({ authManager, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, guardianClient, }) {
16794
16896
  this.authManager = authManager;
16795
16897
  this.immutableXClient = immutableXClient;
@@ -16798,28 +16900,34 @@ class PassportImxProviderFactory {
16798
16900
  this.imxApiClients = imxApiClients;
16799
16901
  this.guardianClient = guardianClient;
16800
16902
  }
16801
- async getProvider() {
16802
- const user = await this.authManager.getUserOrLogin();
16803
- return this.createProviderInstance(user);
16903
+ getProvider() {
16904
+ return __awaiter$4(this, void 0, void 0, function* () {
16905
+ const user = yield this.authManager.getUserOrLogin();
16906
+ return this.createProviderInstance(user);
16907
+ });
16804
16908
  }
16805
- async getProviderSilent() {
16806
- const user = await this.authManager.getUser();
16807
- if (!user) {
16808
- return null;
16809
- }
16810
- return this.createProviderInstance(user);
16909
+ getProviderSilent() {
16910
+ return __awaiter$4(this, void 0, void 0, function* () {
16911
+ const user = yield this.authManager.getUser();
16912
+ if (!user) {
16913
+ return null;
16914
+ }
16915
+ return this.createProviderInstance(user);
16916
+ });
16811
16917
  }
16812
- async createProviderInstance(user) {
16813
- if (!user.idToken) {
16814
- throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
16815
- }
16816
- return new PassportImxProvider({
16817
- authManager: this.authManager,
16818
- immutableXClient: this.immutableXClient,
16819
- passportEventEmitter: this.passportEventEmitter,
16820
- magicAdapter: this.magicAdapter,
16821
- imxApiClients: this.imxApiClients,
16822
- guardianClient: this.guardianClient,
16918
+ createProviderInstance(user) {
16919
+ return __awaiter$4(this, void 0, void 0, function* () {
16920
+ if (!user.idToken) {
16921
+ throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
16922
+ }
16923
+ return new PassportImxProvider({
16924
+ authManager: this.authManager,
16925
+ immutableXClient: this.immutableXClient,
16926
+ passportEventEmitter: this.passportEventEmitter,
16927
+ magicAdapter: this.magicAdapter,
16928
+ imxApiClients: this.imxApiClients,
16929
+ guardianClient: this.guardianClient,
16930
+ });
16823
16931
  });
16824
16932
  }
16825
16933
  }
@@ -16837,18 +16945,8 @@ const validateConfiguration = (configuration, requiredKeys, prefix) => {
16837
16945
  }
16838
16946
  };
16839
16947
  class PassportConfiguration {
16840
- authenticationDomain;
16841
- passportDomain;
16842
- imxPublicApiDomain;
16843
- magicPublishableApiKey;
16844
- magicProviderId;
16845
- oidcConfiguration;
16846
- baseConfig;
16847
- zkEvmRpcUrl;
16848
- relayerUrl;
16849
- multiRollupConfig;
16850
- crossSdkBridgeEnabled;
16851
- constructor({ baseConfig, overrides, crossSdkBridgeEnabled, ...oidcConfiguration }) {
16948
+ constructor(_a) {
16949
+ var { baseConfig, overrides, crossSdkBridgeEnabled } = _a, oidcConfiguration = __rest(_a, ["baseConfig", "overrides", "crossSdkBridgeEnabled"]);
16852
16950
  validateConfiguration(oidcConfiguration, [
16853
16951
  'clientId',
16854
16952
  'redirectUri',
@@ -16953,8 +17051,6 @@ const CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION = 1000;
16953
17051
  const CONFIRMATION_IFRAME_ID = 'passport-confirm';
16954
17052
  const CONFIRMATION_IFRAME_STYLE = 'display: none; position: absolute;width:0px;height:0px;border:0;';
16955
17053
  class ConfirmationScreen {
16956
- config;
16957
- confirmationWindow;
16958
17054
  constructor(config) {
16959
17055
  this.config = config;
16960
17056
  }
@@ -17050,12 +17146,13 @@ class ConfirmationScreen {
17050
17146
  this.confirmationWindow = openPopupCenter({
17051
17147
  url: this.getHref('loading'),
17052
17148
  title: CONFIRMATION_WINDOW_TITLE,
17053
- width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
17054
- height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
17149
+ width: (popupOptions === null || popupOptions === void 0 ? void 0 : popupOptions.width) || CONFIRMATION_WINDOW_WIDTH,
17150
+ height: (popupOptions === null || popupOptions === void 0 ? void 0 : popupOptions.height) || CONFIRMATION_WINDOW_HEIGHT,
17055
17151
  });
17056
17152
  }
17057
17153
  closeWindow() {
17058
- this.confirmationWindow?.close();
17154
+ var _a;
17155
+ (_a = this.confirmationWindow) === null || _a === void 0 ? void 0 : _a.close();
17059
17156
  }
17060
17157
  logout() {
17061
17158
  return new Promise((resolve, rejects) => {
@@ -17083,7 +17180,8 @@ class ConfirmationScreen {
17083
17180
  this.confirmationWindow.location.href = href;
17084
17181
  // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
17085
17182
  const timer = setInterval(() => {
17086
- if (this.confirmationWindow?.closed) {
17183
+ var _a;
17184
+ if ((_a = this.confirmationWindow) === null || _a === void 0 ? void 0 : _a.closed) {
17087
17185
  clearInterval(timer);
17088
17186
  window.removeEventListener('message', messageHandler);
17089
17187
  resolve({ confirmed: false });
@@ -17106,7 +17204,9 @@ var ProviderEvent;
17106
17204
  })(ProviderEvent || (ProviderEvent = {}));
17107
17205
 
17108
17206
  class TypedEventEmitter {
17109
- emitter = new events.EventEmitter();
17207
+ constructor() {
17208
+ this.emitter = new events.EventEmitter();
17209
+ }
17110
17210
  emit(eventName, ...eventArg) {
17111
17211
  this.emitter.emit(eventName, ...eventArg);
17112
17212
  }
@@ -17132,23 +17232,26 @@ const META_TRANSACTIONS_TYPE = `tuple(
17132
17232
  bytes data
17133
17233
  )[]`;
17134
17234
  function getNormalisedTransactions(txs) {
17135
- return txs.map((t) => ({
17136
- delegateCall: t.delegateCall === true,
17137
- revertOnError: t.revertOnError === true,
17138
- gasLimit: t.gasLimit ?? ethers.constants.Zero,
17139
- target: t.to ?? ethers.constants.AddressZero,
17140
- value: t.value ?? ethers.constants.Zero,
17141
- data: t.data ?? [],
17142
- }));
17235
+ return txs.map((t) => {
17236
+ var _a, _b, _c, _d;
17237
+ return ({
17238
+ delegateCall: t.delegateCall === true,
17239
+ revertOnError: t.revertOnError === true,
17240
+ gasLimit: (_a = t.gasLimit) !== null && _a !== void 0 ? _a : ethers.constants.Zero,
17241
+ target: (_b = t.to) !== null && _b !== void 0 ? _b : ethers.constants.AddressZero,
17242
+ value: (_c = t.value) !== null && _c !== void 0 ? _c : ethers.constants.Zero,
17243
+ data: (_d = t.data) !== null && _d !== void 0 ? _d : [],
17244
+ });
17245
+ });
17143
17246
  }
17144
17247
  function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
17145
17248
  const packMetaTransactionsNonceData = ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
17146
17249
  return ethers.utils.keccak256(packMetaTransactionsNonceData);
17147
17250
  }
17148
- const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
17251
+ const getNonce = (jsonRpcProvider, smartContractWalletAddress) => __awaiter$4(void 0, void 0, void 0, function* () {
17149
17252
  try {
17150
17253
  const contract = new ethers.Contract(smartContractWalletAddress, abi.walletContracts.mainModule.abi, jsonRpcProvider);
17151
- const result = await contract.nonce();
17254
+ const result = yield contract.nonce();
17152
17255
  if (result instanceof ethers.BigNumber) {
17153
17256
  return result;
17154
17257
  }
@@ -17164,9 +17267,9 @@ const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
17164
17267
  throw error;
17165
17268
  }
17166
17269
  throw new Error('Unexpected result from contract.nonce() call.');
17167
- };
17270
+ });
17168
17271
  const encodeMessageSubDigest = (chainId, walletAddress, digest) => (ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]));
17169
- const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
17272
+ const getSignedMetaTransactions = (metaTransactions, nonce, chainId, walletAddress, signer) => __awaiter$4(void 0, void 0, void 0, function* () {
17170
17273
  const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
17171
17274
  // Get the hash
17172
17275
  const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
@@ -17174,7 +17277,7 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
17174
17277
  const hash = ethers.utils.keccak256(completePayload);
17175
17278
  // Sign the digest
17176
17279
  const hashArray = ethers.utils.arrayify(hash);
17177
- const ethsigNoType = await signer.signMessage(hashArray);
17280
+ const ethsigNoType = yield signer.signMessage(hashArray);
17178
17281
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
17179
17282
  // Add metadata
17180
17283
  const encodedSignature = core.v1.signature.encodeSignature({
@@ -17196,14 +17299,14 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
17196
17299
  nonce,
17197
17300
  encodedSignature,
17198
17301
  ]);
17199
- };
17302
+ });
17200
17303
  const decodeRelayerTypedDataSignature = (relayerSignature) => {
17201
17304
  const signatureWithThreshold = `0x0000${relayerSignature}`;
17202
17305
  return core.v1.signature.decodeSignature(signatureWithThreshold);
17203
17306
  };
17204
- const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAddress, signer) => {
17307
+ const getSignedTypedData = (typedData, relayerSignature, chainId, walletAddress, signer) => __awaiter$4(void 0, void 0, void 0, function* () {
17205
17308
  // Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
17206
- const types = { ...typedData.types };
17309
+ const types = Object.assign({}, typedData.types);
17207
17310
  // @ts-ignore
17208
17311
  delete types.EIP712Domain;
17209
17312
  // Hash the EIP712 payload and generate the complete payload
@@ -17214,7 +17317,7 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
17214
17317
  // Sign the sub digest
17215
17318
  // https://github.com/immutable/wallet-contracts/blob/7824b5f24b2e0eb2dc465ecb5cd71f3984556b73/src/contracts/modules/commons/ModuleAuth.sol#L155
17216
17319
  const hashArray = ethers.utils.arrayify(hash);
17217
- const ethsigNoType = await signer.signMessage(hashArray);
17320
+ const ethsigNoType = yield signer.signMessage(hashArray);
17218
17321
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
17219
17322
  // Combine the relayer and user signatures; sort by address to match the imageHash order
17220
17323
  const { signers: relayerSigners } = decodeRelayerTypedDataSignature(relayerSignature);
@@ -17225,7 +17328,7 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
17225
17328
  unrecovered: true,
17226
17329
  weight: SIGNATURE_WEIGHT,
17227
17330
  signature: signedDigest,
17228
- address: await signer.getAddress(),
17331
+ address: yield signer.getAddress(),
17229
17332
  },
17230
17333
  ];
17231
17334
  const sortedSigners = combinedSigners.sort((a, b) => {
@@ -17244,85 +17347,88 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
17244
17347
  threshold: EIP712_SIGNATURE_THRESHOLD,
17245
17348
  signers: sortedSigners,
17246
17349
  });
17247
- };
17350
+ });
17248
17351
  const getEip155ChainId = (chainId) => `eip155:${chainId}`;
17249
17352
 
17250
17353
  class RelayerClient {
17251
- config;
17252
- jsonRpcProvider;
17253
- authManager;
17254
17354
  constructor({ config, jsonRpcProvider, authManager }) {
17255
17355
  this.config = config;
17256
17356
  this.jsonRpcProvider = jsonRpcProvider;
17257
17357
  this.authManager = authManager;
17258
17358
  }
17259
- async postToRelayer(request) {
17260
- const body = {
17261
- id: 1,
17262
- jsonrpc: '2.0',
17263
- ...request,
17264
- };
17265
- const user = await this.authManager.getUserZkEvm();
17266
- const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
17267
- method: 'POST',
17268
- headers: {
17269
- Authorization: `Bearer ${user.accessToken}`,
17270
- 'Content-Type': 'application/json',
17271
- },
17272
- body: JSON.stringify(body),
17359
+ postToRelayer(request) {
17360
+ return __awaiter$4(this, void 0, void 0, function* () {
17361
+ const body = Object.assign({ id: 1, jsonrpc: '2.0' }, request);
17362
+ const user = yield this.authManager.getUserZkEvm();
17363
+ const response = yield fetch(`${this.config.relayerUrl}/v1/transactions`, {
17364
+ method: 'POST',
17365
+ headers: {
17366
+ Authorization: `Bearer ${user.accessToken}`,
17367
+ 'Content-Type': 'application/json',
17368
+ },
17369
+ body: JSON.stringify(body),
17370
+ });
17371
+ const jsonResponse = yield response.json();
17372
+ if (jsonResponse.error) {
17373
+ throw jsonResponse.error;
17374
+ }
17375
+ return jsonResponse;
17273
17376
  });
17274
- const jsonResponse = await response.json();
17275
- if (jsonResponse.error) {
17276
- throw jsonResponse.error;
17277
- }
17278
- return jsonResponse;
17279
- }
17280
- async ethSendTransaction(to, data) {
17281
- const { chainId } = await this.jsonRpcProvider.ready;
17282
- const payload = {
17283
- method: 'eth_sendTransaction',
17284
- params: [{
17285
- to,
17286
- data,
17287
- chainId: getEip155ChainId(chainId),
17288
- }],
17289
- };
17290
- const { result } = await this.postToRelayer(payload);
17291
- return result;
17292
17377
  }
17293
- async imGetTransactionByHash(hash) {
17294
- const payload = {
17295
- method: 'im_getTransactionByHash',
17296
- params: [hash],
17297
- };
17298
- const { result } = await this.postToRelayer(payload);
17299
- return result;
17378
+ ethSendTransaction(to, data) {
17379
+ return __awaiter$4(this, void 0, void 0, function* () {
17380
+ const { chainId } = yield this.jsonRpcProvider.ready;
17381
+ const payload = {
17382
+ method: 'eth_sendTransaction',
17383
+ params: [{
17384
+ to,
17385
+ data,
17386
+ chainId: getEip155ChainId(chainId),
17387
+ }],
17388
+ };
17389
+ const { result } = yield this.postToRelayer(payload);
17390
+ return result;
17391
+ });
17300
17392
  }
17301
- async imGetFeeOptions(userAddress, data) {
17302
- const { chainId } = await this.jsonRpcProvider.ready;
17303
- const payload = {
17304
- method: 'im_getFeeOptions',
17305
- params: [{
17306
- userAddress,
17307
- data,
17308
- chainId: getEip155ChainId(chainId),
17309
- }],
17310
- };
17311
- const { result } = await this.postToRelayer(payload);
17312
- return result;
17393
+ imGetTransactionByHash(hash) {
17394
+ return __awaiter$4(this, void 0, void 0, function* () {
17395
+ const payload = {
17396
+ method: 'im_getTransactionByHash',
17397
+ params: [hash],
17398
+ };
17399
+ const { result } = yield this.postToRelayer(payload);
17400
+ return result;
17401
+ });
17313
17402
  }
17314
- async imSignTypedData(address, eip712Payload) {
17315
- const { chainId } = await this.jsonRpcProvider.ready;
17316
- const payload = {
17317
- method: 'im_signTypedData',
17318
- params: [{
17319
- address,
17320
- eip712Payload,
17321
- chainId: getEip155ChainId(chainId),
17322
- }],
17323
- };
17324
- const { result } = await this.postToRelayer(payload);
17325
- return result;
17403
+ imGetFeeOptions(userAddress, data) {
17404
+ return __awaiter$4(this, void 0, void 0, function* () {
17405
+ const { chainId } = yield this.jsonRpcProvider.ready;
17406
+ const payload = {
17407
+ method: 'im_getFeeOptions',
17408
+ params: [{
17409
+ userAddress,
17410
+ data,
17411
+ chainId: getEip155ChainId(chainId),
17412
+ }],
17413
+ };
17414
+ const { result } = yield this.postToRelayer(payload);
17415
+ return result;
17416
+ });
17417
+ }
17418
+ imSignTypedData(address, eip712Payload) {
17419
+ return __awaiter$4(this, void 0, void 0, function* () {
17420
+ const { chainId } = yield this.jsonRpcProvider.ready;
17421
+ const payload = {
17422
+ method: 'im_signTypedData',
17423
+ params: [{
17424
+ address,
17425
+ eip712Payload,
17426
+ chainId: getEip155ChainId(chainId),
17427
+ }],
17428
+ };
17429
+ const { result } = yield this.postToRelayer(payload);
17430
+ return result;
17431
+ });
17326
17432
  }
17327
17433
  }
17328
17434
 
@@ -17349,8 +17455,6 @@ var RpcErrorCode;
17349
17455
  RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
17350
17456
  })(RpcErrorCode || (RpcErrorCode = {}));
17351
17457
  class JsonRpcError extends Error {
17352
- message;
17353
- code;
17354
17458
  constructor(code, message) {
17355
17459
  super(message);
17356
17460
  this.message = message;
@@ -17359,34 +17463,37 @@ class JsonRpcError extends Error {
17359
17463
  }
17360
17464
 
17361
17465
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
17362
- async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
17363
- const [ethereumAddress, ethereumSignature, network, chainListResponse] = await Promise.all([
17364
- ethSigner.getAddress(),
17365
- signRaw(MESSAGE_TO_SIGN, ethSigner),
17366
- jsonRpcProvider.ready,
17367
- multiRollupApiClients.chainsApi.listChains(),
17368
- ]);
17369
- const eipChainId = getEip155ChainId(network.chainId);
17370
- const chainName = chainListResponse.data?.result?.find((chain) => chain.id === eipChainId)?.name;
17371
- if (!chainName) {
17372
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
17373
- }
17374
- try {
17375
- const registrationResponse = await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
17376
- chainName,
17377
- createCounterfactualAddressRequest: {
17378
- ethereum_address: ethereumAddress,
17379
- ethereum_signature: ethereumSignature,
17380
- },
17381
- }, {
17382
- headers: { Authorization: `Bearer ${accessToken}` },
17383
- });
17384
- authManager.forceUserRefreshInBackground();
17385
- return registrationResponse.data.counterfactual_address;
17386
- }
17387
- catch (error) {
17388
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
17389
- }
17466
+ function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
17467
+ var _a, _b, _c;
17468
+ return __awaiter$4(this, void 0, void 0, function* () {
17469
+ const [ethereumAddress, ethereumSignature, network, chainListResponse] = yield Promise.all([
17470
+ ethSigner.getAddress(),
17471
+ signRaw(MESSAGE_TO_SIGN, ethSigner),
17472
+ jsonRpcProvider.ready,
17473
+ multiRollupApiClients.chainsApi.listChains(),
17474
+ ]);
17475
+ const eipChainId = getEip155ChainId(network.chainId);
17476
+ const chainName = (_c = (_b = (_a = chainListResponse.data) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.find((chain) => chain.id === eipChainId)) === null || _c === void 0 ? void 0 : _c.name;
17477
+ if (!chainName) {
17478
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
17479
+ }
17480
+ try {
17481
+ const registrationResponse = yield multiRollupApiClients.passportApi.createCounterfactualAddressV2({
17482
+ chainName,
17483
+ createCounterfactualAddressRequest: {
17484
+ ethereum_address: ethereumAddress,
17485
+ ethereum_signature: ethereumSignature,
17486
+ },
17487
+ }, {
17488
+ headers: { Authorization: `Bearer ${accessToken}` },
17489
+ });
17490
+ authManager.forceUserRefreshInBackground();
17491
+ return registrationResponse.data.counterfactual_address;
17492
+ }
17493
+ catch (error) {
17494
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
17495
+ }
17496
+ });
17390
17497
  }
17391
17498
 
17392
17499
  const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
@@ -17394,14 +17501,17 @@ const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmatio
17394
17501
  const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
17395
17502
  const transformGuardianTransactions = (txs) => {
17396
17503
  try {
17397
- return txs.map((t) => ({
17398
- delegateCall: t.delegateCall === true,
17399
- revertOnError: t.revertOnError === true,
17400
- gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
17401
- target: t.to ?? ethers.ethers.constants.AddressZero,
17402
- value: t.value ? convertBigNumberishToString(t.value) : '0',
17403
- data: t.data ? t.data.toString() : '0x',
17404
- }));
17504
+ return txs.map((t) => {
17505
+ var _a;
17506
+ return ({
17507
+ delegateCall: t.delegateCall === true,
17508
+ revertOnError: t.revertOnError === true,
17509
+ gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
17510
+ target: (_a = t.to) !== null && _a !== void 0 ? _a : ethers.ethers.constants.AddressZero,
17511
+ value: t.value ? convertBigNumberishToString(t.value) : '0',
17512
+ data: t.data ? t.data.toString() : '0x',
17513
+ });
17514
+ });
17405
17515
  }
17406
17516
  catch (error) {
17407
17517
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -17409,11 +17519,6 @@ const transformGuardianTransactions = (txs) => {
17409
17519
  }
17410
17520
  };
17411
17521
  class GuardianClient {
17412
- transactionAPI;
17413
- messageAPI;
17414
- confirmationScreen;
17415
- crossSdkBridgeEnabled;
17416
- authManager;
17417
17522
  constructor({ confirmationScreen, config, authManager }) {
17418
17523
  const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
17419
17524
  this.confirmationScreen = confirmationScreen;
@@ -17430,145 +17535,157 @@ class GuardianClient {
17430
17535
  return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
17431
17536
  }
17432
17537
  withConfirmationScreenTask(popupWindowSize) {
17433
- return (task) => async () => {
17538
+ return (task) => () => __awaiter$4(this, void 0, void 0, function* () {
17434
17539
  this.confirmationScreen.loading(popupWindowSize);
17435
17540
  try {
17436
- return await task();
17541
+ return yield task();
17437
17542
  }
17438
17543
  catch (err) {
17439
17544
  this.confirmationScreen.closeWindow();
17440
17545
  throw err;
17441
17546
  }
17442
- };
17547
+ });
17443
17548
  }
17444
17549
  withDefaultConfirmationScreenTask(task) {
17445
17550
  return this.withConfirmationScreenTask()(task);
17446
17551
  }
17447
- async evaluateImxTransaction({ payloadHash }) {
17448
- const finallyFn = () => {
17449
- this.confirmationScreen.closeWindow();
17450
- };
17451
- const user = await this.authManager.getUserImx();
17452
- const headers = { Authorization: `Bearer ${user.accessToken}` };
17453
- const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
17454
- transactionID: payloadHash,
17455
- chainType: 'starkex',
17456
- }, { headers }), { finallyFn });
17457
- if (!transactionRes.data.id) {
17458
- throw new Error("Transaction doesn't exists");
17459
- }
17460
- const evaluateImxRes = await this.transactionAPI.evaluateTransaction({
17461
- id: payloadHash,
17462
- transactionEvaluationRequest: {
17463
- chainType: 'starkex',
17464
- },
17465
- }, { headers });
17466
- const { confirmationRequired } = evaluateImxRes.data;
17467
- if (confirmationRequired) {
17468
- if (this.crossSdkBridgeEnabled) {
17469
- throw new Error(transactionRejectedCrossSdkBridgeError);
17470
- }
17471
- const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
17472
- if (!confirmationResult.confirmed) {
17473
- throw new Error('Transaction rejected by user');
17474
- }
17475
- }
17476
- else {
17477
- this.confirmationScreen.closeWindow();
17478
- }
17479
- }
17480
- async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
17481
- const user = await this.authManager.getUserZkEvm();
17482
- const headers = { Authorization: `Bearer ${user.accessToken}` };
17483
- const guardianTransactions = transformGuardianTransactions(metaTransactions);
17484
- try {
17485
- const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
17486
- id: 'evm',
17552
+ evaluateImxTransaction({ payloadHash }) {
17553
+ return __awaiter$4(this, void 0, void 0, function* () {
17554
+ const finallyFn = () => {
17555
+ this.confirmationScreen.closeWindow();
17556
+ };
17557
+ const user = yield this.authManager.getUserImx();
17558
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
17559
+ const transactionRes = yield retryWithDelay(() => __awaiter$4(this, void 0, void 0, function* () {
17560
+ return this.transactionAPI.getTransactionByID({
17561
+ transactionID: payloadHash,
17562
+ chainType: 'starkex',
17563
+ }, { headers });
17564
+ }), { finallyFn });
17565
+ if (!transactionRes.data.id) {
17566
+ throw new Error("Transaction doesn't exists");
17567
+ }
17568
+ const evaluateImxRes = yield this.transactionAPI.evaluateTransaction({
17569
+ id: payloadHash,
17487
17570
  transactionEvaluationRequest: {
17488
- chainType: 'evm',
17489
- chainId,
17490
- transactionData: {
17491
- nonce,
17492
- userAddress: user.zkEvm.ethAddress,
17493
- metaTransactions: guardianTransactions,
17494
- },
17571
+ chainType: 'starkex',
17495
17572
  },
17496
17573
  }, { headers });
17497
- return transactionEvaluationResponseAxiosResponse.data;
17498
- }
17499
- catch (error) {
17500
- const errorMessage = error instanceof Error ? error.message : String(error);
17501
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
17502
- }
17574
+ const { confirmationRequired } = evaluateImxRes.data;
17575
+ if (confirmationRequired) {
17576
+ if (this.crossSdkBridgeEnabled) {
17577
+ throw new Error(transactionRejectedCrossSdkBridgeError);
17578
+ }
17579
+ const confirmationResult = yield this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
17580
+ if (!confirmationResult.confirmed) {
17581
+ throw new Error('Transaction rejected by user');
17582
+ }
17583
+ }
17584
+ else {
17585
+ this.confirmationScreen.closeWindow();
17586
+ }
17587
+ });
17503
17588
  }
17504
- async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
17505
- const transactionEvaluationResponse = await this.evaluateEVMTransaction({
17506
- chainId,
17507
- nonce,
17508
- metaTransactions,
17589
+ evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
17590
+ return __awaiter$4(this, void 0, void 0, function* () {
17591
+ const user = yield this.authManager.getUserZkEvm();
17592
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
17593
+ const guardianTransactions = transformGuardianTransactions(metaTransactions);
17594
+ try {
17595
+ const transactionEvaluationResponseAxiosResponse = yield this.transactionAPI.evaluateTransaction({
17596
+ id: 'evm',
17597
+ transactionEvaluationRequest: {
17598
+ chainType: 'evm',
17599
+ chainId,
17600
+ transactionData: {
17601
+ nonce,
17602
+ userAddress: user.zkEvm.ethAddress,
17603
+ metaTransactions: guardianTransactions,
17604
+ },
17605
+ },
17606
+ }, { headers });
17607
+ return transactionEvaluationResponseAxiosResponse.data;
17608
+ }
17609
+ catch (error) {
17610
+ const errorMessage = error instanceof Error ? error.message : String(error);
17611
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
17612
+ }
17509
17613
  });
17510
- const { confirmationRequired, transactionId } = transactionEvaluationResponse;
17511
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
17512
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
17513
- }
17514
- if (confirmationRequired && !!transactionId) {
17515
- const user = await this.authManager.getUserZkEvm();
17516
- const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
17517
- if (!confirmationResult.confirmed) {
17518
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
17614
+ }
17615
+ validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
17616
+ return __awaiter$4(this, void 0, void 0, function* () {
17617
+ const transactionEvaluationResponse = yield this.evaluateEVMTransaction({
17618
+ chainId,
17619
+ nonce,
17620
+ metaTransactions,
17621
+ });
17622
+ const { confirmationRequired, transactionId } = transactionEvaluationResponse;
17623
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
17624
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
17625
+ }
17626
+ if (confirmationRequired && !!transactionId) {
17627
+ const user = yield this.authManager.getUserZkEvm();
17628
+ const confirmationResult = yield this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
17629
+ if (!confirmationResult.confirmed) {
17630
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
17631
+ }
17519
17632
  }
17520
- }
17521
- else {
17522
- this.confirmationScreen.closeWindow();
17523
- }
17633
+ else {
17634
+ this.confirmationScreen.closeWindow();
17635
+ }
17636
+ });
17524
17637
  }
17525
- async evaluateMessage({ chainID, payload }) {
17526
- try {
17527
- const user = await this.authManager.getUserZkEvm();
17528
- if (user === null) {
17529
- throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
17638
+ evaluateMessage({ chainID, payload }) {
17639
+ return __awaiter$4(this, void 0, void 0, function* () {
17640
+ try {
17641
+ const user = yield this.authManager.getUserZkEvm();
17642
+ if (user === null) {
17643
+ throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
17644
+ }
17645
+ const messageEvalResponse = yield this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
17646
+ return messageEvalResponse.data;
17530
17647
  }
17531
- const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
17532
- return messageEvalResponse.data;
17533
- }
17534
- catch (error) {
17535
- const errorMessage = error instanceof Error ? error.message : String(error);
17536
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
17537
- }
17648
+ catch (error) {
17649
+ const errorMessage = error instanceof Error ? error.message : String(error);
17650
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
17651
+ }
17652
+ });
17538
17653
  }
17539
- async validateMessage({ chainID, payload }) {
17540
- const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
17541
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
17542
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
17543
- }
17544
- if (confirmationRequired && !!messageId) {
17545
- const user = await this.authManager.getUserZkEvm();
17546
- const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
17547
- if (!confirmationResult.confirmed) {
17548
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
17654
+ validateMessage({ chainID, payload }) {
17655
+ return __awaiter$4(this, void 0, void 0, function* () {
17656
+ const { messageId, confirmationRequired } = yield this.evaluateMessage({ chainID, payload });
17657
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
17658
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
17659
+ }
17660
+ if (confirmationRequired && !!messageId) {
17661
+ const user = yield this.authManager.getUserZkEvm();
17662
+ const confirmationResult = yield this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
17663
+ if (!confirmationResult.confirmed) {
17664
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
17665
+ }
17549
17666
  }
17550
- }
17551
- else {
17552
- this.confirmationScreen.closeWindow();
17553
- }
17667
+ else {
17668
+ this.confirmationScreen.closeWindow();
17669
+ }
17670
+ });
17554
17671
  }
17555
17672
  }
17556
17673
 
17557
17674
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
17558
17675
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
17559
- const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
17676
+ const getMetaTransactions = (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => __awaiter$4(void 0, void 0, void 0, function* () {
17560
17677
  // NOTE: We sign the transaction before getting the fee options because
17561
17678
  // accurate estimation of a transaction gas cost is only possible if the smart
17562
17679
  // wallet contract can actually execute it (in a simulated environment) - and
17563
17680
  // it can only execute signed transactions.
17564
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
17681
+ const signedTransaction = yield getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
17565
17682
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
17566
17683
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
17567
17684
  // used in this transaction. Each fee option has a "recipientAddress" we
17568
17685
  // should transfer the payment to, an amount and a currency. We choose one
17569
17686
  // option and build a transaction that sends the expected currency amount for
17570
17687
  // that option to the specified address.
17571
- const feeOptions = await relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
17688
+ const feeOptions = yield relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
17572
17689
  const imxFeeOption = feeOptions.find((feeOption) => feeOption.tokenSymbol === 'IMX');
17573
17690
  if (!imxFeeOption) {
17574
17691
  throw new Error('Failed to retrieve fees for IMX token');
@@ -17583,16 +17700,16 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
17583
17700
  return [metaTransaction];
17584
17701
  }
17585
17702
  return [metaTransaction, feeMetaTransaction];
17586
- };
17703
+ });
17587
17704
  const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
17588
- .withConfirmationScreen({ width: 480, height: 720 })(async () => {
17705
+ .withConfirmationScreen({ width: 480, height: 720 })(() => __awaiter$4(void 0, void 0, void 0, function* () {
17589
17706
  const transactionRequest = params[0];
17590
17707
  if (!transactionRequest.to) {
17591
17708
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
17592
17709
  }
17593
- const { chainId } = await jsonRpcProvider.ready;
17710
+ const { chainId } = yield jsonRpcProvider.ready;
17594
17711
  const chainIdBigNumber = ethers.BigNumber.from(chainId);
17595
- const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
17712
+ const nonce = yield getNonce(jsonRpcProvider, zkevmAddress);
17596
17713
  const metaTransaction = {
17597
17714
  to: transactionRequest.to,
17598
17715
  data: transactionRequest.data,
@@ -17600,9 +17717,9 @@ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient,
17600
17717
  value: transactionRequest.value,
17601
17718
  revertOnError: true,
17602
17719
  };
17603
- const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
17720
+ const metaTransactions = yield getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
17604
17721
  // Parallelize the validation and signing of the transaction
17605
- const [, signedTransactions] = await Promise.all([
17722
+ const [, signedTransactions] = yield Promise.all([
17606
17723
  guardianClient.validateEVMTransaction({
17607
17724
  chainId: getEip155ChainId(chainId),
17608
17725
  nonce: convertBigNumberishToString(nonce),
@@ -17612,9 +17729,9 @@ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient,
17612
17729
  // whole payload is different and needs a new signature.
17613
17730
  getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner),
17614
17731
  ]);
17615
- const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
17616
- const retrieveRelayerTransaction = async () => {
17617
- const tx = await relayerClient.imGetTransactionByHash(relayerId);
17732
+ const relayerId = yield relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
17733
+ const retrieveRelayerTransaction = () => __awaiter$4(void 0, void 0, void 0, function* () {
17734
+ const tx = yield relayerClient.imGetTransactionByHash(relayerId);
17618
17735
  // NOTE: The transaction hash is only available from the Relayer once the
17619
17736
  // transaction is actually submitted onchain. Hence we need to poll the
17620
17737
  // Relayer get transaction endpoint until the status transitions to one that
@@ -17623,8 +17740,8 @@ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient,
17623
17740
  throw new Error();
17624
17741
  }
17625
17742
  return tx;
17626
- };
17627
- const relayerTransaction = await retryWithDelay(retrieveRelayerTransaction, {
17743
+ });
17744
+ const relayerTransaction = yield retryWithDelay(retrieveRelayerTransaction, {
17628
17745
  retries: MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES,
17629
17746
  interval: TRANSACTION_HASH_RETRIEVAL_WAIT,
17630
17747
  finalErr: new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'transaction hash not generated in time'),
@@ -17640,11 +17757,12 @@ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient,
17640
17757
  throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, errorMessage);
17641
17758
  }
17642
17759
  return relayerTransaction.hash;
17643
- });
17760
+ }));
17644
17761
 
17645
17762
  const REQUIRED_TYPED_DATA_PROPERTIES = ['types', 'domain', 'primaryType', 'message'];
17646
17763
  const isValidTypedDataPayload = (typedData) => (REQUIRED_TYPED_DATA_PROPERTIES.every((key) => key in typedData));
17647
17764
  const transformTypedData = (typedData, chainId) => {
17765
+ var _a;
17648
17766
  let transformedTypedData;
17649
17767
  if (typeof typedData === 'string') {
17650
17768
  try {
@@ -17663,7 +17781,7 @@ const transformTypedData = (typedData, chainId) => {
17663
17781
  if (!isValidTypedDataPayload(transformedTypedData)) {
17664
17782
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid typed data argument. The following properties are required: ${REQUIRED_TYPED_DATA_PROPERTIES.join(', ')}`);
17665
17783
  }
17666
- const providedChainId = transformedTypedData.domain?.chainId;
17784
+ const providedChainId = (_a = transformedTypedData.domain) === null || _a === void 0 ? void 0 : _a.chainId;
17667
17785
  if (providedChainId) {
17668
17786
  // domain.chainId (if defined) can be a number, string, or hex value, but the relayer & guardian only accept a number.
17669
17787
  if (typeof providedChainId === 'string') {
@@ -17680,168 +17798,234 @@ const transformTypedData = (typedData, chainId) => {
17680
17798
  }
17681
17799
  return transformedTypedData;
17682
17800
  };
17683
- const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
17684
- .withConfirmationScreen({ width: 480, height: 720 })(async () => {
17685
- const fromAddress = params[0];
17686
- const typedDataParam = params[1];
17687
- if (!fromAddress || !typedDataParam) {
17688
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `${method} requires an address and a typed data JSON`);
17689
- }
17690
- const { chainId } = await jsonRpcProvider.ready;
17691
- const typedData = transformTypedData(typedDataParam, chainId);
17692
- await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
17693
- const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
17694
- return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, ethSigner);
17801
+ const signTypedDataV4 = ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => __awaiter$4(void 0, void 0, void 0, function* () {
17802
+ return guardianClient
17803
+ .withConfirmationScreen({ width: 480, height: 720 })(() => __awaiter$4(void 0, void 0, void 0, function* () {
17804
+ const fromAddress = params[0];
17805
+ const typedDataParam = params[1];
17806
+ if (!fromAddress || !typedDataParam) {
17807
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `${method} requires an address and a typed data JSON`);
17808
+ }
17809
+ const { chainId } = yield jsonRpcProvider.ready;
17810
+ const typedData = transformTypedData(typedDataParam, chainId);
17811
+ yield guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
17812
+ const relayerSignature = yield relayerClient.imSignTypedData(fromAddress, typedData);
17813
+ return getSignedTypedData(typedData, relayerSignature, ethers.BigNumber.from(chainId), fromAddress, ethSigner);
17814
+ }));
17695
17815
  });
17696
17816
 
17817
+ var _ZkEvmProvider_instances, _ZkEvmProvider_authManager, _ZkEvmProvider_config, _ZkEvmProvider_eventEmitter, _ZkEvmProvider_guardianClient, _ZkEvmProvider_jsonRpcProvider, _ZkEvmProvider_magicAdapter, _ZkEvmProvider_multiRollupApiClients, _ZkEvmProvider_relayerClient, _ZkEvmProvider_ethSigner, _ZkEvmProvider_signerInitialisationError, _ZkEvmProvider_zkEvmAddress, _ZkEvmProvider_handleLogout, _ZkEvmProvider_initialiseEthSigner, _ZkEvmProvider_getSigner, _ZkEvmProvider_performRequest, _ZkEvmProvider_performJsonRpcRequest;
17697
17818
  const isZkEvmUser = (user) => 'zkEvm' in user;
17698
17819
  class ZkEvmProvider {
17699
- #authManager;
17700
- #config;
17701
- #eventEmitter;
17702
- #guardianClient;
17703
- #jsonRpcProvider; // Used for read
17704
- #magicAdapter;
17705
- #multiRollupApiClients;
17706
- #relayerClient;
17707
- /**
17708
- * This property is set during `#initialiseEthSigner` and stores the signer in a promise.
17709
- * This property is not meant to be accessed directly, but through the
17710
- * `#getSigner` method.
17711
- * @see getSigner
17712
- */
17713
- #ethSigner;
17714
- #signerInitialisationError;
17715
- #zkEvmAddress;
17716
- isPassport = true;
17717
17820
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
17718
- this.#authManager = authManager;
17719
- this.#magicAdapter = magicAdapter;
17720
- this.#config = config;
17721
- this.#guardianClient = guardianClient;
17821
+ _ZkEvmProvider_instances.add(this);
17822
+ _ZkEvmProvider_authManager.set(this, void 0);
17823
+ _ZkEvmProvider_config.set(this, void 0);
17824
+ _ZkEvmProvider_eventEmitter.set(this, void 0);
17825
+ _ZkEvmProvider_guardianClient.set(this, void 0);
17826
+ _ZkEvmProvider_jsonRpcProvider.set(this, void 0); // Used for read
17827
+ _ZkEvmProvider_magicAdapter.set(this, void 0);
17828
+ _ZkEvmProvider_multiRollupApiClients.set(this, void 0);
17829
+ _ZkEvmProvider_relayerClient.set(this, void 0);
17830
+ /**
17831
+ * This property is set during `#initialiseEthSigner` and stores the signer in a promise.
17832
+ * This property is not meant to be accessed directly, but through the
17833
+ * `#getSigner` method.
17834
+ * @see getSigner
17835
+ */
17836
+ _ZkEvmProvider_ethSigner.set(this, void 0);
17837
+ _ZkEvmProvider_signerInitialisationError.set(this, void 0);
17838
+ _ZkEvmProvider_zkEvmAddress.set(this, void 0);
17839
+ this.isPassport = true;
17840
+ _ZkEvmProvider_handleLogout.set(this, () => {
17841
+ const shouldEmitAccountsChanged = !!__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f");
17842
+ __classPrivateFieldSet(this, _ZkEvmProvider_ethSigner, undefined, "f");
17843
+ __classPrivateFieldSet(this, _ZkEvmProvider_zkEvmAddress, undefined, "f");
17844
+ if (shouldEmitAccountsChanged) {
17845
+ __classPrivateFieldGet(this, _ZkEvmProvider_eventEmitter, "f").emit(ProviderEvent.ACCOUNTS_CHANGED, []);
17846
+ }
17847
+ });
17848
+ __classPrivateFieldSet(this, _ZkEvmProvider_authManager, authManager, "f");
17849
+ __classPrivateFieldSet(this, _ZkEvmProvider_magicAdapter, magicAdapter, "f");
17850
+ __classPrivateFieldSet(this, _ZkEvmProvider_config, config, "f");
17851
+ __classPrivateFieldSet(this, _ZkEvmProvider_guardianClient, guardianClient, "f");
17722
17852
  if (config.crossSdkBridgeEnabled) {
17723
17853
  // JsonRpcProvider by default sets the referrer as "client".
17724
17854
  // On Unreal 4 this errors as the browser used is expecting a valid URL.
17725
- this.#jsonRpcProvider = new providers.JsonRpcProvider({
17726
- url: this.#config.zkEvmRpcUrl,
17855
+ __classPrivateFieldSet(this, _ZkEvmProvider_jsonRpcProvider, new providers.JsonRpcProvider({
17856
+ url: __classPrivateFieldGet(this, _ZkEvmProvider_config, "f").zkEvmRpcUrl,
17727
17857
  fetchOptions: { referrer: 'http://imtblgamesdk.local' },
17728
- });
17858
+ }), "f");
17729
17859
  }
17730
17860
  else {
17731
- this.#jsonRpcProvider = new providers.JsonRpcProvider(this.#config.zkEvmRpcUrl);
17732
- }
17733
- this.#relayerClient = new RelayerClient({
17734
- config: this.#config,
17735
- jsonRpcProvider: this.#jsonRpcProvider,
17736
- authManager: this.#authManager,
17861
+ __classPrivateFieldSet(this, _ZkEvmProvider_jsonRpcProvider, new providers.JsonRpcProvider(__classPrivateFieldGet(this, _ZkEvmProvider_config, "f").zkEvmRpcUrl), "f");
17862
+ }
17863
+ __classPrivateFieldSet(this, _ZkEvmProvider_relayerClient, new RelayerClient({
17864
+ config: __classPrivateFieldGet(this, _ZkEvmProvider_config, "f"),
17865
+ jsonRpcProvider: __classPrivateFieldGet(this, _ZkEvmProvider_jsonRpcProvider, "f"),
17866
+ authManager: __classPrivateFieldGet(this, _ZkEvmProvider_authManager, "f"),
17867
+ }), "f");
17868
+ __classPrivateFieldSet(this, _ZkEvmProvider_multiRollupApiClients, multiRollupApiClients, "f");
17869
+ __classPrivateFieldSet(this, _ZkEvmProvider_eventEmitter, new TypedEventEmitter(), "f");
17870
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, __classPrivateFieldGet(this, _ZkEvmProvider_handleLogout, "f"));
17871
+ }
17872
+ request(request) {
17873
+ return __awaiter$4(this, void 0, void 0, function* () {
17874
+ try {
17875
+ return __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_performRequest).call(this, request);
17876
+ }
17877
+ catch (error) {
17878
+ if (error instanceof JsonRpcError) {
17879
+ throw error;
17880
+ }
17881
+ if (error instanceof Error) {
17882
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, error.message);
17883
+ }
17884
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Internal error');
17885
+ }
17737
17886
  });
17738
- this.#multiRollupApiClients = multiRollupApiClients;
17739
- this.#eventEmitter = new TypedEventEmitter();
17740
- passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
17741
17887
  }
17742
- #handleLogout = () => {
17743
- const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
17744
- this.#ethSigner = undefined;
17745
- this.#zkEvmAddress = undefined;
17746
- if (shouldEmitAccountsChanged) {
17747
- this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
17888
+ sendAsync(request, callback) {
17889
+ if (!callback) {
17890
+ throw new Error('No callback provided');
17748
17891
  }
17749
- };
17750
- /**
17751
- * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
17752
- * The signer is stored in a promise so that it can be retrieved by the provider
17753
- * when needed.
17754
- *
17755
- * If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
17756
- * so that it doesn't result in an unhandled promise rejection.
17757
- *
17758
- * This error is thrown when the signer is requested through:
17759
- * @see #getSigner
17760
- *
17761
- */
17762
- #initialiseEthSigner(user) {
17763
- const generateSigner = async () => {
17764
- const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
17765
- const web3Provider = new providers.Web3Provider(magicRpcProvider);
17766
- return web3Provider.getSigner();
17767
- };
17768
- // eslint-disable-next-line no-async-promise-executor
17769
- this.#ethSigner = new Promise(async (resolve) => {
17770
- try {
17771
- resolve(await generateSigner());
17892
+ if (Array.isArray(request)) {
17893
+ Promise.all(request.map(__classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_performJsonRpcRequest))).then((result) => {
17894
+ callback(null, result);
17895
+ }).catch((error) => {
17896
+ callback(error, []);
17897
+ });
17898
+ }
17899
+ else {
17900
+ __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_performJsonRpcRequest).call(this, request).then((result) => {
17901
+ callback(null, result);
17902
+ }).catch((error) => {
17903
+ callback(error, null);
17904
+ });
17905
+ }
17906
+ }
17907
+ send(request, callbackOrParams, callback) {
17908
+ return __awaiter$4(this, void 0, void 0, function* () {
17909
+ // Web3 >= 1.0.0-beta.38 calls `send` with method and parameters.
17910
+ if (typeof request === 'string') {
17911
+ if (typeof callbackOrParams === 'function') {
17912
+ return this.sendAsync({
17913
+ method: request,
17914
+ params: [],
17915
+ }, callbackOrParams);
17916
+ }
17917
+ if (callback) {
17918
+ return this.sendAsync({
17919
+ method: request,
17920
+ params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
17921
+ }, callback);
17922
+ }
17923
+ return this.request({
17924
+ method: request,
17925
+ params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
17926
+ });
17772
17927
  }
17773
- catch (err) {
17774
- // Capture and store the initialization error
17775
- this.#signerInitialisationError = err;
17776
- resolve(undefined);
17928
+ // Web3 <= 1.0.0-beta.37 uses `send` with a callback for async queries.
17929
+ if (typeof callbackOrParams === 'function') {
17930
+ return this.sendAsync(request, callbackOrParams);
17931
+ }
17932
+ if (!Array.isArray(request) && typeof request === 'object') {
17933
+ return __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_performJsonRpcRequest).call(this, request);
17777
17934
  }
17935
+ throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
17778
17936
  });
17779
17937
  }
17780
- async #getSigner() {
17781
- const ethSigner = await this.#ethSigner;
17938
+ on(event, listener) {
17939
+ __classPrivateFieldGet(this, _ZkEvmProvider_eventEmitter, "f").on(event, listener);
17940
+ }
17941
+ removeListener(event, listener) {
17942
+ __classPrivateFieldGet(this, _ZkEvmProvider_eventEmitter, "f").removeListener(event, listener);
17943
+ }
17944
+ }
17945
+ _ZkEvmProvider_authManager = new WeakMap(), _ZkEvmProvider_config = new WeakMap(), _ZkEvmProvider_eventEmitter = new WeakMap(), _ZkEvmProvider_guardianClient = new WeakMap(), _ZkEvmProvider_jsonRpcProvider = new WeakMap(), _ZkEvmProvider_magicAdapter = new WeakMap(), _ZkEvmProvider_multiRollupApiClients = new WeakMap(), _ZkEvmProvider_relayerClient = new WeakMap(), _ZkEvmProvider_ethSigner = new WeakMap(), _ZkEvmProvider_signerInitialisationError = new WeakMap(), _ZkEvmProvider_zkEvmAddress = new WeakMap(), _ZkEvmProvider_handleLogout = new WeakMap(), _ZkEvmProvider_instances = new WeakSet(), _ZkEvmProvider_initialiseEthSigner = function _ZkEvmProvider_initialiseEthSigner(user) {
17946
+ const generateSigner = () => __awaiter$4(this, void 0, void 0, function* () {
17947
+ const magicRpcProvider = yield __classPrivateFieldGet(this, _ZkEvmProvider_magicAdapter, "f").login(user.idToken);
17948
+ const web3Provider = new providers.Web3Provider(magicRpcProvider);
17949
+ return web3Provider.getSigner();
17950
+ });
17951
+ // eslint-disable-next-line no-async-promise-executor
17952
+ __classPrivateFieldSet(this, _ZkEvmProvider_ethSigner, new Promise((resolve) => __awaiter$4(this, void 0, void 0, function* () {
17953
+ try {
17954
+ resolve(yield generateSigner());
17955
+ }
17956
+ catch (err) {
17957
+ // Capture and store the initialization error
17958
+ __classPrivateFieldSet(this, _ZkEvmProvider_signerInitialisationError, err, "f");
17959
+ resolve(undefined);
17960
+ }
17961
+ })), "f");
17962
+ }, _ZkEvmProvider_getSigner = function _ZkEvmProvider_getSigner() {
17963
+ return __awaiter$4(this, void 0, void 0, function* () {
17964
+ const ethSigner = yield __classPrivateFieldGet(this, _ZkEvmProvider_ethSigner, "f");
17782
17965
  // Throw the stored error if the signers failed to initialise
17783
17966
  if (typeof ethSigner === 'undefined') {
17784
- if (typeof this.#signerInitialisationError !== 'undefined') {
17785
- throw this.#signerInitialisationError;
17967
+ if (typeof __classPrivateFieldGet(this, _ZkEvmProvider_signerInitialisationError, "f") !== 'undefined') {
17968
+ throw __classPrivateFieldGet(this, _ZkEvmProvider_signerInitialisationError, "f");
17786
17969
  }
17787
17970
  throw new Error('Signer failed to initialise');
17788
17971
  }
17789
17972
  return ethSigner;
17790
- }
17791
- async #performRequest(request) {
17973
+ });
17974
+ }, _ZkEvmProvider_performRequest = function _ZkEvmProvider_performRequest(request) {
17975
+ return __awaiter$4(this, void 0, void 0, function* () {
17792
17976
  switch (request.method) {
17793
17977
  case 'eth_requestAccounts': {
17794
- if (this.#zkEvmAddress) {
17795
- return [this.#zkEvmAddress];
17978
+ if (__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")) {
17979
+ return [__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")];
17796
17980
  }
17797
- const user = await this.#authManager.getUserOrLogin();
17798
- this.#initialiseEthSigner(user);
17981
+ const user = yield __classPrivateFieldGet(this, _ZkEvmProvider_authManager, "f").getUserOrLogin();
17982
+ __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_initialiseEthSigner).call(this, user);
17799
17983
  if (!isZkEvmUser(user)) {
17800
- const ethSigner = await this.#getSigner();
17801
- this.#zkEvmAddress = await registerZkEvmUser({
17984
+ const ethSigner = yield __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_getSigner).call(this);
17985
+ __classPrivateFieldSet(this, _ZkEvmProvider_zkEvmAddress, yield registerZkEvmUser({
17802
17986
  ethSigner,
17803
- authManager: this.#authManager,
17804
- multiRollupApiClients: this.#multiRollupApiClients,
17987
+ authManager: __classPrivateFieldGet(this, _ZkEvmProvider_authManager, "f"),
17988
+ multiRollupApiClients: __classPrivateFieldGet(this, _ZkEvmProvider_multiRollupApiClients, "f"),
17805
17989
  accessToken: user.accessToken,
17806
- jsonRpcProvider: this.#jsonRpcProvider,
17807
- });
17990
+ jsonRpcProvider: __classPrivateFieldGet(this, _ZkEvmProvider_jsonRpcProvider, "f"),
17991
+ }), "f");
17808
17992
  }
17809
17993
  else {
17810
- this.#zkEvmAddress = user.zkEvm.ethAddress;
17994
+ __classPrivateFieldSet(this, _ZkEvmProvider_zkEvmAddress, user.zkEvm.ethAddress, "f");
17811
17995
  }
17812
- this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
17813
- return [this.#zkEvmAddress];
17996
+ __classPrivateFieldGet(this, _ZkEvmProvider_eventEmitter, "f").emit(ProviderEvent.ACCOUNTS_CHANGED, [__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")]);
17997
+ return [__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")];
17814
17998
  }
17815
17999
  case 'eth_sendTransaction': {
17816
- if (!this.#zkEvmAddress) {
18000
+ if (!__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")) {
17817
18001
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
17818
18002
  }
17819
- const ethSigner = await this.#getSigner();
18003
+ const ethSigner = yield __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_getSigner).call(this);
17820
18004
  return sendTransaction$1({
17821
18005
  params: request.params || [],
17822
18006
  ethSigner,
17823
- guardianClient: this.#guardianClient,
17824
- jsonRpcProvider: this.#jsonRpcProvider,
17825
- relayerClient: this.#relayerClient,
17826
- zkevmAddress: this.#zkEvmAddress,
18007
+ guardianClient: __classPrivateFieldGet(this, _ZkEvmProvider_guardianClient, "f"),
18008
+ jsonRpcProvider: __classPrivateFieldGet(this, _ZkEvmProvider_jsonRpcProvider, "f"),
18009
+ relayerClient: __classPrivateFieldGet(this, _ZkEvmProvider_relayerClient, "f"),
18010
+ zkevmAddress: __classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f"),
17827
18011
  });
17828
18012
  }
17829
18013
  case 'eth_accounts': {
17830
- return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
18014
+ return __classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f") ? [__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")] : [];
17831
18015
  }
17832
18016
  case 'eth_signTypedData':
17833
18017
  case 'eth_signTypedData_v4': {
17834
- if (!this.#zkEvmAddress) {
18018
+ if (!__classPrivateFieldGet(this, _ZkEvmProvider_zkEvmAddress, "f")) {
17835
18019
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
17836
18020
  }
17837
- const ethSigner = await this.#getSigner();
18021
+ const ethSigner = yield __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_getSigner).call(this);
17838
18022
  return signTypedDataV4({
17839
18023
  method: request.method,
17840
18024
  params: request.params || [],
17841
18025
  ethSigner,
17842
- jsonRpcProvider: this.#jsonRpcProvider,
17843
- relayerClient: this.#relayerClient,
17844
- guardianClient: this.#guardianClient,
18026
+ jsonRpcProvider: __classPrivateFieldGet(this, _ZkEvmProvider_jsonRpcProvider, "f"),
18027
+ relayerClient: __classPrivateFieldGet(this, _ZkEvmProvider_relayerClient, "f"),
18028
+ guardianClient: __classPrivateFieldGet(this, _ZkEvmProvider_guardianClient, "f"),
17845
18029
  });
17846
18030
  }
17847
18031
  // Pass through methods
@@ -17858,17 +18042,18 @@ class ZkEvmProvider {
17858
18042
  case 'eth_getTransactionByHash':
17859
18043
  case 'eth_getTransactionReceipt':
17860
18044
  case 'eth_getTransactionCount': {
17861
- return this.#jsonRpcProvider.send(request.method, request.params || []);
18045
+ return __classPrivateFieldGet(this, _ZkEvmProvider_jsonRpcProvider, "f").send(request.method, request.params || []);
17862
18046
  }
17863
18047
  default: {
17864
18048
  throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
17865
18049
  }
17866
18050
  }
17867
- }
17868
- async #performJsonRpcRequest(request) {
18051
+ });
18052
+ }, _ZkEvmProvider_performJsonRpcRequest = function _ZkEvmProvider_performJsonRpcRequest(request) {
18053
+ return __awaiter$4(this, void 0, void 0, function* () {
17869
18054
  const { id, jsonrpc } = request;
17870
18055
  try {
17871
- const result = await this.#performRequest(request);
18056
+ const result = yield __classPrivateFieldGet(this, _ZkEvmProvider_instances, "m", _ZkEvmProvider_performRequest).call(this, request);
17872
18057
  return {
17873
18058
  id,
17874
18059
  jsonrpc,
@@ -17892,76 +18077,8 @@ class ZkEvmProvider {
17892
18077
  error: jsonRpcError,
17893
18078
  };
17894
18079
  }
17895
- }
17896
- async request(request) {
17897
- try {
17898
- return this.#performRequest(request);
17899
- }
17900
- catch (error) {
17901
- if (error instanceof JsonRpcError) {
17902
- throw error;
17903
- }
17904
- if (error instanceof Error) {
17905
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, error.message);
17906
- }
17907
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Internal error');
17908
- }
17909
- }
17910
- sendAsync(request, callback) {
17911
- if (!callback) {
17912
- throw new Error('No callback provided');
17913
- }
17914
- if (Array.isArray(request)) {
17915
- Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
17916
- callback(null, result);
17917
- }).catch((error) => {
17918
- callback(error, []);
17919
- });
17920
- }
17921
- else {
17922
- this.#performJsonRpcRequest(request).then((result) => {
17923
- callback(null, result);
17924
- }).catch((error) => {
17925
- callback(error, null);
17926
- });
17927
- }
17928
- }
17929
- async send(request, callbackOrParams, callback) {
17930
- // Web3 >= 1.0.0-beta.38 calls `send` with method and parameters.
17931
- if (typeof request === 'string') {
17932
- if (typeof callbackOrParams === 'function') {
17933
- return this.sendAsync({
17934
- method: request,
17935
- params: [],
17936
- }, callbackOrParams);
17937
- }
17938
- if (callback) {
17939
- return this.sendAsync({
17940
- method: request,
17941
- params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
17942
- }, callback);
17943
- }
17944
- return this.request({
17945
- method: request,
17946
- params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
17947
- });
17948
- }
17949
- // Web3 <= 1.0.0-beta.37 uses `send` with a callback for async queries.
17950
- if (typeof callbackOrParams === 'function') {
17951
- return this.sendAsync(request, callbackOrParams);
17952
- }
17953
- if (!Array.isArray(request) && typeof request === 'object') {
17954
- return this.#performJsonRpcRequest(request);
17955
- }
17956
- throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
17957
- }
17958
- on(event, listener) {
17959
- this.#eventEmitter.on(event, listener);
17960
- }
17961
- removeListener(event, listener) {
17962
- this.#eventEmitter.removeListener(event, listener);
17963
- }
17964
- }
18080
+ });
18081
+ };
17965
18082
 
17966
18083
  const buildImxClientConfig = (passportModuleConfiguration) => {
17967
18084
  if (passportModuleConfiguration.overrides) {
@@ -17973,7 +18090,8 @@ const buildImxClientConfig = (passportModuleConfiguration) => {
17973
18090
  return imxApiConfig.getProduction();
17974
18091
  };
17975
18092
  const buildImxApiClients = (passportModuleConfiguration) => {
17976
- if (passportModuleConfiguration.overrides?.imxApiClients)
18093
+ var _a;
18094
+ if ((_a = passportModuleConfiguration.overrides) === null || _a === void 0 ? void 0 : _a.imxApiClients)
17977
18095
  return passportModuleConfiguration.overrides.imxApiClients;
17978
18096
  const config = buildImxClientConfig(passportModuleConfiguration);
17979
18097
  return new ImxApiClients(config);
@@ -18015,15 +18133,6 @@ const buildPrivateVars = (passportModuleConfiguration) => {
18015
18133
  };
18016
18134
  };
18017
18135
  class Passport {
18018
- authManager;
18019
- config;
18020
- confirmationScreen;
18021
- immutableXClient;
18022
- magicAdapter;
18023
- multiRollupApiClients;
18024
- passportImxProviderFactory;
18025
- passportEventEmitter;
18026
- guardianClient;
18027
18136
  constructor(passportModuleConfiguration) {
18028
18137
  const privateVars = buildPrivateVars(passportModuleConfiguration);
18029
18138
  this.config = privateVars.config;
@@ -18042,11 +18151,15 @@ class Passport {
18042
18151
  * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
18043
18152
  * `connectImx` instead.
18044
18153
  */
18045
- async connectImxSilent() {
18046
- return this.passportImxProviderFactory.getProviderSilent();
18154
+ connectImxSilent() {
18155
+ return __awaiter$4(this, void 0, void 0, function* () {
18156
+ return this.passportImxProviderFactory.getProviderSilent();
18157
+ });
18047
18158
  }
18048
- async connectImx() {
18049
- return this.passportImxProviderFactory.getProvider();
18159
+ connectImx() {
18160
+ return __awaiter$4(this, void 0, void 0, function* () {
18161
+ return this.passportImxProviderFactory.getProvider();
18162
+ });
18050
18163
  }
18051
18164
  connectEvm() {
18052
18165
  return new ZkEvmProvider({
@@ -18067,57 +18180,69 @@ class Passport {
18067
18180
  * @param options.anonymousId - If provided, Passport internal metrics will be enriched with this value.
18068
18181
  * @returns {Promise<UserProfile | null>} the user profile if the user is logged in, otherwise null
18069
18182
  */
18070
- async login(options) {
18071
- const { useCachedSession = false } = options || {};
18072
- let user = null;
18073
- try {
18074
- user = await this.authManager.getUser();
18075
- }
18076
- catch (error) {
18077
- if (useCachedSession) {
18078
- throw error;
18183
+ login(options) {
18184
+ return __awaiter$4(this, void 0, void 0, function* () {
18185
+ const { useCachedSession = false } = options || {};
18186
+ let user = null;
18187
+ try {
18188
+ user = yield this.authManager.getUser();
18079
18189
  }
18080
- logger$f.warn('Failed to retrieve a cached user session', error);
18081
- }
18082
- if (!user && !useCachedSession) {
18083
- user = await this.authManager.login(options?.anonymousId);
18084
- }
18085
- if (user) {
18086
- identify({
18087
- passportId: user.profile.sub,
18088
- });
18089
- }
18090
- return user ? user.profile : null;
18190
+ catch (error) {
18191
+ if (useCachedSession) {
18192
+ throw error;
18193
+ }
18194
+ logger$f.warn('Failed to retrieve a cached user session', error);
18195
+ }
18196
+ if (!user && !useCachedSession) {
18197
+ user = yield this.authManager.login(options === null || options === void 0 ? void 0 : options.anonymousId);
18198
+ }
18199
+ if (user) {
18200
+ identify({
18201
+ passportId: user.profile.sub,
18202
+ });
18203
+ }
18204
+ return user ? user.profile : null;
18205
+ });
18091
18206
  }
18092
- async loginCallback() {
18093
- return this.authManager.loginCallback();
18207
+ loginCallback() {
18208
+ return __awaiter$4(this, void 0, void 0, function* () {
18209
+ return this.authManager.loginCallback();
18210
+ });
18094
18211
  }
18095
- async loginWithDeviceFlow(options) {
18096
- return this.authManager.loginWithDeviceFlow(options?.anonymousId);
18212
+ loginWithDeviceFlow(options) {
18213
+ return __awaiter$4(this, void 0, void 0, function* () {
18214
+ return this.authManager.loginWithDeviceFlow(options === null || options === void 0 ? void 0 : options.anonymousId);
18215
+ });
18097
18216
  }
18098
- async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
18099
- const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
18100
- return user.profile;
18217
+ loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
18218
+ return __awaiter$4(this, void 0, void 0, function* () {
18219
+ const user = yield this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
18220
+ return user.profile;
18221
+ });
18101
18222
  }
18102
18223
  loginWithPKCEFlow() {
18103
18224
  return this.authManager.getPKCEAuthorizationUrl();
18104
18225
  }
18105
- async loginWithPKCEFlowCallback(authorizationCode, state) {
18106
- const user = await this.authManager.loginWithPKCEFlowCallback(authorizationCode, state);
18107
- return user.profile;
18226
+ loginWithPKCEFlowCallback(authorizationCode, state) {
18227
+ return __awaiter$4(this, void 0, void 0, function* () {
18228
+ const user = yield this.authManager.loginWithPKCEFlowCallback(authorizationCode, state);
18229
+ return user.profile;
18230
+ });
18108
18231
  }
18109
- async logout() {
18110
- try {
18111
- await this.confirmationScreen.logout();
18112
- }
18113
- catch (err) {
18114
- logger$f.warn('Failed to logout from confirmation screen', err);
18115
- }
18116
- await Promise.allSettled([
18117
- this.authManager.logout(),
18118
- this.magicAdapter.logout(),
18119
- ]);
18120
- this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
18232
+ logout() {
18233
+ return __awaiter$4(this, void 0, void 0, function* () {
18234
+ try {
18235
+ yield this.confirmationScreen.logout();
18236
+ }
18237
+ catch (err) {
18238
+ logger$f.warn('Failed to logout from confirmation screen', err);
18239
+ }
18240
+ yield Promise.allSettled([
18241
+ this.authManager.logout(),
18242
+ this.magicAdapter.logout(),
18243
+ ]);
18244
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
18245
+ });
18121
18246
  }
18122
18247
  /**
18123
18248
  * Logs the user out of Passport when using device flow authentication.
@@ -18125,42 +18250,54 @@ class Passport {
18125
18250
  * @returns {Promise<string>} The device flow end session endpoint. Consumers are responsible for
18126
18251
  * opening this URL in the same browser that was used to log the user in.
18127
18252
  */
18128
- async logoutDeviceFlow() {
18129
- await this.authManager.removeUser();
18130
- await this.magicAdapter.logout();
18131
- this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
18132
- return this.authManager.getDeviceFlowEndSessionEndpoint();
18253
+ logoutDeviceFlow() {
18254
+ return __awaiter$4(this, void 0, void 0, function* () {
18255
+ yield this.authManager.removeUser();
18256
+ yield this.magicAdapter.logout();
18257
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_OUT);
18258
+ return this.authManager.getDeviceFlowEndSessionEndpoint();
18259
+ });
18133
18260
  }
18134
18261
  /**
18135
18262
  * This method should only be called from the logout redirect uri
18136
18263
  * when logout mode is 'silent'.
18137
18264
  */
18138
- async logoutSilentCallback(url) {
18139
- return this.authManager.logoutSilentCallback(url);
18265
+ logoutSilentCallback(url) {
18266
+ return __awaiter$4(this, void 0, void 0, function* () {
18267
+ return this.authManager.logoutSilentCallback(url);
18268
+ });
18140
18269
  }
18141
- async getUserInfo() {
18142
- const user = await this.authManager.getUser();
18143
- return user?.profile;
18270
+ getUserInfo() {
18271
+ return __awaiter$4(this, void 0, void 0, function* () {
18272
+ const user = yield this.authManager.getUser();
18273
+ return user === null || user === void 0 ? void 0 : user.profile;
18274
+ });
18144
18275
  }
18145
- async getIdToken() {
18146
- const user = await this.authManager.getUser();
18147
- return user?.idToken;
18276
+ getIdToken() {
18277
+ return __awaiter$4(this, void 0, void 0, function* () {
18278
+ const user = yield this.authManager.getUser();
18279
+ return user === null || user === void 0 ? void 0 : user.idToken;
18280
+ });
18148
18281
  }
18149
- async getAccessToken() {
18150
- const user = await this.authManager.getUser();
18151
- return user?.accessToken;
18282
+ getAccessToken() {
18283
+ return __awaiter$4(this, void 0, void 0, function* () {
18284
+ const user = yield this.authManager.getUser();
18285
+ return user === null || user === void 0 ? void 0 : user.accessToken;
18286
+ });
18152
18287
  }
18153
- async getLinkedAddresses() {
18154
- const user = await this.authManager.getUser();
18155
- if (!user?.profile.sub) {
18156
- return [];
18157
- }
18158
- const headers = { Authorization: `Bearer ${user.accessToken}` };
18159
- const linkedAddressesResult = await this.multiRollupApiClients.passportApi.getLinkedAddresses({
18160
- chainName: ChainName$1.ETHEREUM,
18161
- userId: user?.profile.sub,
18162
- }, { headers });
18163
- return linkedAddressesResult.data.linked_addresses;
18288
+ getLinkedAddresses() {
18289
+ return __awaiter$4(this, void 0, void 0, function* () {
18290
+ const user = yield this.authManager.getUser();
18291
+ if (!(user === null || user === void 0 ? void 0 : user.profile.sub)) {
18292
+ return [];
18293
+ }
18294
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
18295
+ const linkedAddressesResult = yield this.multiRollupApiClients.passportApi.getLinkedAddresses({
18296
+ chainName: ChainName$1.ETHEREUM,
18297
+ userId: user === null || user === void 0 ? void 0 : user.profile.sub,
18298
+ }, { headers });
18299
+ return linkedAddressesResult.data.linked_addresses;
18300
+ });
18164
18301
  }
18165
18302
  }
18166
18303
 
@@ -36945,7 +37082,7 @@ const flattenProperties = (properties) => {
36945
37082
  };
36946
37083
 
36947
37084
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
36948
- const SDK_VERSION = '1.13.5';
37085
+ const SDK_VERSION = '1.13.6-alpha';
36949
37086
  const getReferrer = () => {
36950
37087
  if (isNode()) {
36951
37088
  return '';
@@ -42121,7 +42258,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42121
42258
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
42122
42259
  };
42123
42260
 
42124
- const SDK_VERSION_MARKER = '1.13.5';
42261
+ const SDK_VERSION_MARKER = '1.13.6-alpha';
42125
42262
  // This SDK version is replaced by the `yarn build` command ran on the root level
42126
42263
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42127
42264