@mocanetwork/airkit 1.6.0-beta.5 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,7 +97,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
97
97
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
98
98
  };
99
99
 
100
- var version = "1.6.0-beta.5";
100
+ var version = "1.6.0";
101
101
  var airkitPackage = {
102
102
  version: version};
103
103
 
@@ -108,6 +108,8 @@ const AirAuthMessageTypes = {
108
108
  LOGIN_REQUEST: "air_auth_login_request",
109
109
  LOGIN_RESPONSE: "air_auth_login_response",
110
110
  LOGIN_SERVICE_RESPONSE: "air_auth_login_service_response",
111
+ UPDATE_SESSION_CONFIG_REQUEST: "air_auth_update_session_config_request",
112
+ UPDATE_SESSION_CONFIG_RESPONSE: "air_auth_update_session_config_response",
111
113
  USER_INFO_REQUEST: "air_auth_user_info_request",
112
114
  USER_INFO_RESPONSE: "air_auth_user_info_response",
113
115
  PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
@@ -116,7 +118,6 @@ const AirAuthMessageTypes = {
116
118
  REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response",
117
119
  WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request",
118
120
  WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response",
119
- INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication",
120
121
  IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
121
122
  SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
122
123
  SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
@@ -130,15 +131,10 @@ const AirAuthMessageTypes = {
130
131
  PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
131
132
  LOGOUT_REQUEST: "air_auth_logout_request",
132
133
  LOGOUT_RESPONSE: "air_auth_logout_response",
133
- RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
134
- INIT_RECOVERY_COMMUNICATION: "air_auth_init_recovery_communication",
135
- RESET_RECOVERY_COMMUNICATION: "air_auth_reset_recovery_communication",
136
134
  START_RECOVERY_REQUEST: "air_start_recovery_request",
137
135
  START_RECOVERY_RESPONSE: "air_start_recovery_response",
138
136
  RECOVERY_REQUEST: "air_auth_recovery_request",
139
137
  RECOVERY_RESPONSE: "air_auth_recovery_response",
140
- INIT_CREDENTIAL_COMMUNICATION: "air_auth_init_credential_communication",
141
- RESET_CREDENTIAL_COMMUNICATION: "air_auth_reset_credential_communication",
142
138
  EXPIRED_LOGOUT_REQUEST: "air_auth_expired_logout_request"
143
139
  };
144
140
 
@@ -146,11 +142,9 @@ const AirCredentialMessageTypes = {
146
142
  SERVICE_STARTED: "air_credential_service_started",
147
143
  INITIALIZATION_REQUEST: "air_credential_initialization_request",
148
144
  INITIALIZATION_RESPONSE: "air_credential_initialization_response",
149
- INIT_AUTH_COMMUNICATION: "air_credential_init_auth_communication",
150
- CREDENTIAL_AUTH_INITIALIZED: "air_credential_auth_initialized",
151
- INIT_WALLET_COMMUNICATION: "air_credential_init_wallet_communication",
152
- CREDENTIAL_WALLET_INITIALIZED: "air_credential_wallet_initialized",
153
145
  CREDENTIAL_IFRAME_VISIBILITY_REQUEST: "air_credential_iframe_visibility_request",
146
+ UPDATE_SESSION_CONFIG_REQUEST: "air_credential_update_session_config_request",
147
+ UPDATE_SESSION_CONFIG_RESPONSE: "air_credential_update_session_config_response",
154
148
  LOGOUT_REQUEST: "air_credential_logout_request",
155
149
  LOGOUT_RESPONSE: "air_credential_logout_response",
156
150
  // New credential operation message types
@@ -165,9 +159,10 @@ const AirRecoveryMessageTypes = {
165
159
  SERVICE_STARTED: "air_recovery_service_started",
166
160
  INITIALIZATION_REQUEST: "air_recovery_initialization_request",
167
161
  INITIALIZATION_RESPONSE: "air_recovery_initialization_response",
168
- INIT_AUTH_COMMUNICATION: "air_recovery_init_auth_communication",
169
162
  RECOVERY_INITIALIZED: "air_recovery_initialized",
170
163
  RECOVERY_IFRAME_VISIBILITY_REQUEST: "air_recovery_iframe_visibility_request",
164
+ UPDATE_SESSION_CONFIG_REQUEST: "air_recovery_update_session_config_request",
165
+ UPDATE_SESSION_CONFIG_RESPONSE: "air_recovery_update_session_config_response",
171
166
  LOGOUT_REQUEST: "air_recovery_logout_request",
172
167
  LOGOUT_RESPONSE: "air_recovery_logout_response"
173
168
  };
@@ -178,8 +173,9 @@ const AirWalletMessageTypes = {
178
173
  INITIALIZATION_RESPONSE: "air_initialization_response",
179
174
  CLOSE_MODAL_REQUEST: "air_close_modal_request",
180
175
  CLOSE_MODAL_RESPONSE: "air_close_modal_response",
181
- INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
182
176
  WALLET_INITIALIZED: "air_wallet_initialized",
177
+ UPDATE_SESSION_CONFIG_REQUEST: "air_wallet_update_session_config_request",
178
+ UPDATE_SESSION_CONFIG_RESPONSE: "air_wallet_update_session_config_response",
183
179
  WALLET_LOGIN_REQUEST: "air_wallet_login_request",
184
180
  WALLET_LOGIN_RESPONSE: "air_wallet_login_response",
185
181
  SETUP_OR_UPDATE_MFA_REQUEST: "air_setup_mfa_request",
@@ -197,8 +193,6 @@ const AirWalletMessageTypes = {
197
193
  IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
198
194
  LOGOUT_REQUEST: "air_logout_request",
199
195
  LOGOUT_RESPONSE: "air_logout_response",
200
- INIT_CREDENTIAL_COMMUNICATION: "air_init_credential_communication",
201
- RESET_CREDENTIAL_COMMUNICATION: "air_reset_credential_communication",
202
196
  INTERNAL_PROVIDER_REQUEST: "air_internal_provider_request",
203
197
  INTERNAL_PROVIDER_RESPONSE: "air_internal_provider_response"
204
198
  };
@@ -728,7 +722,7 @@ class SwitchChainError extends ProviderRpcError {
728
722
  class TransactionRejectedRpcError extends ProviderRpcError {
729
723
  constructor(message) {
730
724
  // Remove the "Version: viem@x.x.x" suffix if present
731
- const cleanMessage = message.replace(/\nVersion:.*$/, '');
725
+ const cleanMessage = message.replace(/\nVersion:.*$/, "");
732
726
  super(cleanMessage);
733
727
  this.code = -32003;
734
728
  this.name = "TransactionRejectedRpcError";
@@ -1685,6 +1679,7 @@ class AirError extends BaseError {}
1685
1679
  new Set(AirClientUserErrors);
1686
1680
  new Set(Object.values(Codes));
1687
1681
 
1682
+ class OutgoingMessageEvent extends MessageEvent {}
1688
1683
  class MessageServiceBase {
1689
1684
  get events$() {
1690
1685
  return this._events$;
@@ -1700,13 +1695,16 @@ class MessageServiceBase {
1700
1695
  this.allowedMessageTypes = allowedMessageTypes;
1701
1696
  this.closeListener = null;
1702
1697
  }
1698
+ static _getName(name, targetName) {
1699
+ return `${name} Service: ${targetName} Channel`;
1700
+ }
1703
1701
  async _open(target) {
1704
1702
  await this.close();
1705
1703
  this.eventSubject = new Subject();
1706
1704
  this._events$ = this.eventSubject.asObservable();
1707
1705
  this._messages$ = this.eventSubject.pipe(map(ev => ev.data));
1708
1706
  this._events$.subscribe(event => {
1709
- const sentOrReceived = event.origin === window.origin ? "sent" : "received";
1707
+ const sentOrReceived = event instanceof OutgoingMessageEvent ? "sent" : "received";
1710
1708
  log.debug(`[${this.name}] Message ${sentOrReceived}:`, JSON.stringify(event.data, bigIntReplacer));
1711
1709
  });
1712
1710
  const handleMessage = async ev => {
@@ -1778,7 +1776,7 @@ class MessageServiceBase {
1778
1776
  log.debug(`[${this.name}] Not opened yet`);
1779
1777
  return;
1780
1778
  }
1781
- this.eventSubject.next(new MessageEvent("message", {
1779
+ this.eventSubject.next(new OutgoingMessageEvent("message", {
1782
1780
  data: clonedMessage,
1783
1781
  origin: window.origin
1784
1782
  }));
@@ -1878,7 +1876,7 @@ class AirWalletProvider {
1878
1876
  if (!loginResult) {
1879
1877
  throw new UnauthorizedProviderError("User is not logged in");
1880
1878
  }
1881
- if (method === "eth_accounts" &&
1879
+ if ((method === "eth_accounts" || method === "eth_requestAccounts") &&
1882
1880
  !__classPrivateFieldGet(this, _AirWalletProvider_isWalletInitialized, "f").call(this) &&
1883
1881
  loginResult?.abstractAccountAddress) {
1884
1882
  return [loginResult.abstractAccountAddress];
@@ -1943,9 +1941,8 @@ const ALLOWED_AUTH_MESSAGES = [
1943
1941
  AirAuthMessageTypes.LOGIN_RESPONSE,
1944
1942
  AirAuthMessageTypes.SETUP_WALLET_REQUEST,
1945
1943
  AirAuthMessageTypes.SETUP_RECOVERY_REQUEST,
1946
- AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
1947
- AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
1948
1944
  AirAuthMessageTypes.LOGOUT_RESPONSE,
1945
+ AirAuthMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
1949
1946
  AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE,
1950
1947
  AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
1951
1948
  AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
@@ -1965,11 +1962,6 @@ class AuthMessageService extends MessageServiceBase {
1965
1962
  const window = authIframe.contentWindow;
1966
1963
  await super._open({ window, origin });
1967
1964
  }
1968
- async initWalletCommunication() {
1969
- await this.sendMessage({
1970
- type: AirAuthMessageTypes.INIT_WALLET_COMMUNICATION,
1971
- });
1972
- }
1973
1965
  async sendPartnerUserInfoRequest() {
1974
1966
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
1975
1967
  await this.sendMessage({
@@ -1978,6 +1970,11 @@ class AuthMessageService extends MessageServiceBase {
1978
1970
  });
1979
1971
  return response;
1980
1972
  }
1973
+ async sendUpdateSessionConfigRequest(payload) {
1974
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
1975
+ await this.sendMessage({ type: AirAuthMessageTypes.UPDATE_SESSION_CONFIG_REQUEST, payload });
1976
+ return response;
1977
+ }
1981
1978
  async sendLoginRequest(payload) {
1982
1979
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LOGIN_RESPONSE)));
1983
1980
  await this.sendMessage({ type: AirAuthMessageTypes.LOGIN_REQUEST, payload });
@@ -1991,9 +1988,6 @@ class AuthMessageService extends MessageServiceBase {
1991
1988
  await this.sendMessage({ type: AirAuthMessageTypes.LOGOUT_REQUEST });
1992
1989
  return response;
1993
1990
  }
1994
- async resetWalletCommunication() {
1995
- await this.sendMessage({ type: AirAuthMessageTypes.RESET_WALLET_COMMUNICATION });
1996
- }
1997
1991
  async sendInitializationRequest(payload) {
1998
1992
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
1999
1993
  await this.sendMessage({ type: AirAuthMessageTypes.INITIALIZATION_REQUEST, payload });
@@ -2010,16 +2004,6 @@ class AuthMessageService extends MessageServiceBase {
2010
2004
  async sendSetupWalletErrorResponse(error) {
2011
2005
  await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
2012
2006
  }
2013
- async initRecoveryCommunication() {
2014
- await this.sendMessage({
2015
- type: AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION,
2016
- });
2017
- }
2018
- async resetRecoveryCommunication() {
2019
- await this.sendMessage({
2020
- type: AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION,
2021
- });
2022
- }
2023
2007
  async sendSetupRecoverySuccessResponse() {
2024
2008
  await this.sendMessage({
2025
2009
  type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
@@ -2056,19 +2040,6 @@ class AuthMessageService extends MessageServiceBase {
2056
2040
  await this.sendMessage({ type: AirAuthMessageTypes.START_RECOVERY_REQUEST, payload });
2057
2041
  return response;
2058
2042
  }
2059
- /*
2060
- * Initialize credential communication
2061
- */
2062
- async initCredentialCommunication() {
2063
- await this.sendMessage({
2064
- type: AirAuthMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
2065
- });
2066
- }
2067
- async resetCredentialCommunication() {
2068
- await this.sendMessage({
2069
- type: AirAuthMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
2070
- });
2071
- }
2072
2043
  }
2073
2044
  _a$3 = AuthMessageService;
2074
2045
  _AuthMessageService_instance = { value: void 0 };
@@ -2077,8 +2048,7 @@ var _a$2, _CredentialMessageService_instance;
2077
2048
  const ALLOWED_CREDENTIAL_MESSAGES = [
2078
2049
  AirCredentialMessageTypes.INITIALIZATION_RESPONSE,
2079
2050
  AirCredentialMessageTypes.CREDENTIAL_IFRAME_VISIBILITY_REQUEST,
2080
- AirCredentialMessageTypes.CREDENTIAL_AUTH_INITIALIZED,
2081
- AirCredentialMessageTypes.CREDENTIAL_WALLET_INITIALIZED,
2051
+ AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
2082
2052
  AirCredentialMessageTypes.LOGOUT_RESPONSE,
2083
2053
  AirCredentialMessageTypes.ISSUE_CREDENTIAL_RESPONSE,
2084
2054
  AirCredentialMessageTypes.VERIFY_CREDENTIAL_RESPONSE,
@@ -2104,17 +2074,11 @@ class CredentialMessageService extends MessageServiceBase {
2104
2074
  });
2105
2075
  return response;
2106
2076
  }
2107
- async initAuthCommunication() {
2108
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.CREDENTIAL_AUTH_INITIALIZED)));
2109
- await this.sendMessage({
2110
- type: AirCredentialMessageTypes.INIT_AUTH_COMMUNICATION,
2111
- });
2112
- return response;
2113
- }
2114
- async initWalletCommunication() {
2115
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.CREDENTIAL_WALLET_INITIALIZED)));
2077
+ async sendUpdateSessionConfigRequest(payload) {
2078
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
2116
2079
  await this.sendMessage({
2117
- type: AirCredentialMessageTypes.INIT_WALLET_COMMUNICATION,
2080
+ type: AirCredentialMessageTypes.UPDATE_SESSION_CONFIG_REQUEST,
2081
+ payload,
2118
2082
  });
2119
2083
  return response;
2120
2084
  }
@@ -2238,14 +2202,17 @@ class RecoveryMessageService extends MessageServiceBase {
2238
2202
  });
2239
2203
  return response;
2240
2204
  }
2241
- async initAuthCommunication() {
2242
- await this.sendMessage({
2243
- type: AirRecoveryMessageTypes.INIT_AUTH_COMMUNICATION,
2244
- });
2245
- }
2246
2205
  async onInitialized() {
2247
2206
  return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.RECOVERY_INITIALIZED)));
2248
2207
  }
2208
+ async sendUpdateSessionConfigRequest(payload) {
2209
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
2210
+ await this.sendMessage({
2211
+ type: AirRecoveryMessageTypes.UPDATE_SESSION_CONFIG_REQUEST,
2212
+ payload,
2213
+ });
2214
+ return response;
2215
+ }
2249
2216
  async logout() {
2250
2217
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirRecoveryMessageTypes.LOGOUT_RESPONSE)));
2251
2218
  await this.sendMessage({ type: AirRecoveryMessageTypes.LOGOUT_REQUEST });
@@ -2265,6 +2232,7 @@ var _a, _WalletMessageService_instance;
2265
2232
  const ALLOWED_WALLET_MESSAGES = [
2266
2233
  AirWalletMessageTypes.INITIALIZATION_RESPONSE,
2267
2234
  AirWalletMessageTypes.WALLET_INITIALIZED,
2235
+ AirWalletMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE,
2268
2236
  AirWalletMessageTypes.WALLET_LOGIN_RESPONSE,
2269
2237
  AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE,
2270
2238
  AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE,
@@ -2289,14 +2257,6 @@ class WalletMessageService extends MessageServiceBase {
2289
2257
  const window = walletIframe.contentWindow;
2290
2258
  await super._open({ window, origin });
2291
2259
  }
2292
- async initAuthCommunication(skipWalletLogin) {
2293
- await this.sendMessage({
2294
- type: AirWalletMessageTypes.INIT_AUTH_COMMUNICATION,
2295
- payload: {
2296
- skipWalletLogin,
2297
- },
2298
- });
2299
- }
2300
2260
  async sendDeploySmartAccountRequest() {
2301
2261
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
2302
2262
  await this.sendMessage({
@@ -2324,6 +2284,11 @@ class WalletMessageService extends MessageServiceBase {
2324
2284
  onInitialized() {
2325
2285
  return firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_INITIALIZED)));
2326
2286
  }
2287
+ async sendUpdateSessionConfigRequest(payload) {
2288
+ const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.UPDATE_SESSION_CONFIG_RESPONSE)));
2289
+ await this.sendMessage({ type: AirWalletMessageTypes.UPDATE_SESSION_CONFIG_REQUEST, payload });
2290
+ return response;
2291
+ }
2327
2292
  async sendLoginRequest() {
2328
2293
  const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirWalletMessageTypes.WALLET_LOGIN_RESPONSE)));
2329
2294
  await this.sendMessage({
@@ -2390,16 +2355,6 @@ class WalletMessageService extends MessageServiceBase {
2390
2355
  });
2391
2356
  return response;
2392
2357
  }
2393
- async initCredentialCommunication() {
2394
- await this.sendMessage({
2395
- type: AirWalletMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
2396
- });
2397
- }
2398
- async resetCredentialCommunication() {
2399
- await this.sendMessage({
2400
- type: AirWalletMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
2401
- });
2402
- }
2403
2358
  }
2404
2359
  _a = WalletMessageService;
2405
2360
  _WalletMessageService_instance = { value: void 0 };
@@ -2541,7 +2496,7 @@ class WindowService {
2541
2496
  ]);
2542
2497
  return (await response).data;
2543
2498
  }
2544
- async openAndInitializeWalletServiceWindow({ url, windowId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
2499
+ async openAndInitializeWalletServiceWindow({ url, windowId, sessionId, partnerId, enableLogging, onRetry, sdkVersion, enableAutomation, }) {
2545
2500
  if (this.windowControllers.has(windowId)) {
2546
2501
  throw new Error("Window controller already exists");
2547
2502
  }
@@ -2559,6 +2514,7 @@ class WindowService {
2559
2514
  try {
2560
2515
  channel = new MessageChannel();
2561
2516
  const { payload } = await this.sendWindowInitializationRequest(windowId, {
2517
+ sessionId,
2562
2518
  partnerId,
2563
2519
  enableLogging,
2564
2520
  sdkVersion,
@@ -2598,7 +2554,7 @@ class WindowService {
2598
2554
  }
2599
2555
  var WindowService$1 = WindowService.instance;
2600
2556
 
2601
- var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airAuthListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_recoveryInitialization, _AirService_recoveryMessagingService, _AirService_recoveryIframeController, _AirService_credentialsInitialization, _AirService_credentialMessagingService, _AirService_credentialIframeController, _AirService_ensureCredential, _AirService_initializeCredentials, _AirService_subscribeToCredentialEvents, _AirService_cleanUpCredential, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet, _AirService_ensureRecovery, _AirService_initializeRecovery, _AirService_subscribeToRecoveryEvents, _AirService_cleanUpRecovery;
2557
+ var _AirService_instances, _AirService_loginResult, _AirService_buildEnv, _AirService_enableLogging, _AirService_partnerId, _AirService_sessionId, _AirService_sessionConfig, _AirService_authMessagingService, _AirService_authIframeController, _AirService_isAuthInitialized, _AirService_airEventListener, _AirService_walletMessagingService, _AirService_walletIframeController, _AirService_walletInitialization, _AirService_walletLoggedInResult, _AirService_airWalletProvider, _AirService_recoveryInitialization, _AirService_recoveryMessagingService, _AirService_recoveryIframeController, _AirService_credentialsInitialization, _AirService_credentialMessagingService, _AirService_credentialIframeController, _AirService_assertInitialized, _AirService_assertLoggedIn, _AirService_ensureCredential, _AirService_initializeCredentials, _AirService_subscribeToCredentialEvents, _AirService_cleanUpCredential, _AirService_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet, _AirService_ensureRecovery, _AirService_initializeRecovery, _AirService_subscribeToRecoveryEvents, _AirService_cleanUpRecovery;
2602
2558
  const airKitVersion = airkitPackage.version;
2603
2559
  class AirService {
2604
2560
  constructor({ partnerId }) {
@@ -2607,11 +2563,13 @@ class AirService {
2607
2563
  _AirService_buildEnv.set(this, void 0);
2608
2564
  _AirService_enableLogging.set(this, false);
2609
2565
  _AirService_partnerId.set(this, void 0);
2566
+ _AirService_sessionId.set(this, void 0);
2567
+ _AirService_sessionConfig.set(this, void 0);
2610
2568
  //#modalZIndex: number; TODO implement z index overwrite
2611
2569
  _AirService_authMessagingService.set(this, void 0);
2612
2570
  _AirService_authIframeController.set(this, void 0);
2613
2571
  _AirService_isAuthInitialized.set(this, false);
2614
- _AirService_airAuthListener.set(this, []);
2572
+ _AirService_airEventListener.set(this, []);
2615
2573
  _AirService_walletMessagingService.set(this, void 0);
2616
2574
  _AirService_walletIframeController.set(this, void 0);
2617
2575
  _AirService_walletInitialization.set(this, void 0);
@@ -2661,15 +2619,17 @@ class AirService {
2661
2619
  shouldEnableAutomation() {
2662
2620
  return localStorage.getItem("automation") === "true" && __classPrivateFieldGet(this, _AirService_buildEnv, "f") !== BUILD_ENV.PRODUCTION;
2663
2621
  }
2664
- async init({ buildEnv = BUILD_ENV.PRODUCTION, enableLogging = false, skipRehydration = false, }) {
2622
+ async init({ buildEnv = BUILD_ENV.PRODUCTION, enableLogging = false, skipRehydration = false, sessionConfig = undefined, }) {
2665
2623
  if (!__classPrivateFieldGet(this, _AirService_partnerId, "f"))
2666
- throw new Error("Partner ID is required to initialize auth service");
2624
+ throw new AirServiceError("CLIENT_ERROR", "Partner ID is required to initialize the service");
2667
2625
  if (__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2668
- return;
2626
+ return __classPrivateFieldGet(this, _AirService_loginResult, "f") ?? null;
2669
2627
  __classPrivateFieldSet(this, _AirService_buildEnv, buildEnv, "f");
2670
2628
  __classPrivateFieldSet(this, _AirService_enableLogging, enableLogging, "f");
2629
+ __classPrivateFieldSet(this, _AirService_sessionConfig, sessionConfig, "f");
2671
2630
  const { authUrl } = AIR_URLS[buildEnv];
2672
2631
  configureLogLevel(buildEnv, enableLogging);
2632
+ __classPrivateFieldSet(this, _AirService_sessionId, randomId(), "f");
2673
2633
  const authIframeOrigin = new URL(authUrl).origin;
2674
2634
  __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController("air-auth", authUrl), "f");
2675
2635
  try {
@@ -2719,12 +2679,14 @@ class AirService {
2719
2679
  if (ev.data === AirAuthMessageTypes.AUTH_SETUP_COMPLETED) {
2720
2680
  window.removeEventListener("message", handleAuthMessage);
2721
2681
  const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendInitializationRequest({
2682
+ sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
2722
2683
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
2723
2684
  skipRehydration,
2724
2685
  partnerDAppUrl: window.location.href,
2725
2686
  sdkVersion: airKitVersion,
2726
2687
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
2727
2688
  enableAutomation: this.shouldEnableAutomation(),
2689
+ sessionConfig,
2728
2690
  });
2729
2691
  if (payload.success === true) {
2730
2692
  resolve(payload);
@@ -2750,13 +2712,12 @@ class AirService {
2750
2712
  catch (error) {
2751
2713
  log.debug("Error initializing auth service", error);
2752
2714
  await this.cleanUp();
2753
- throw error;
2715
+ throw AirServiceError.from(error);
2754
2716
  }
2755
2717
  return null;
2756
2718
  }
2757
2719
  async login(options) {
2758
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2759
- throw new Error("Service is not initialized");
2720
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
2760
2721
  if (__classPrivateFieldGet(this, _AirService_loginResult, "f"))
2761
2722
  return __classPrivateFieldGet(this, _AirService_loginResult, "f");
2762
2723
  const { payload } = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLoginRequest({
@@ -2773,38 +2734,24 @@ class AirService {
2773
2734
  * @experimental This method is experimental and will change in the future.
2774
2735
  */
2775
2736
  async deploySmartAccount() {
2776
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2777
- throw new Error("Service is not initialized");
2778
2737
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2779
- try {
2780
- log.info("deploySmartAccount");
2781
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendDeploySmartAccountRequest();
2782
- if (payload.success === false) {
2783
- throw new AirServiceError(payload.errorName, payload.errorMessage);
2784
- }
2785
- return { txHash: payload.txHash };
2786
- }
2787
- catch (error) {
2788
- throw AirServiceError.from(error);
2738
+ log.info("deploySmartAccount");
2739
+ const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendDeploySmartAccountRequest();
2740
+ if (payload.success === false) {
2741
+ throw new AirServiceError(payload.errorName, payload.errorMessage);
2789
2742
  }
2743
+ return { txHash: payload.txHash };
2790
2744
  }
2791
2745
  /**
2792
2746
  * @experimental This method is experimental and will change in the future.
2793
2747
  */
2794
2748
  async isSmartAccountDeployed() {
2795
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2796
- throw new Error("Service is not initialized");
2797
2749
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2798
- try {
2799
- const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendIsSmartAccountDeployedRequest();
2800
- if (payload.success === false) {
2801
- throw new AirServiceError(payload.errorName, payload.errorMessage);
2802
- }
2803
- return payload.isDeployed;
2804
- }
2805
- catch (error) {
2806
- throw AirServiceError.from(error);
2750
+ const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendIsSmartAccountDeployedRequest();
2751
+ if (payload.success === false) {
2752
+ throw new AirServiceError(payload.errorName, payload.errorMessage);
2807
2753
  }
2754
+ return payload.isDeployed;
2808
2755
  }
2809
2756
  getProvider() {
2810
2757
  return this.provider;
@@ -2856,8 +2803,7 @@ class AirService {
2856
2803
  }
2857
2804
  }
2858
2805
  async getUserInfo() {
2859
- if (!this.isLoggedIn)
2860
- throw new Error("User not logged in");
2806
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
2861
2807
  const info = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerUserInfoRequest();
2862
2808
  if (info.payload.success === false) {
2863
2809
  throw new AirServiceError(info.payload.errorName, info.payload.errorMessage);
@@ -2874,11 +2820,37 @@ class AirService {
2874
2820
  },
2875
2821
  };
2876
2822
  }
2823
+ async updateSessionConfig(config) {
2824
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
2825
+ __classPrivateFieldSet(this, _AirService_sessionConfig, config, "f");
2826
+ const resultsPromise = [__classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendUpdateSessionConfigRequest(config)];
2827
+ if (__classPrivateFieldGet(this, _AirService_walletInitialization, "f")) {
2828
+ resultsPromise.push(__classPrivateFieldGet(this, _AirService_walletInitialization, "f")
2829
+ .then(() => __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendUpdateSessionConfigRequest(config))
2830
+ .catch(() => null));
2831
+ }
2832
+ if (__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")) {
2833
+ resultsPromise.push(__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")
2834
+ .then(() => __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").sendUpdateSessionConfigRequest(config))
2835
+ .catch(() => null));
2836
+ }
2837
+ if (__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")) {
2838
+ resultsPromise.push(__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")
2839
+ .then(() => __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").sendUpdateSessionConfigRequest(config))
2840
+ .catch(() => null));
2841
+ }
2842
+ const results = await Promise.all(resultsPromise);
2843
+ for (const result of results) {
2844
+ if (result && result.payload.success === false) {
2845
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2846
+ }
2847
+ }
2848
+ const sessionConfig = { locale: results[0].payload.locale };
2849
+ __classPrivateFieldSet(this, _AirService_sessionConfig, sessionConfig, "f");
2850
+ return sessionConfig;
2851
+ }
2877
2852
  async goToPartner(partnerUrl) {
2878
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2879
- throw new Error("Service is not initialized");
2880
- if (!this.isLoggedIn)
2881
- throw new Error("No active session to generate token");
2853
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
2882
2854
  const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCrossPartnerTokenRequest(partnerUrl);
2883
2855
  if (result.payload.success === false) {
2884
2856
  throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
@@ -2888,35 +2860,24 @@ class AirService {
2888
2860
  };
2889
2861
  }
2890
2862
  async startRecovery(payload) {
2891
- try {
2892
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
2893
- if (result.payload.success === false) {
2894
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2895
- }
2896
- }
2897
- catch (error) {
2898
- throw AirServiceError.from(error);
2863
+ const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
2864
+ if (result.payload.success === false) {
2865
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2899
2866
  }
2900
2867
  }
2901
2868
  async getAccessToken() {
2902
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2903
- throw new Error("Service is not initialized");
2904
- if (!this.isLoggedIn)
2905
- throw new Error("No active session to get partner access token");
2869
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
2906
2870
  const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendPartnerAccessTokenRequest();
2907
2871
  if (result.payload.success !== true) {
2908
2872
  throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2909
2873
  }
2910
2874
  if (!result.payload.partnerAccessToken) {
2911
- throw new Error("Partner access token not found in response");
2875
+ throw new AirServiceError("UNAUTHORIZED", "Partner access token not found in response");
2912
2876
  }
2913
2877
  return { token: result.payload.partnerAccessToken };
2914
2878
  }
2915
2879
  async logout() {
2916
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2917
- throw new Error("Service is not initialized");
2918
- if (!this.isLoggedIn)
2919
- throw new Error("No active session to logout");
2880
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertLoggedIn).call(this);
2920
2881
  // Clear up credentials first to avoid issues with wallet and auth messaging services
2921
2882
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpCredential).call(this);
2922
2883
  await Promise.all([
@@ -2928,33 +2889,21 @@ class AirService {
2928
2889
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
2929
2890
  }
2930
2891
  async cleanUp() {
2892
+ await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpCredential).call(this);
2893
+ await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
2931
2894
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2932
2895
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
2933
- await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
2934
- await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpCredential).call(this);
2935
- this.clearEventListeners();
2896
+ __classPrivateFieldSet(this, _AirService_airEventListener, [], "f");
2897
+ __classPrivateFieldSet(this, _AirService_sessionId, undefined, "f");
2898
+ __classPrivateFieldSet(this, _AirService_buildEnv, undefined, "f");
2936
2899
  }
2937
- /**
2938
- * Register an event listener for Air service events.
2939
- *
2940
- * Available events:
2941
- * - "initialized": Service initialization completed
2942
- * - "logged_in": User successfully logged in
2943
- * - "logged_out": User logged out
2944
- * - "wallet_initialized": Wallet initialization completed
2945
- *
2946
- * @param listener The event listener function
2947
- */
2948
2900
  on(listener) {
2949
- if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) < 0)
2950
- __classPrivateFieldGet(this, _AirService_airAuthListener, "f").push(listener);
2901
+ if (__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener) < 0)
2902
+ __classPrivateFieldGet(this, _AirService_airEventListener, "f").push(listener);
2951
2903
  }
2952
2904
  off(listener) {
2953
- if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) >= 0)
2954
- __classPrivateFieldGet(this, _AirService_airAuthListener, "f").splice(__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener), 1);
2955
- }
2956
- clearEventListeners() {
2957
- __classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
2905
+ if (__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener) >= 0)
2906
+ __classPrivateFieldGet(this, _AirService_airEventListener, "f").splice(__classPrivateFieldGet(this, _AirService_airEventListener, "f").indexOf(listener), 1);
2958
2907
  }
2959
2908
  async preloadCredential() {
2960
2909
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureCredential).call(this);
@@ -2987,9 +2936,15 @@ class AirService {
2987
2936
  return payload.verificationResult;
2988
2937
  }
2989
2938
  }
2990
- _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airAuthListener = new WeakMap(), _AirService_walletMessagingService = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_recoveryInitialization = new WeakMap(), _AirService_recoveryMessagingService = new WeakMap(), _AirService_recoveryIframeController = new WeakMap(), _AirService_credentialsInitialization = new WeakMap(), _AirService_credentialMessagingService = new WeakMap(), _AirService_credentialIframeController = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_ensureCredential = async function _AirService_ensureCredential() {
2991
- if (!this.isInitialized)
2992
- throw new Error("Service not initialized");
2939
+ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _AirService_enableLogging = new WeakMap(), _AirService_partnerId = new WeakMap(), _AirService_sessionId = new WeakMap(), _AirService_sessionConfig = new WeakMap(), _AirService_authMessagingService = new WeakMap(), _AirService_authIframeController = new WeakMap(), _AirService_isAuthInitialized = new WeakMap(), _AirService_airEventListener = new WeakMap(), _AirService_walletMessagingService = new WeakMap(), _AirService_walletIframeController = new WeakMap(), _AirService_walletInitialization = new WeakMap(), _AirService_walletLoggedInResult = new WeakMap(), _AirService_airWalletProvider = new WeakMap(), _AirService_recoveryInitialization = new WeakMap(), _AirService_recoveryMessagingService = new WeakMap(), _AirService_recoveryIframeController = new WeakMap(), _AirService_credentialsInitialization = new WeakMap(), _AirService_credentialMessagingService = new WeakMap(), _AirService_credentialIframeController = new WeakMap(), _AirService_instances = new WeakSet(), _AirService_assertInitialized = function _AirService_assertInitialized() {
2940
+ if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2941
+ throw new AirServiceError("NOT_INITIALIZED", "Service is not initialized");
2942
+ }, _AirService_assertLoggedIn = function _AirService_assertLoggedIn() {
2943
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
2944
+ if (!this.isLoggedIn)
2945
+ throw new AirServiceError("NOT_LOGGED_IN", "User not logged in");
2946
+ }, _AirService_ensureCredential = async function _AirService_ensureCredential() {
2947
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
2993
2948
  void __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2994
2949
  try {
2995
2950
  if (!__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f"))
@@ -2999,11 +2954,11 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2999
2954
  catch (error) {
3000
2955
  __classPrivateFieldSet(this, _AirService_credentialsInitialization, null, "f");
3001
2956
  log.error("Error ensuring credentials", error);
3002
- throw error;
2957
+ throw AirServiceError.from(error);
3003
2958
  }
3004
2959
  }, _AirService_initializeCredentials = async function _AirService_initializeCredentials() {
3005
2960
  if (__classPrivateFieldGet(this, _AirService_credentialsInitialization, "f")) {
3006
- throw new Error("Already initializing credentials");
2961
+ throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing credentials");
3007
2962
  }
3008
2963
  const { credentialUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
3009
2964
  const credentialIframeOrigin = new URL(credentialUrl).origin;
@@ -3016,11 +2971,13 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3016
2971
  if (ev.data === AirCredentialMessageTypes.SERVICE_STARTED) {
3017
2972
  window.removeEventListener("message", handleCredentialMessage);
3018
2973
  const { payload } = await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").sendInitializationRequest({
2974
+ sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
3019
2975
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
3020
2976
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
3021
2977
  sdkVersion: airKitVersion,
3022
2978
  partnerDAppUrl: window.location.href,
3023
2979
  enableAutomation: this.shouldEnableAutomation(),
2980
+ sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
3024
2981
  });
3025
2982
  if (payload.success === true) {
3026
2983
  resolve();
@@ -3039,13 +2996,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3039
2996
  await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_credentialIframeController, "f").iframeElement);
3040
2997
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToCredentialEvents).call(this);
3041
2998
  await credentialInitRequestPromise;
3042
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initCredentialCommunication();
3043
- await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").initAuthCommunication();
3044
- log.info("[Embed] Credential auth channel initialized");
3045
2999
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
3046
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").initCredentialCommunication();
3047
- await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").initWalletCommunication();
3048
- log.info("[Embed] Credential wallet channel initialized");
3049
3000
  log.info("Credential service initialized successfully");
3050
3001
  }
3051
3002
  catch (error) {
@@ -3054,7 +3005,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3054
3005
  if (closeDApp) {
3055
3006
  window.close();
3056
3007
  }
3057
- throw error;
3008
+ throw AirServiceError.from(error);
3058
3009
  }
3059
3010
  }, _AirService_subscribeToCredentialEvents = function _AirService_subscribeToCredentialEvents() {
3060
3011
  __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").messages$.subscribe(async (message) => {
@@ -3076,19 +3027,10 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3076
3027
  __classPrivateFieldGet(this, _AirService_credentialIframeController, "f").destroy();
3077
3028
  __classPrivateFieldSet(this, _AirService_credentialIframeController, undefined, "f");
3078
3029
  }
3079
- const walletIframeElement = __classPrivateFieldGet(this, _AirService_walletIframeController, "f")?.iframeElement;
3080
- if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
3081
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").resetCredentialCommunication();
3082
- }
3083
- const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
3084
- if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3085
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetCredentialCommunication();
3086
- }
3087
3030
  await __classPrivateFieldGet(this, _AirService_credentialMessagingService, "f").close();
3088
3031
  __classPrivateFieldSet(this, _AirService_credentialsInitialization, undefined, "f");
3089
3032
  }, _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
3090
- if (!this.isInitialized)
3091
- throw new Error("Service not initialized");
3033
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
3092
3034
  if (!__classPrivateFieldGet(this, _AirService_walletInitialization, "f"))
3093
3035
  __classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeWallet).call(this, option), "f");
3094
3036
  if (__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"))
@@ -3102,7 +3044,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3102
3044
  catch (error) {
3103
3045
  __classPrivateFieldSet(this, _AirService_walletInitialization, null, "f");
3104
3046
  log.error("Error initializing wallet", error);
3105
- throw error;
3047
+ throw AirServiceError.from(error);
3106
3048
  }
3107
3049
  if (__classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f"))
3108
3050
  return __classPrivateFieldGet(this, _AirService_walletLoggedInResult, "f");
@@ -3113,7 +3055,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3113
3055
  return __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_createWalletInitializedResult).call(this, walletLoginResult.payload);
3114
3056
  }, _AirService_initializeWallet = async function _AirService_initializeWallet(option) {
3115
3057
  if (__classPrivateFieldGet(this, _AirService_walletInitialization, "f"))
3116
- throw new Error("Already initializing");
3058
+ throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing");
3117
3059
  const { walletUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
3118
3060
  const walletIframeOrigin = new URL(walletUrl).origin;
3119
3061
  try {
@@ -3124,10 +3066,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3124
3066
  if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
3125
3067
  window.removeEventListener("message", handleWalletMessage);
3126
3068
  const { payload } = await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").sendInitializationRequest({
3069
+ sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
3127
3070
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
3128
3071
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
3129
3072
  sdkVersion: airKitVersion,
3130
3073
  enableAutomation: this.shouldEnableAutomation(),
3074
+ sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
3131
3075
  });
3132
3076
  if (payload.success === true) {
3133
3077
  resolve();
@@ -3150,8 +3094,6 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3150
3094
  if (!this.isLoggedIn && !option?.skipWalletLogin) {
3151
3095
  await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").onLoggedIn();
3152
3096
  }
3153
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initWalletCommunication();
3154
- await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").initAuthCommunication(option?.skipWalletLogin ?? false);
3155
3097
  const walletInitResult = await walletInitPromise;
3156
3098
  if (walletInitResult.payload.success !== true) {
3157
3099
  throw new AirServiceError(walletInitResult.payload.errorName, walletInitResult.payload.errorMessage);
@@ -3165,7 +3107,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3165
3107
  catch (error) {
3166
3108
  log.error("Error initializing wallet", error);
3167
3109
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
3168
- throw error;
3110
+ throw AirServiceError.from(error);
3169
3111
  }
3170
3112
  }, _AirService_subscribeToWalletEvents = function _AirService_subscribeToWalletEvents() {
3171
3113
  __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").messages$.subscribe(async (msg) => {
@@ -3194,6 +3136,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3194
3136
  const { windowController, port } = await WindowService$1.openAndInitializeWalletServiceWindow({
3195
3137
  url: msg.payload.url,
3196
3138
  windowId: msg.payload.windowId,
3139
+ sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
3197
3140
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
3198
3141
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
3199
3142
  sdkVersion: airKitVersion,
@@ -3212,7 +3155,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3212
3155
  }
3213
3156
  });
3214
3157
  }, _AirService_triggerEventListeners = function _AirService_triggerEventListeners(data) {
3215
- __classPrivateFieldGet(this, _AirService_airAuthListener, "f").forEach((listener) => {
3158
+ __classPrivateFieldGet(this, _AirService_airEventListener, "f").forEach((listener) => {
3216
3159
  listener(data);
3217
3160
  });
3218
3161
  }, _AirService_triggerAirAuthInitialized = function _AirService_triggerAirAuthInitialized(result) {
@@ -3270,17 +3213,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3270
3213
  __classPrivateFieldGet(this, _AirService_walletIframeController, "f").destroy();
3271
3214
  __classPrivateFieldSet(this, _AirService_walletIframeController, undefined, "f");
3272
3215
  }
3273
- const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
3274
- if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3275
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetWalletCommunication();
3276
- }
3277
3216
  // Close the message service
3278
3217
  await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").close();
3279
3218
  __classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined, "f");
3280
3219
  __classPrivateFieldSet(this, _AirService_walletInitialization, undefined, "f");
3281
3220
  }, _AirService_ensureRecovery = async function _AirService_ensureRecovery() {
3282
- if (!this.isInitialized)
3283
- throw new Error("Service not initialized");
3221
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_assertInitialized).call(this);
3284
3222
  if (!__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f")) {
3285
3223
  __classPrivateFieldSet(this, _AirService_recoveryInitialization, __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_initializeRecovery).call(this), "f");
3286
3224
  }
@@ -3290,11 +3228,11 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3290
3228
  catch (error) {
3291
3229
  __classPrivateFieldSet(this, _AirService_recoveryInitialization, null, "f");
3292
3230
  log.error("Error initializing recovery", error);
3293
- throw error;
3231
+ throw AirServiceError.from(error);
3294
3232
  }
3295
3233
  }, _AirService_initializeRecovery = async function _AirService_initializeRecovery() {
3296
3234
  if (__classPrivateFieldGet(this, _AirService_recoveryInitialization, "f"))
3297
- throw new Error("Already initializing");
3235
+ throw new AirServiceError("ALREADY_INITIALIZING", "Already initializing");
3298
3236
  const { recoveryUrl } = AIR_URLS[__classPrivateFieldGet(this, _AirService_buildEnv, "f")];
3299
3237
  const recoveryIframeOrigin = new URL(recoveryUrl).origin;
3300
3238
  try {
@@ -3305,10 +3243,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3305
3243
  if (ev.data === AirRecoveryMessageTypes.SERVICE_STARTED) {
3306
3244
  window.removeEventListener("message", handleRecoveryMessage);
3307
3245
  const { payload } = await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").sendInitializationRequest({
3246
+ sessionId: __classPrivateFieldGet(this, _AirService_sessionId, "f"),
3308
3247
  partnerId: __classPrivateFieldGet(this, _AirService_partnerId, "f"),
3309
3248
  enableLogging: __classPrivateFieldGet(this, _AirService_enableLogging, "f"),
3310
3249
  sdkVersion: airKitVersion,
3311
3250
  enableAutomation: this.shouldEnableAutomation(),
3251
+ sessionConfig: __classPrivateFieldGet(this, _AirService_sessionConfig, "f"),
3312
3252
  });
3313
3253
  if (payload.success === true) {
3314
3254
  resolve();
@@ -3327,17 +3267,12 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3327
3267
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_subscribeToRecoveryEvents).call(this);
3328
3268
  const recoveryInitPromise = __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").onInitialized();
3329
3269
  await recoveryInitRequestPromise;
3330
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").initRecoveryCommunication();
3331
- await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").initAuthCommunication();
3332
- const recoveryInitResult = await recoveryInitPromise;
3333
- if (recoveryInitResult.payload.success !== true) {
3334
- throw new AirServiceError(recoveryInitResult.payload.errorName, recoveryInitResult.payload.errorMessage);
3335
- }
3270
+ await recoveryInitPromise;
3336
3271
  }
3337
3272
  catch (error) {
3338
3273
  log.error("Error initializing recovery", error);
3339
3274
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
3340
- throw error;
3275
+ throw AirServiceError.from(error);
3341
3276
  }
3342
3277
  }, _AirService_subscribeToRecoveryEvents = function _AirService_subscribeToRecoveryEvents() {
3343
3278
  __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").messages$.subscribe(async (message) => {
@@ -3360,10 +3295,6 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3360
3295
  __classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").destroy();
3361
3296
  __classPrivateFieldSet(this, _AirService_recoveryIframeController, undefined, "f");
3362
3297
  }
3363
- const authIframeElement = __classPrivateFieldGet(this, _AirService_authIframeController, "f")?.iframeElement;
3364
- if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3365
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").resetRecoveryCommunication();
3366
- }
3367
3298
  // Close the message service
3368
3299
  await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").close();
3369
3300
  __classPrivateFieldSet(this, _AirService_recoveryInitialization, undefined, "f");