@mocanetwork/airkit-connector 1.5.0 → 1.5.1

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.
@@ -94,7 +94,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
94
94
  var e = new Error(message);
95
95
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
96
96
  };
97
- var version$2 = "1.5.0";
97
+ var version$2 = "1.5.1";
98
98
  var airkitPackage = {
99
99
  version: version$2
100
100
  };
@@ -125,8 +125,6 @@ const AirAuthMessageTypes = {
125
125
  CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
126
126
  PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
127
127
  PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
128
- CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
129
- CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
130
128
  LOGOUT_REQUEST: "air_auth_logout_request",
131
129
  LOGOUT_RESPONSE: "air_auth_logout_response",
132
130
  RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
@@ -136,12 +134,9 @@ const AirAuthMessageTypes = {
136
134
  START_RECOVERY_RESPONSE: "air_start_recovery_response",
137
135
  RECOVERY_REQUEST: "air_auth_recovery_request",
138
136
  RECOVERY_RESPONSE: "air_auth_recovery_response",
139
- LINK_EOA_CREDENTIAL_REQUEST: "air_auth_link_eoa_credential_request",
140
- LINK_EOA_CREDENTIAL_RESPONSE: "air_auth_link_eoa_credential_response",
141
- LINKAGE_NONCE_REQUEST: "air_auth_linkage_nonce_request",
142
- LINKAGE_NONCE_RESPONSE: "air_auth_linkage_nonce_response",
143
- CREDENTIAL_SIGNERS_REQUEST: "air_auth_credential_signers_request",
144
- CREDENTIAL_SIGNERS_RESPONSE: "air_auth_credential_signers_response"
137
+ INIT_CREDENTIAL_COMMUNICATION: "air_auth_init_credential_communication",
138
+ RESET_CREDENTIAL_COMMUNICATION: "air_auth_reset_credential_communication",
139
+ EXPIRED_LOGOUT_REQUEST: "air_auth_expired_logout_request"
145
140
  };
146
141
  const AirRecoveryMessageTypes = {
147
142
  SERVICE_STARTED: "air_recovery_service_started",
@@ -177,7 +172,11 @@ const AirWalletMessageTypes = {
177
172
  IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
178
173
  IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
179
174
  LOGOUT_REQUEST: "air_logout_request",
180
- LOGOUT_RESPONSE: "air_logout_response"
175
+ LOGOUT_RESPONSE: "air_logout_response",
176
+ INIT_CREDENTIAL_COMMUNICATION: "air_init_credential_communication",
177
+ RESET_CREDENTIAL_COMMUNICATION: "air_reset_credential_communication",
178
+ INTERNAL_PROVIDER_REQUEST: "air_internal_provider_request",
179
+ INTERNAL_PROVIDER_RESPONSE: "air_internal_provider_response"
181
180
  };
182
181
  const AirWindowMessageTypes = {
183
182
  OPEN_WINDOW_REQUEST: "air_open_window_request",
@@ -560,8 +559,6 @@ const configureLogLevel = (environment, enableLogging) => {
560
559
  level = enableLogging ? log$1.levels.DEBUG : log$1.levels.INFO;
561
560
  } else if (environment === "uat" || environment === "sandbox") {
562
561
  level = enableLogging ? log$1.levels.INFO : log$1.levels.WARN;
563
- } else if (environment === "sandbox") {
564
- level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
565
562
  } else if (environment === "production") {
566
563
  // Be cautious with enabling more than WARN in prod
567
564
  level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
@@ -576,31 +573,38 @@ const BUILD_ENV = {
576
573
  DEVELOPMENT: "development",
577
574
  SANDBOX: "sandbox"
578
575
  };
576
+ const IFRAME_NAME_PREFIX_SET = ["air-wallet", "air-recovery", "air-credential", "air-auth"]; // order defines the z-index from highest to lowest
577
+
579
578
  const AIR_URLS = {
580
579
  [BUILD_ENV.DEVELOPMENT]: {
581
580
  authUrl: "http://localhost:8200/auth/",
582
581
  walletUrl: "http://localhost:8200/wallet/",
583
- recoveryUrl: "http://localhost:8200/recovery/"
582
+ recoveryUrl: "http://localhost:8200/recovery/",
583
+ credentialUrl: "http://localhost:8200/credential/"
584
584
  },
585
585
  [BUILD_ENV.STAGING]: {
586
586
  authUrl: "https://account.staging.air3.com/auth/",
587
587
  walletUrl: "https://account.staging.air3.com/wallet/",
588
- recoveryUrl: "https://account.staging.air3.com/recovery/"
588
+ recoveryUrl: "https://account.staging.air3.com/recovery/",
589
+ credentialUrl: "https://account.staging.air3.com/credential/"
589
590
  },
590
591
  [BUILD_ENV.UAT]: {
591
592
  authUrl: "https://account.uat.air3.com/auth/",
592
593
  walletUrl: "https://account.uat.air3.com/wallet/",
593
- recoveryUrl: "https://account.uat.air3.com/recovery/"
594
+ recoveryUrl: "https://account.uat.air3.com/recovery/",
595
+ credentialUrl: "https://account.uat.air3.com/credential/"
594
596
  },
595
597
  [BUILD_ENV.SANDBOX]: {
596
598
  authUrl: "https://account.sandbox.air3.com/auth/",
597
599
  walletUrl: "https://account.sandbox.air3.com/wallet/",
598
- recoveryUrl: "https://account.sandbox.air3.com/recovery/"
600
+ recoveryUrl: "https://account.sandbox.air3.com/recovery/",
601
+ credentialUrl: "https://account.sandbox.air3.com/credential/"
599
602
  },
600
603
  [BUILD_ENV.PRODUCTION]: {
601
604
  authUrl: "https://account.air3.com/auth/",
602
605
  walletUrl: "https://account.air3.com/wallet/",
603
- recoveryUrl: "https://account.air3.com/recovery/"
606
+ recoveryUrl: "https://account.air3.com/recovery/",
607
+ credentialUrl: "https://account.air3.com/credential/"
604
608
  }
605
609
  };
606
610
  const isElement = element => element instanceof Element || element instanceof Document;
@@ -1608,7 +1612,7 @@ const Codes = {
1608
1612
  ...AirIDErrorName,
1609
1613
  ...WindowErrorName
1610
1614
  };
1611
- const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED"];
1615
+ const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED", "ACCOUNT_DELETION_PENDING"];
1612
1616
  class AirError extends BaseError$2 {}
1613
1617
  new Set(AirClientUserErrors);
1614
1618
  new Set(Object.values(Codes));
@@ -1863,7 +1867,7 @@ _AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_is
1863
1867
  });
1864
1868
  };
1865
1869
  var _a$2, _AuthMessageService_instance;
1866
- const ALLOWED_AUTH_MESSAGES = [AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.SETUP_WALLET_REQUEST, AirAuthMessageTypes.SETUP_RECOVERY_REQUEST, AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION, AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION, AirAuthMessageTypes.LOGOUT_RESPONSE, AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE, AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE, AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE, AirAuthMessageTypes.START_RECOVERY_RESPONSE, AirAuthMessageTypes.LINK_EOA_CREDENTIAL_RESPONSE, AirAuthMessageTypes.LINKAGE_NONCE_RESPONSE, AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE];
1870
+ const ALLOWED_AUTH_MESSAGES = [AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.SETUP_WALLET_REQUEST, AirAuthMessageTypes.SETUP_RECOVERY_REQUEST, AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION, AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION, AirAuthMessageTypes.LOGOUT_RESPONSE, AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE, AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE, AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, AirAuthMessageTypes.START_RECOVERY_RESPONSE, AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST];
1867
1871
  class AuthMessageService extends MessageServiceBase {
1868
1872
  static create() {
1869
1873
  if (!__classPrivateFieldGet$1(this, _a$2, "f", _AuthMessageService_instance)) {
@@ -1986,36 +1990,18 @@ class AuthMessageService extends MessageServiceBase {
1986
1990
  });
1987
1991
  return response;
1988
1992
  }
1989
- async sendCredentialSaltRequest() {
1990
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE)));
1991
- await this.sendMessage({
1992
- type: AirAuthMessageTypes.CREDENTIAL_SALT_REQUEST
1993
- });
1994
- return response;
1995
- }
1996
- async sendLinkEoaCredentialRequest(payload) {
1997
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.LINK_EOA_CREDENTIAL_RESPONSE)));
1998
- await this.sendMessage({
1999
- type: AirAuthMessageTypes.LINK_EOA_CREDENTIAL_REQUEST,
2000
- payload
2001
- });
2002
- return response;
2003
- }
2004
- async sendCredentialSignersRequest(payload) {
2005
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE)));
1993
+ /*
1994
+ * Initialize credential communication
1995
+ */
1996
+ async initCredentialCommunication() {
2006
1997
  await this.sendMessage({
2007
- type: AirAuthMessageTypes.CREDENTIAL_SIGNERS_REQUEST,
2008
- payload
1998
+ type: AirAuthMessageTypes.INIT_CREDENTIAL_COMMUNICATION
2009
1999
  });
2010
- return response;
2011
2000
  }
