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