2012
- async sendLinkageNonceRequest(payload) {
2013
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.LINKAGE_NONCE_RESPONSE)));
2001
+ async resetCredentialCommunication() {
2014
2002
  await this.sendMessage({
2015
- type: AirAuthMessageTypes.LINKAGE_NONCE_REQUEST,
2016
- payload
2003
+ type: AirAuthMessageTypes.RESET_CREDENTIAL_COMMUNICATION
2017
2004
  });
2018
- return response;
2019
2005
  }
2020
2006
  }
2021
2007
  _a$2 = AuthMessageService;
@@ -2024,22 +2010,21 @@ _AuthMessageService_instance = {
2024
2010
  };
2025
2011
  class IframeController {
2026
2012
  getZIndex() {
2027
- if (this.iframeId.includes("air-auth")) return this.AUTH_IFRAME_Z_INDEX;
2028
- if (this.iframeId.includes("air-wallet")) return this.WALLET_IFRAME_Z_INDEX;
2029
- if (this.iframeId.includes("air-recovery")) return this.RECOVERY_IFRAME_Z_INDEX;
2030
- return "9999999"; // Default z-index if not matched
2013
+ for (let i = 0; i < IFRAME_NAME_PREFIX_SET.length; i++) {
2014
+ if (this.iframeId.includes(IFRAME_NAME_PREFIX_SET[i])) {
2015
+ return IframeController.HIGHEST_Z_INDEX - i;
2016
+ }
2017
+ }
2018
+ return IframeController.HIGHEST_Z_INDEX - IFRAME_NAME_PREFIX_SET.length; // Lowest z-index if no match
2031
2019
  }
2032
- constructor(iframeUrl, iframeId, state) {
2020
+ constructor(iframePrefix, iframeUrl, state) {
2033
2021
  this._iframeElement = null;
2034
- this.AUTH_IFRAME_Z_INDEX = "9999998";
2035
- this.WALLET_IFRAME_Z_INDEX = "9999999";
2036
- this.RECOVERY_IFRAME_Z_INDEX = "999999";
2037
2022
  this.state = {
2038
- ...IframeController.defaultState,
2023
+ ...IframeController.DEFAULT_STATE,
2039
2024
  ...state
2040
2025
  };
2041
2026
  this.iframeUrl = iframeUrl;
2042
- this.iframeId = iframeId;
2027
+ this.iframeId = `${iframePrefix}-${randomId()}`;
2043
2028
  }
2044
2029
  get iframeElement() {
2045
2030
  return this._iframeElement;
@@ -2051,7 +2036,7 @@ class IframeController {
2051
2036
  iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
2052
2037
  iframe.src = this.iframeUrl;
2053
2038
  iframe.style.position = "fixed";
2054
- iframe.style.zIndex = this.getZIndex();
2039
+ iframe.style.zIndex = `${this.getZIndex()}`;
2055
2040
  iframe.style.border = "none";
2056
2041
  iframe.style.margin = "0";
2057
2042
  iframe.style.padding = "0";
@@ -2090,9 +2075,10 @@ class IframeController {
2090
2075
  this.iframeElement.contentWindow.postMessage(message, origin);
2091
2076
  }
2092
2077
  }
2093
- IframeController.defaultState = {
2078
+ IframeController.DEFAULT_STATE = {
2094
2079
  isVisible: false
2095
2080
  };
2081
+ IframeController.HIGHEST_Z_INDEX = 2147483647;
2096
2082
  var _a$1, _RecoveryMessageService_instance;
2097
2083
  const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
2098
2084
  class RecoveryMessageService extends MessageServiceBase {
@@ -2140,11 +2126,12 @@ _RecoveryMessageService_instance = {
2140
2126
  value: void 0
2141
2127
  };
2142
2128
  var _a, _WalletMessageService_instance;
2143
- const ALLOWED_WALLET_MESSAGES = [AirWalletMessageTypes.INITIALIZATION_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_LOGIN_RESPONSE, AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE, AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE, AirWalletMessageTypes.SHOW_ON_RAMP_UI_RESPONSE, AirWalletMessageTypes.CLAIM_ID_RESPONSE, AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE, AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST, AirWalletMessageTypes.LOGOUT_RESPONSE, AirWindowMessageTypes.OPEN_WINDOW_REQUEST, AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE];
2129
+ const ALLOWED_WALLET_MESSAGES = [AirWalletMessageTypes.INITIALIZATION_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_LOGIN_RESPONSE, AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_RESPONSE, AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE, AirWalletMessageTypes.SHOW_ON_RAMP_UI_RESPONSE, AirWalletMessageTypes.CLAIM_ID_RESPONSE, AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE, AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST, AirWalletMessageTypes.LOGOUT_RESPONSE, AirWindowMessageTypes.OPEN_WINDOW_REQUEST, AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE];
2144
2130
  class WalletMessageService extends MessageServiceBase {
2145
2131
  static create() {
2146
- if (__classPrivateFieldGet$1(this, _a, "f", _WalletMessageService_instance)) throw new Error("WalletMessageService already created");
2147
- __classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
2132
+ if (!__classPrivateFieldGet$1(this, _a, "f", _WalletMessageService_instance)) {
2133
+ __classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
2134
+ }
2148
2135
  return __classPrivateFieldGet$1(this, _a, "f", _WalletMessageService_instance);
2149
2136
  }
2150
2137
  async open(walletIframe) {
@@ -2269,6 +2256,16 @@ class WalletMessageService extends MessageServiceBase {
2269
2256
  });
2270
2257
  return response;
2271
2258
  }
2259
+ async initCredentialCommunication() {
2260
+ await this.sendMessage({
2261
+ type: AirWalletMessageTypes.INIT_CREDENTIAL_COMMUNICATION
2262
+ });
2263
+ }
2264
+ async resetCredentialCommunication() {
2265
+ await this.sendMessage({
2266
+ type: AirWalletMessageTypes.RESET_CREDENTIAL_COMMUNICATION
2267
+ });
2268
+ }
2272
2269
  }
2273
2270
  _a = WalletMessageService;
2274
2271
  _WalletMessageService_instance = {
@@ -2481,6 +2478,9 @@ var WindowService$1 = WindowService.instance;
2481
2478
  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_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;
2482
2479
  const airKitVersion = airkitPackage.version;
2483
2480
  class AirService {
2481
+ // #credentialsInitialization?: Promise<void>;
2482
+ // #credentialMessagingService: CredentialMessageService;
2483
+ // #credentialIframeController: IframeController;
2484
2484
  constructor({
2485
2485
  partnerId
2486
2486
  }) {
@@ -2506,6 +2506,7 @@ class AirService {
2506
2506
  __classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create());
2507
2507
  __classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create());
2508
2508
  __classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create());
2509
+ // this.#credentialMessagingService = CredentialMessageService.create();
2509
2510
  __classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
2510
2511
  isWalletInitialized: () => this.isWalletInitialized,
2511
2512
  ensureWallet: __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
@@ -2553,7 +2554,7 @@ class AirService {
2553
2554
  } = AIR_URLS[buildEnv];
2554
2555
  configureLogLevel(buildEnv, enableLogging);
2555
2556
  const authIframeOrigin = new URL(authUrl).origin;
2556
- __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController(authUrl, `air-auth-${randomId()}`));
2557
+ __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController("air-auth", authUrl));
2557
2558
  try {
2558
2559
  __classPrivateFieldGet$1(this, _AirService_authIframeController, "f").createIframe();
2559
2560
  log$1.info(authUrl, "url loaded");
@@ -2591,6 +2592,11 @@ class AirService {
2591
2592
  }
2592
2593
  break;
2593
2594
  }
2595
+ case AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST:
2596
+ {
2597
+ await this.logout();
2598
+ break;
2599
+ }
2594
2600
  }
2595
2601
  });
2596
2602
  const result = await new Promise((resolve, reject) => {
@@ -2689,57 +2695,6 @@ class AirService {
2689
2695
  throw AirServiceError.from(error);
2690
2696
  }
2691
2697
  }
2692
- /**
2693
- * @experimental This method is experimental and will change in the future.
2694
- */
2695
- async getCredentialSalt() {
2696
- if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2697
- if (!this.isLoggedIn) throw new Error("No active session to get partner access token");
2698
- const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendCredentialSaltRequest();
2699
- if (result.payload.success === false) {
2700
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2701
- }
2702
- return {
2703
- credentialSalt: result.payload.credentialSalt
2704
- };
2705
- }
2706
- /**
2707
- * @experimental This method is experimental and will change in the future.
2708
- */
2709
- async getLinkageNonce(payload) {
2710
- if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2711
- if (!this.isLoggedIn) throw new Error("No active session to get nonce");
2712
- const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendLinkageNonceRequest(payload);
2713
- if (result.payload.success === false) {
2714
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2715
- }
2716
- return {
2717
- nonce: result.payload.nonce
2718
- };
2719
- }
2720
- /**
2721
- * @experimental This method is experimental and will change in the future.
2722
- */
2723
- async retrieveCredentialSigners(payload) {
2724
- if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2725
- if (!this.isLoggedIn) throw new Error("No active session to retrieve EOA credential");
2726
- const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendCredentialSignersRequest(payload);
2727
- if (result.payload.success === false) {
2728
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2729
- }
2730
- return result.payload.credentials;
2731
- }
2732
- /**
2733
- * @experimental This method is experimental and will change in the future.
2734
- */
2735
- async linkEoaCredential(payload) {
2736
- if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2737
- if (!this.isLoggedIn) throw new Error("No active session to link EOA credential");
2738
- const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendLinkEoaCredentialRequest(payload);
2739
- if (result.payload.success === false) {
2740
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2741
- }
2742
- }
2743
2698
  getProvider() {
2744
2699
  return this.provider;
2745
2700
  }
@@ -2853,9 +2808,9 @@ class AirService {
2853
2808
  async logout() {
2854
2809
  if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2855
2810
  if (!this.isLoggedIn) throw new Error("No active session to logout");
2856
- // Clear up wallet
2857
- await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2858
- await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").logout();
2811
+ // Clear up credentials first to avoid issues with wallet and auth messaging services
2812
+ // await this.#cleanUpCredential();
2813
+ await Promise.all([__classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this), __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this), __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").logout()]);
2859
2814
  __classPrivateFieldSet(this, _AirService_loginResult, undefined);
2860
2815
  __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
2861
2816
  }
@@ -2863,8 +2818,22 @@ class AirService {
2863
2818
  await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2864
2819
  await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
2865
2820
  await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
2821
+ // await this.#cleanUpCredential();
2866
2822
  this.clearEventListeners();
2867
2823
  }
2824
+ /**
2825
+ * Register an event listener for Air service events.
2826
+ *
2827
+ * Available events:
2828
+ * - "initialized": Service initialization completed
2829
+ * - "logged_in": User successfully logged in
2830
+ * - "logged_out": User logged out
2831
+ * - "wallet_initialized": Wallet initialization completed
2832
+ * - "credential_issuance_finished": Credential issuance finished (success or failure)
2833
+ * - "credential_verification_finished": Credential verification finished (success or failure)
2834
+ *
2835
+ * @param listener The event listener function
2836
+ */
2868
2837
  on(listener) {
2869
2838
  if (__classPrivateFieldGet$1(this, _AirService_airAuthListener, "f").indexOf(listener) < 0) __classPrivateFieldGet$1(this, _AirService_airAuthListener, "f").push(listener);
2870
2839
  }
@@ -2875,7 +2844,211 @@ class AirService {
2875
2844
  __classPrivateFieldSet(this, _AirService_airAuthListener, []);
2876
2845
  }
2877
2846
  }
2878
- _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_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
2847
+ _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_instances = new WeakSet(), _AirService_ensureWallet =
2848
+ // /**
2849
+ // * Issue a credential using the credential SDK
2850
+ // * @param claimRequest The claim request containing credential details
2851
+ // * @param projectName The name of the project
2852
+ // * @param options Optional configuration for the credential widget
2853
+ // */
2854
+ // public async issueCredential(
2855
+ // claimRequest: {
2856
+ // process: "Issue";
2857
+ // issuerDid: string;
2858
+ // issuerAuth: string;
2859
+ // credentialId: string;
2860
+ // credentialSubject: Record<string, unknown>;
2861
+ // },
2862
+ // projectName: string,
2863
+ // options?: {
2864
+ // endpoint?: string;
2865
+ // theme?: "auto" | "light" | "dark";
2866
+ // locale?: "en" | "zh-hk";
2867
+ // }
2868
+ // ): Promise<Record<string, never>> {
2869
+ // await this.#ensureCredentials();
2870
+ // try {
2871
+ // const { payload } = await this.#credentialMessagingService.sendIssueCredentialRequest({
2872
+ // claimRequest,
2873
+ // projectName,
2874
+ // options: options || {},
2875
+ // });
2876
+ //
2877
+ // return payload;
2878
+ // } catch (error) {
2879
+ // throw AirServiceError.from(error);
2880
+ // }
2881
+ // }
2882
+ //
2883
+ // /**
2884
+ // * Verify a credential using the credential SDK
2885
+ // * @param queryRequest The query request containing verification details
2886
+ // * @param projectName The name of the project
2887
+ // * @param options Optional configuration for the credential widget
2888
+ // */
2889
+ // public async verifyCredential(
2890
+ // queryRequest: {
2891
+ // process: "Verify";
2892
+ // verifierAuth: string;
2893
+ // programId: string;
2894
+ // },
2895
+ // projectName: string,
2896
+ // options?: {
2897
+ // endpoint?: string;
2898
+ // theme?: "auto" | "light" | "dark";
2899
+ // locale?: "en" | "zh-hk";
2900
+ // }
2901
+ // ): Promise<{
2902
+ // verificationResults: {
2903
+ // status:
2904
+ // | "Compliant"
2905
+ // | "Non-Compliant"
2906
+ // | "Pending"
2907
+ // | "Revoking"
2908
+ // | "Revoked"
2909
+ // | "Expired"
2910
+ // | "NotFound";
2911
+ // };
2912
+ // }> {
2913
+ // await this.#ensureCredentials();
2914
+ //
2915
+ // try {
2916
+ // const { payload } = await this.#credentialMessagingService.sendVerifyCredentialRequest({
2917
+ // queryRequest,
2918
+ // projectName,
2919
+ // options: options || {},
2920
+ // });
2921
+ //
2922
+ // return payload;
2923
+ // } catch (error) {
2924
+ // throw AirServiceError.from(error);
2925
+ // }
2926
+ // }
2927
+ // async #ensureCredentials(): Promise<void> {
2928
+ // if (!this.isInitialized) throw new Error("Service not initialized");
2929
+ // if (!this.isLoggedIn) throw new Error("User not logged in");
2930
+ // void this.#ensureWallet();
2931
+ //
2932
+ // try {
2933
+ // if (!this.#credentialsInitialization)
2934
+ // this.#credentialsInitialization = this.#initializeCredentials();
2935
+ // await this.#credentialsInitialization;
2936
+ // } catch (error) {
2937
+ // this.#credentialsInitialization = null;
2938
+ // log.error("Error ensuring credentials", error);
2939
+ // throw error;
2940
+ // }
2941
+ // }
2942
+ // async #initializeCredentials(): Promise<void> {
2943
+ // if (this.#credentialsInitialization) {
2944
+ // throw new Error("Already initializing credentials");
2945
+ // }
2946
+ // const { credentialUrl } = AIR_URLS[this.#buildEnv];
2947
+ // const credentailIframeOrigin = new URL(credentialUrl).origin;
2948
+ // try {
2949
+ // const credentialInitRequestPromise = new Promise<void>((resolve, reject) => {
2950
+ // const handleCredentialMessage = async (ev: MessageEvent) => {
2951
+ // if (ev.origin !== credentailIframeOrigin) return;
2952
+ // if (ev.data === AirCredentialMessageTypes.SERVICE_STARTED) {
2953
+ // window.removeEventListener("message", handleCredentialMessage);
2954
+ // const { payload } = await this.#credentialMessagingService.sendInitializationRequest({
2955
+ // partnerId: this.#partnerId,
2956
+ // enableLogging: this.#enableLogging,
2957
+ // sdkVersion: airKitVersion,
2958
+ // enableAutomation: this.shouldEnableAutomation(),
2959
+ // });
2960
+ // if (payload.success === true) {
2961
+ // resolve();
2962
+ // } else {
2963
+ // reject(new AirServiceError(payload.errorName, payload.errorMessage));
2964
+ // }
2965
+ // }
2966
+ // };
2967
+ // window.addEventListener("message", handleCredentialMessage);
2968
+ // });
2969
+ // this.#credentialIframeController = new IframeController("air-credential", credentialUrl);
2970
+ // this.#credentialIframeController.createIframe();
2971
+ // log.info(credentialUrl, "url loaded");
2972
+ //
2973
+ // await this.#credentialMessagingService.open(this.#credentialIframeController.iframeElement);
2974
+ // this.#subscribeToCredentialEvents();
2975
+ // await credentialInitRequestPromise;
2976
+ //
2977
+ // await this.#authMessagingService.initCredentialCommunication();
2978
+ // await this.#credentialMessagingService.initAuthCommunication();
2979
+ // log.info("[Embed] Credential auth channel initialized");
2980
+ //
2981
+ // await this.#ensureWallet();
2982
+ // await this.#walletMessagingService.initCredentialCommunication();
2983
+ // await this.#credentialMessagingService.initWalletCommunication();
2984
+ // log.info("[Embed] Credential wallet channel initialized");
2985
+ //
2986
+ // log.info("Credential service initialized successfully");
2987
+ // } catch (error) {
2988
+ // log.error("Error initializing credentials", error);
2989
+ // await this.#cleanUpCredential();
2990
+ // throw error;
2991
+ // }
2992
+ // }
2993
+ // #subscribeToCredentialEvents() {
2994
+ // this.#credentialMessagingService.messages$.subscribe(async (message: AirCredentialMessage) => {
2995
+ // switch (message.type) {
2996
+ // case AirCredentialMessageTypes.CREDENTIAL_IFRAME_VISIBILITY_REQUEST: {
2997
+ // this.#credentialIframeController.setIframeVisibility(message.payload.visible);
2998
+ // this.#credentialIframeController.updateIframeState();
2999
+ // break;
3000
+ // }
3001
+ // case AirCredentialMessageTypes.ISSUE_CREDENTIAL_RESPONSE: {
3002
+ // // Trigger general event for issue credential completion
3003
+ // this.#triggerEventListeners({
3004
+ // event: "credential_issuance_finished",
3005
+ // data: {
3006
+ // success: true,
3007
+ // },
3008
+ // });
3009
+ // break;
3010
+ // }
3011
+ // case AirCredentialMessageTypes.VERIFY_CREDENTIAL_RESPONSE: {
3012
+ // // Trigger general event for verify credential completion
3013
+ // this.#triggerEventListeners({
3014
+ // event: "credential_verification_finished",
3015
+ // data: {
3016
+ // success: true,
3017
+ // verificationResults: message.payload.verificationResults,
3018
+ // },
3019
+ // });
3020
+ // break;
3021
+ // }
3022
+ // }
3023
+ // });
3024
+ // }
3025
+ // async #cleanUpCredential(): Promise<void> {
3026
+ // if (!this.#isAuthInitialized) return;
3027
+ //
3028
+ // const credentialIframeElement = this.#credentialIframeController?.iframeElement;
3029
+ // if (
3030
+ // isElement(credentialIframeElement) &&
3031
+ // window.document.body.contains(credentialIframeElement)
3032
+ // ) {
3033
+ // await this.#credentialMessagingService.logout();
3034
+ // this.#credentialIframeController.destroy();
3035
+ // this.#credentialIframeController = undefined;
3036
+ // }
3037
+ //
3038
+ // const walletIframeElement = this.#walletIframeController?.iframeElement;
3039
+ // if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
3040
+ // await this.#walletMessagingService.resetCredentialCommunication();
3041
+ // }
3042
+ //
3043
+ // const authIframeElement = this.#authIframeController?.iframeElement;
3044
+ // if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3045
+ // await this.#authMessagingService.resetCredentialCommunication();
3046
+ // }
3047
+ //
3048
+ // await this.#credentialMessagingService.close();
3049
+ // this.#credentialsInitialization = undefined;
3050
+ // }
3051
+ async function _AirService_ensureWallet(option) {
2879
3052
  if (!this.isInitialized) throw new Error("Service not initialized");
2880
3053
  if (!this.isLoggedIn && !option?.skipWalletLogin) throw new Error("User not logged in");
2881
3054
  if (!__classPrivateFieldGet$1(this, _AirService_walletInitialization, "f")) __classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_initializeWallet).call(this, option));
@@ -2925,7 +3098,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2925
3098
  };
2926
3099
  window.addEventListener("message", handleWalletMessage);
2927
3100
  });
2928
- __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
3101
+ __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController("air-wallet", walletUrl), "f");
2929
3102
  __classPrivateFieldGet$1(this, _AirService_walletIframeController, "f").createIframe();
2930
3103
  log$1.info(walletUrl, "url loaded");
2931
3104
  await __classPrivateFieldGet$1(this, _AirService_walletMessagingService, "f").open(__classPrivateFieldGet$1(this, _AirService_walletIframeController, "f").iframeElement);
@@ -3112,7 +3285,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3112
3285
  };
3113
3286
  window.addEventListener("message", handleRecoveryMessage);
3114
3287
  });
3115
- __classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(recoveryUrl, `air-recovery-${randomId()}`), "f");
3288
+ __classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController("air-recovery", recoveryUrl), "f");
3116
3289
  __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").createIframe();
3117
3290
  log$1.info(recoveryUrl, "url loaded");
3118
3291
  await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").iframeElement);