@mocanetwork/airkit 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.
@@ -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.5.0";
100
+ var version = "1.5.1";
101
101
  var airkitPackage = {
102
102
  version: version};
103
103
 
@@ -128,8 +128,6 @@ const AirAuthMessageTypes = {
128
128
  CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
129
129
  PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
130
130
  PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
131
- CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
132
- CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
133
131
  LOGOUT_REQUEST: "air_auth_logout_request",
134
132
  LOGOUT_RESPONSE: "air_auth_logout_response",
135
133
  RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
@@ -139,12 +137,9 @@ const AirAuthMessageTypes = {
139
137
  START_RECOVERY_RESPONSE: "air_start_recovery_response",
140
138
  RECOVERY_REQUEST: "air_auth_recovery_request",
141
139
  RECOVERY_RESPONSE: "air_auth_recovery_response",
142
- LINK_EOA_CREDENTIAL_REQUEST: "air_auth_link_eoa_credential_request",
143
- LINK_EOA_CREDENTIAL_RESPONSE: "air_auth_link_eoa_credential_response",
144
- LINKAGE_NONCE_REQUEST: "air_auth_linkage_nonce_request",
145
- LINKAGE_NONCE_RESPONSE: "air_auth_linkage_nonce_response",
146
- CREDENTIAL_SIGNERS_REQUEST: "air_auth_credential_signers_request",
147
- CREDENTIAL_SIGNERS_RESPONSE: "air_auth_credential_signers_response"
140
+ INIT_CREDENTIAL_COMMUNICATION: "air_auth_init_credential_communication",
141
+ RESET_CREDENTIAL_COMMUNICATION: "air_auth_reset_credential_communication",
142
+ EXPIRED_LOGOUT_REQUEST: "air_auth_expired_logout_request"
148
143
  };
149
144
 
150
145
  const AirRecoveryMessageTypes = {
@@ -182,7 +177,11 @@ const AirWalletMessageTypes = {
182
177
  IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
183
178
  IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
184
179
  LOGOUT_REQUEST: "air_logout_request",
185
- LOGOUT_RESPONSE: "air_logout_response"
180
+ LOGOUT_RESPONSE: "air_logout_response",
181
+ INIT_CREDENTIAL_COMMUNICATION: "air_init_credential_communication",
182
+ RESET_CREDENTIAL_COMMUNICATION: "air_reset_credential_communication",
183
+ INTERNAL_PROVIDER_REQUEST: "air_internal_provider_request",
184
+ INTERNAL_PROVIDER_RESPONSE: "air_internal_provider_response"
186
185
  };
187
186
 
188
187
  const AirWindowMessageTypes = {
@@ -571,8 +570,6 @@ const configureLogLevel = (environment, enableLogging) => {
571
570
  level = enableLogging ? log.levels.DEBUG : log.levels.INFO;
572
571
  } else if (environment === "uat" || environment === "sandbox") {
573
572
  level = enableLogging ? log.levels.INFO : log.levels.WARN;
574
- } else if (environment === "sandbox") {
575
- level = enableLogging ? log.levels.WARN : log.levels.ERROR;
576
573
  } else if (environment === "production") {
577
574
  // Be cautious with enabling more than WARN in prod
578
575
  level = enableLogging ? log.levels.WARN : log.levels.ERROR;
@@ -588,32 +585,43 @@ const BUILD_ENV = {
588
585
  DEVELOPMENT: "development",
589
586
  SANDBOX: "sandbox",
590
587
  };
588
+ const IFRAME_NAME_PREFIX_SET = [
589
+ "air-wallet",
590
+ "air-recovery",
591
+ "air-credential",
592
+ "air-auth",
593
+ ]; // order defines the z-index from highest to lowest
591
594
 
592
595
  const AIR_URLS = {
593
596
  [BUILD_ENV.DEVELOPMENT]: {
594
597
  authUrl: "http://localhost:8200/auth/",
595
598
  walletUrl: "http://localhost:8200/wallet/",
596
599
  recoveryUrl: "http://localhost:8200/recovery/",
600
+ credentialUrl: "http://localhost:8200/credential/",
597
601
  },
598
602
  [BUILD_ENV.STAGING]: {
599
603
  authUrl: "https://account.staging.air3.com/auth/",
600
604
  walletUrl: "https://account.staging.air3.com/wallet/",
601
605
  recoveryUrl: "https://account.staging.air3.com/recovery/",
606
+ credentialUrl: "https://account.staging.air3.com/credential/",
602
607
  },
603
608
  [BUILD_ENV.UAT]: {
604
609
  authUrl: "https://account.uat.air3.com/auth/",
605
610
  walletUrl: "https://account.uat.air3.com/wallet/",
606
611
  recoveryUrl: "https://account.uat.air3.com/recovery/",
612
+ credentialUrl: "https://account.uat.air3.com/credential/",
607
613
  },
608
614
  [BUILD_ENV.SANDBOX]: {
609
615
  authUrl: "https://account.sandbox.air3.com/auth/",
610
616
  walletUrl: "https://account.sandbox.air3.com/wallet/",
611
617
  recoveryUrl: "https://account.sandbox.air3.com/recovery/",
618
+ credentialUrl: "https://account.sandbox.air3.com/credential/",
612
619
  },
613
620
  [BUILD_ENV.PRODUCTION]: {
614
621
  authUrl: "https://account.air3.com/auth/",
615
622
  walletUrl: "https://account.air3.com/wallet/",
616
623
  recoveryUrl: "https://account.air3.com/recovery/",
624
+ credentialUrl: "https://account.air3.com/credential/",
617
625
  },
618
626
  };
619
627
  const isElement = (element) => element instanceof Element || element instanceof Document;
@@ -1652,7 +1660,7 @@ const Codes = {
1652
1660
  ...WindowErrorName
1653
1661
  };
1654
1662
 
1655
- const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED"];
1663
+ const AirClientUserErrors = ["USER_CANCELLED", "CONFIG_ERROR", "CLIENT_ERROR", "UNKNOWN_ERROR", "PERMISSION_NOT_ENABLED", "SMART_ACCOUNT_NOT_DEPLOYED", "ACCOUNT_DELETION_PENDING"];
1656
1664
 
1657
1665
  class AirError extends BaseError {}
1658
1666
  new Set(AirClientUserErrors);
@@ -1923,11 +1931,8 @@ const ALLOWED_AUTH_MESSAGES = [
1923
1931
  AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE,
1924
1932
  AirAuthMessageTypes.PARTNER_ACCESS_TOKEN_RESPONSE,
1925
1933
  AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST,
1926
- AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE,
1927
1934
  AirAuthMessageTypes.START_RECOVERY_RESPONSE,
1928
- AirAuthMessageTypes.LINK_EOA_CREDENTIAL_RESPONSE,
1929
- AirAuthMessageTypes.LINKAGE_NONCE_RESPONSE,
1930
- AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE,
1935
+ AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST,
1931
1936
  ];
1932
1937
  class AuthMessageService extends MessageServiceBase {
1933
1938
  static create() {
@@ -2029,28 +2034,18 @@ class AuthMessageService extends MessageServiceBase {
2029
2034
  await this.sendMessage({ type: AirAuthMessageTypes.START_RECOVERY_REQUEST, payload });
2030
2035
  return response;
2031
2036
  }
2032
- async sendCredentialSaltRequest() {
2033
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE)));
2034
- await this.sendMessage({ type: AirAuthMessageTypes.CREDENTIAL_SALT_REQUEST });
2035
- return response;
2036
- }
2037
- async sendLinkEoaCredentialRequest(payload) {
2038
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LINK_EOA_CREDENTIAL_RESPONSE)));
2039
- await this.sendMessage({ type: AirAuthMessageTypes.LINK_EOA_CREDENTIAL_REQUEST, payload });
2040
- return response;
2041
- }
2042
- async sendCredentialSignersRequest(payload) {
2043
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.CREDENTIAL_SIGNERS_RESPONSE)));
2037
+ /*
2038
+ * Initialize credential communication
2039
+ */
2040
+ async initCredentialCommunication() {
2044
2041
  await this.sendMessage({
2045
- type: AirAuthMessageTypes.CREDENTIAL_SIGNERS_REQUEST,
2046
- payload,
2042
+ type: AirAuthMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
2047
2043
  });
2048
- return response;
2049
2044
  }
2050
- async sendLinkageNonceRequest(payload) {
2051
- const response = firstValueFrom(this.messages$.pipe(filter((msg) => msg.type === AirAuthMessageTypes.LINKAGE_NONCE_RESPONSE)));
2052
- await this.sendMessage({ type: AirAuthMessageTypes.LINKAGE_NONCE_REQUEST, payload });
2053
- return response;
2045
+ async resetCredentialCommunication() {
2046
+ await this.sendMessage({
2047
+ type: AirAuthMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
2048
+ });
2054
2049
  }
2055
2050
  }
2056
2051
  _a$2 = AuthMessageService;
@@ -2058,25 +2053,21 @@ _AuthMessageService_instance = { value: void 0 };
2058
2053
 
2059
2054
  class IframeController {
2060
2055
  getZIndex() {
2061
- if (this.iframeId.includes("air-auth"))
2062
- return this.AUTH_IFRAME_Z_INDEX;
2063
- if (this.iframeId.includes("air-wallet"))
2064
- return this.WALLET_IFRAME_Z_INDEX;
2065
- if (this.iframeId.includes("air-recovery"))
2066
- return this.RECOVERY_IFRAME_Z_INDEX;
2067
- return "9999999"; // Default z-index if not matched
2068
- }
2069
- constructor(iframeUrl, iframeId, state) {
2056
+ for (let i = 0; i < IFRAME_NAME_PREFIX_SET.length; i++) {
2057
+ if (this.iframeId.includes(IFRAME_NAME_PREFIX_SET[i])) {
2058
+ return IframeController.HIGHEST_Z_INDEX - i;
2059
+ }
2060
+ }
2061
+ return IframeController.HIGHEST_Z_INDEX - IFRAME_NAME_PREFIX_SET.length; // Lowest z-index if no match
2062
+ }
2063
+ constructor(iframePrefix, iframeUrl, state) {
2070
2064
  this._iframeElement = null;
2071
- this.AUTH_IFRAME_Z_INDEX = "9999998";
2072
- this.WALLET_IFRAME_Z_INDEX = "9999999";
2073
- this.RECOVERY_IFRAME_Z_INDEX = "999999";
2074
2065
  this.state = {
2075
- ...IframeController.defaultState,
2066
+ ...IframeController.DEFAULT_STATE,
2076
2067
  ...state,
2077
2068
  };
2078
2069
  this.iframeUrl = iframeUrl;
2079
- this.iframeId = iframeId;
2070
+ this.iframeId = `${iframePrefix}-${randomId()}`;
2080
2071
  }
2081
2072
  get iframeElement() {
2082
2073
  return this._iframeElement;
@@ -2089,7 +2080,7 @@ class IframeController {
2089
2080
  iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
2090
2081
  iframe.src = this.iframeUrl;
2091
2082
  iframe.style.position = "fixed";
2092
- iframe.style.zIndex = this.getZIndex();
2083
+ iframe.style.zIndex = `${this.getZIndex()}`;
2093
2084
  iframe.style.border = "none";
2094
2085
  iframe.style.margin = "0";
2095
2086
  iframe.style.padding = "0";
@@ -2128,9 +2119,10 @@ class IframeController {
2128
2119
  this.iframeElement.contentWindow.postMessage(message, origin);
2129
2120
  }
2130
2121
  }
2131
- IframeController.defaultState = {
2122
+ IframeController.DEFAULT_STATE = {
2132
2123
  isVisible: false,
2133
2124
  };
2125
+ IframeController.HIGHEST_Z_INDEX = 2147483647;
2134
2126
 
2135
2127
  var _a$1, _RecoveryMessageService_instance;
2136
2128
  const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
@@ -2183,7 +2175,6 @@ const ALLOWED_WALLET_MESSAGES = [
2183
2175
  AirWalletMessageTypes.CLAIM_ID_RESPONSE,
2184
2176
  AirWalletMessageTypes.IS_SMART_ACCOUNT_DEPLOYED_RESPONSE,
2185
2177
  AirWalletMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE,
2186
- AirWalletMessageTypes.WALLET_INITIALIZED,
2187
2178
  AirWalletMessageTypes.WALLET_IFRAME_VISIBILITY_REQUEST,
2188
2179
  AirWalletMessageTypes.LOGOUT_RESPONSE,
2189
2180
  AirWindowMessageTypes.OPEN_WINDOW_REQUEST,
@@ -2191,9 +2182,9 @@ const ALLOWED_WALLET_MESSAGES = [
2191
2182
  ];
2192
2183
  class WalletMessageService extends MessageServiceBase {
2193
2184
  static create() {
2194
- if (__classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance))
2195
- throw new Error("WalletMessageService already created");
2196
- __classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
2185
+ if (!__classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance)) {
2186
+ __classPrivateFieldSet(this, _a, new _a("Embed Service: Wallet Channel", ALLOWED_WALLET_MESSAGES), "f", _WalletMessageService_instance);
2187
+ }
2197
2188
  return __classPrivateFieldGet(this, _a, "f", _WalletMessageService_instance);
2198
2189
  }
2199
2190
  async open(walletIframe) {
@@ -2302,6 +2293,16 @@ class WalletMessageService extends MessageServiceBase {
2302
2293
  });
2303
2294
  return response;
2304
2295
  }
2296
+ async initCredentialCommunication() {
2297
+ await this.sendMessage({
2298
+ type: AirWalletMessageTypes.INIT_CREDENTIAL_COMMUNICATION,
2299
+ });
2300
+ }
2301
+ async resetCredentialCommunication() {
2302
+ await this.sendMessage({
2303
+ type: AirWalletMessageTypes.RESET_CREDENTIAL_COMMUNICATION,
2304
+ });
2305
+ }
2305
2306
  }
2306
2307
  _a = WalletMessageService;
2307
2308
  _WalletMessageService_instance = { value: void 0 };
@@ -2503,6 +2504,9 @@ var WindowService$1 = WindowService.instance;
2503
2504
  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;
2504
2505
  const airKitVersion = airkitPackage.version;
2505
2506
  class AirService {
2507
+ // #credentialsInitialization?: Promise<void>;
2508
+ // #credentialMessagingService: CredentialMessageService;
2509
+ // #credentialIframeController: IframeController;
2506
2510
  constructor({ partnerId }) {
2507
2511
  _AirService_instances.add(this);
2508
2512
  _AirService_loginResult.set(this, void 0);
@@ -2526,6 +2530,7 @@ class AirService {
2526
2530
  __classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create(), "f");
2527
2531
  __classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create(), "f");
2528
2532
  __classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create(), "f");
2533
+ // this.#credentialMessagingService = CredentialMessageService.create();
2529
2534
  __classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
2530
2535
  isWalletInitialized: () => this.isWalletInitialized,
2531
2536
  ensureWallet: __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
@@ -2569,7 +2574,7 @@ class AirService {
2569
2574
  const { authUrl } = AIR_URLS[buildEnv];
2570
2575
  configureLogLevel(buildEnv, enableLogging);
2571
2576
  const authIframeOrigin = new URL(authUrl).origin;
2572
- __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController(authUrl, `air-auth-${randomId()}`), "f");
2577
+ __classPrivateFieldSet(this, _AirService_authIframeController, new IframeController("air-auth", authUrl), "f");
2573
2578
  try {
2574
2579
  __classPrivateFieldGet(this, _AirService_authIframeController, "f").createIframe();
2575
2580
  log.info(authUrl, "url loaded");
@@ -2604,6 +2609,10 @@ class AirService {
2604
2609
  }
2605
2610
  break;
2606
2611
  }
2612
+ case AirAuthMessageTypes.EXPIRED_LOGOUT_REQUEST: {
2613
+ await this.logout();
2614
+ break;
2615
+ }
2607
2616
  }
2608
2617
  });
2609
2618
  const result = await new Promise((resolve, reject) => {
@@ -2700,65 +2709,6 @@ class AirService {
2700
2709
  throw AirServiceError.from(error);
2701
2710
  }
2702
2711
  }
2703
- /**
2704
- * @experimental This method is experimental and will change in the future.
2705
- */
2706
- async getCredentialSalt() {
2707
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2708
- throw new Error("Service is not initialized");
2709
- if (!this.isLoggedIn)
2710
- throw new Error("No active session to get partner access token");
2711
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCredentialSaltRequest();
2712
- if (result.payload.success === false) {
2713
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2714
- }
2715
- return {
2716
- credentialSalt: result.payload.credentialSalt,
2717
- };
2718
- }
2719
- /**
2720
- * @experimental This method is experimental and will change in the future.
2721
- */
2722
- async getLinkageNonce(payload) {
2723
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2724
- throw new Error("Service is not initialized");
2725
- if (!this.isLoggedIn)
2726
- throw new Error("No active session to get nonce");
2727
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLinkageNonceRequest(payload);
2728
- if (result.payload.success === false) {
2729
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2730
- }
2731
- return {
2732
- nonce: result.payload.nonce,
2733
- };
2734
- }
2735
- /**
2736
- * @experimental This method is experimental and will change in the future.
2737
- */
2738
- async retrieveCredentialSigners(payload) {
2739
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2740
- throw new Error("Service is not initialized");
2741
- if (!this.isLoggedIn)
2742
- throw new Error("No active session to retrieve EOA credential");
2743
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendCredentialSignersRequest(payload);
2744
- if (result.payload.success === false) {
2745
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2746
- }
2747
- return result.payload.credentials;
2748
- }
2749
- /**
2750
- * @experimental This method is experimental and will change in the future.
2751
- */
2752
- async linkEoaCredential(payload) {
2753
- if (!__classPrivateFieldGet(this, _AirService_isAuthInitialized, "f"))
2754
- throw new Error("Service is not initialized");
2755
- if (!this.isLoggedIn)
2756
- throw new Error("No active session to link EOA credential");
2757
- const result = await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").sendLinkEoaCredentialRequest(payload);
2758
- if (result.payload.success === false) {
2759
- throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2760
- }
2761
- }
2762
2712
  getProvider() {
2763
2713
  return this.provider;
2764
2714
  }
@@ -2870,9 +2820,13 @@ class AirService {
2870
2820
  throw new Error("Service is not initialized");
2871
2821
  if (!this.isLoggedIn)
2872
2822
  throw new Error("No active session to logout");
2873
- // Clear up wallet
2874
- await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2875
- await __classPrivateFieldGet(this, _AirService_authMessagingService, "f").logout();
2823
+ // Clear up credentials first to avoid issues with wallet and auth messaging services
2824
+ // await this.#cleanUpCredential();
2825
+ await Promise.all([
2826
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this),
2827
+ __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this),
2828
+ __classPrivateFieldGet(this, _AirService_authMessagingService, "f").logout(),
2829
+ ]);
2876
2830
  __classPrivateFieldSet(this, _AirService_loginResult, undefined, "f");
2877
2831
  __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_triggerAirAuthLoggedOut).call(this);
2878
2832
  }
@@ -2880,8 +2834,22 @@ class AirService {
2880
2834
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2881
2835
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
2882
2836
  await __classPrivateFieldGet(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
2837
+ // await this.#cleanUpCredential();
2883
2838
  this.clearEventListeners();
2884
2839
  }
2840
+ /**
2841
+ * Register an event listener for Air service events.
2842
+ *
2843
+ * Available events:
2844
+ * - "initialized": Service initialization completed
2845
+ * - "logged_in": User successfully logged in
2846
+ * - "logged_out": User logged out
2847
+ * - "wallet_initialized": Wallet initialization completed
2848
+ * - "credential_issuance_finished": Credential issuance finished (success or failure)
2849
+ * - "credential_verification_finished": Credential verification finished (success or failure)
2850
+ *
2851
+ * @param listener The event listener function
2852
+ */
2885
2853
  on(listener) {
2886
2854
  if (__classPrivateFieldGet(this, _AirService_airAuthListener, "f").indexOf(listener) < 0)
2887
2855
  __classPrivateFieldGet(this, _AirService_airAuthListener, "f").push(listener);
@@ -2894,7 +2862,211 @@ class AirService {
2894
2862
  __classPrivateFieldSet(this, _AirService_airAuthListener, [], "f");
2895
2863
  }
2896
2864
  }
2897
- _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) {
2865
+ _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 =
2866
+ // /**
2867
+ // * Issue a credential using the credential SDK
2868
+ // * @param claimRequest The claim request containing credential details
2869
+ // * @param projectName The name of the project
2870
+ // * @param options Optional configuration for the credential widget
2871
+ // */
2872
+ // public async issueCredential(
2873
+ // claimRequest: {
2874
+ // process: "Issue";
2875
+ // issuerDid: string;
2876
+ // issuerAuth: string;
2877
+ // credentialId: string;
2878
+ // credentialSubject: Record<string, unknown>;
2879
+ // },
2880
+ // projectName: string,
2881
+ // options?: {
2882
+ // endpoint?: string;
2883
+ // theme?: "auto" | "light" | "dark";
2884
+ // locale?: "en" | "zh-hk";
2885
+ // }
2886
+ // ): Promise<Record<string, never>> {
2887
+ // await this.#ensureCredentials();
2888
+ // try {
2889
+ // const { payload } = await this.#credentialMessagingService.sendIssueCredentialRequest({
2890
+ // claimRequest,
2891
+ // projectName,
2892
+ // options: options || {},
2893
+ // });
2894
+ //
2895
+ // return payload;
2896
+ // } catch (error) {
2897
+ // throw AirServiceError.from(error);
2898
+ // }
2899
+ // }
2900
+ //
2901
+ // /**
2902
+ // * Verify a credential using the credential SDK
2903
+ // * @param queryRequest The query request containing verification details
2904
+ // * @param projectName The name of the project
2905
+ // * @param options Optional configuration for the credential widget
2906
+ // */
2907
+ // public async verifyCredential(
2908
+ // queryRequest: {
2909
+ // process: "Verify";
2910
+ // verifierAuth: string;
2911
+ // programId: string;
2912
+ // },
2913
+ // projectName: string,
2914
+ // options?: {
2915
+ // endpoint?: string;
2916
+ // theme?: "auto" | "light" | "dark";
2917
+ // locale?: "en" | "zh-hk";
2918
+ // }
2919
+ // ): Promise<{
2920
+ // verificationResults: {
2921
+ // status:
2922
+ // | "Compliant"
2923
+ // | "Non-Compliant"
2924
+ // | "Pending"
2925
+ // | "Revoking"
2926
+ // | "Revoked"
2927
+ // | "Expired"
2928
+ // | "NotFound";
2929
+ // };
2930
+ // }> {
2931
+ // await this.#ensureCredentials();
2932
+ //
2933
+ // try {
2934
+ // const { payload } = await this.#credentialMessagingService.sendVerifyCredentialRequest({
2935
+ // queryRequest,
2936
+ // projectName,
2937
+ // options: options || {},
2938
+ // });
2939
+ //
2940
+ // return payload;
2941
+ // } catch (error) {
2942
+ // throw AirServiceError.from(error);
2943
+ // }
2944
+ // }
2945
+ // async #ensureCredentials(): Promise<void> {
2946
+ // if (!this.isInitialized) throw new Error("Service not initialized");
2947
+ // if (!this.isLoggedIn) throw new Error("User not logged in");
2948
+ // void this.#ensureWallet();
2949
+ //
2950
+ // try {
2951
+ // if (!this.#credentialsInitialization)
2952
+ // this.#credentialsInitialization = this.#initializeCredentials();
2953
+ // await this.#credentialsInitialization;
2954
+ // } catch (error) {
2955
+ // this.#credentialsInitialization = null;
2956
+ // log.error("Error ensuring credentials", error);
2957
+ // throw error;
2958
+ // }
2959
+ // }
2960
+ // async #initializeCredentials(): Promise<void> {
2961
+ // if (this.#credentialsInitialization) {
2962
+ // throw new Error("Already initializing credentials");
2963
+ // }
2964
+ // const { credentialUrl } = AIR_URLS[this.#buildEnv];
2965
+ // const credentailIframeOrigin = new URL(credentialUrl).origin;
2966
+ // try {
2967
+ // const credentialInitRequestPromise = new Promise<void>((resolve, reject) => {
2968
+ // const handleCredentialMessage = async (ev: MessageEvent) => {
2969
+ // if (ev.origin !== credentailIframeOrigin) return;
2970
+ // if (ev.data === AirCredentialMessageTypes.SERVICE_STARTED) {
2971
+ // window.removeEventListener("message", handleCredentialMessage);
2972
+ // const { payload } = await this.#credentialMessagingService.sendInitializationRequest({
2973
+ // partnerId: this.#partnerId,
2974
+ // enableLogging: this.#enableLogging,
2975
+ // sdkVersion: airKitVersion,
2976
+ // enableAutomation: this.shouldEnableAutomation(),
2977
+ // });
2978
+ // if (payload.success === true) {
2979
+ // resolve();
2980
+ // } else {
2981
+ // reject(new AirServiceError(payload.errorName, payload.errorMessage));
2982
+ // }
2983
+ // }
2984
+ // };
2985
+ // window.addEventListener("message", handleCredentialMessage);
2986
+ // });
2987
+ // this.#credentialIframeController = new IframeController("air-credential", credentialUrl);
2988
+ // this.#credentialIframeController.createIframe();
2989
+ // log.info(credentialUrl, "url loaded");
2990
+ //
2991
+ // await this.#credentialMessagingService.open(this.#credentialIframeController.iframeElement);
2992
+ // this.#subscribeToCredentialEvents();
2993
+ // await credentialInitRequestPromise;
2994
+ //
2995
+ // await this.#authMessagingService.initCredentialCommunication();
2996
+ // await this.#credentialMessagingService.initAuthCommunication();
2997
+ // log.info("[Embed] Credential auth channel initialized");
2998
+ //
2999
+ // await this.#ensureWallet();
3000
+ // await this.#walletMessagingService.initCredentialCommunication();
3001
+ // await this.#credentialMessagingService.initWalletCommunication();
3002
+ // log.info("[Embed] Credential wallet channel initialized");
3003
+ //
3004
+ // log.info("Credential service initialized successfully");
3005
+ // } catch (error) {
3006
+ // log.error("Error initializing credentials", error);
3007
+ // await this.#cleanUpCredential();
3008
+ // throw error;
3009
+ // }
3010
+ // }
3011
+ // #subscribeToCredentialEvents() {
3012
+ // this.#credentialMessagingService.messages$.subscribe(async (message: AirCredentialMessage) => {
3013
+ // switch (message.type) {
3014
+ // case AirCredentialMessageTypes.CREDENTIAL_IFRAME_VISIBILITY_REQUEST: {
3015
+ // this.#credentialIframeController.setIframeVisibility(message.payload.visible);
3016
+ // this.#credentialIframeController.updateIframeState();
3017
+ // break;
3018
+ // }
3019
+ // case AirCredentialMessageTypes.ISSUE_CREDENTIAL_RESPONSE: {
3020
+ // // Trigger general event for issue credential completion
3021
+ // this.#triggerEventListeners({
3022
+ // event: "credential_issuance_finished",
3023
+ // data: {
3024
+ // success: true,
3025
+ // },
3026
+ // });
3027
+ // break;
3028
+ // }
3029
+ // case AirCredentialMessageTypes.VERIFY_CREDENTIAL_RESPONSE: {
3030
+ // // Trigger general event for verify credential completion
3031
+ // this.#triggerEventListeners({
3032
+ // event: "credential_verification_finished",
3033
+ // data: {
3034
+ // success: true,
3035
+ // verificationResults: message.payload.verificationResults,
3036
+ // },
3037
+ // });
3038
+ // break;
3039
+ // }
3040
+ // }
3041
+ // });
3042
+ // }
3043
+ // async #cleanUpCredential(): Promise<void> {
3044
+ // if (!this.#isAuthInitialized) return;
3045
+ //
3046
+ // const credentialIframeElement = this.#credentialIframeController?.iframeElement;
3047
+ // if (
3048
+ // isElement(credentialIframeElement) &&
3049
+ // window.document.body.contains(credentialIframeElement)
3050
+ // ) {
3051
+ // await this.#credentialMessagingService.logout();
3052
+ // this.#credentialIframeController.destroy();
3053
+ // this.#credentialIframeController = undefined;
3054
+ // }
3055
+ //
3056
+ // const walletIframeElement = this.#walletIframeController?.iframeElement;
3057
+ // if (isElement(walletIframeElement) && window.document.body.contains(walletIframeElement)) {
3058
+ // await this.#walletMessagingService.resetCredentialCommunication();
3059
+ // }
3060
+ //
3061
+ // const authIframeElement = this.#authIframeController?.iframeElement;
3062
+ // if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3063
+ // await this.#authMessagingService.resetCredentialCommunication();
3064
+ // }
3065
+ //
3066
+ // await this.#credentialMessagingService.close();
3067
+ // this.#credentialsInitialization = undefined;
3068
+ // }
3069
+ async function _AirService_ensureWallet(option) {
2898
3070
  if (!this.isInitialized)
2899
3071
  throw new Error("Service not initialized");
2900
3072
  if (!this.isLoggedIn && !option?.skipWalletLogin)
@@ -2949,7 +3121,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2949
3121
  };
2950
3122
  window.addEventListener("message", handleWalletMessage);
2951
3123
  });
2952
- __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController(walletUrl, `air-wallet-${randomId()}`), "f");
3124
+ __classPrivateFieldSet(this, _AirService_walletIframeController, new IframeController("air-wallet", walletUrl), "f");
2953
3125
  __classPrivateFieldGet(this, _AirService_walletIframeController, "f").createIframe();
2954
3126
  log.info(walletUrl, "url loaded");
2955
3127
  await __classPrivateFieldGet(this, _AirService_walletMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_walletIframeController, "f").iframeElement);
@@ -3127,7 +3299,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
3127
3299
  };
3128
3300
  window.addEventListener("message", handleRecoveryMessage);
3129
3301
  });
3130
- __classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(recoveryUrl, `air-recovery-${randomId()}`), "f");
3302
+ __classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController("air-recovery", recoveryUrl), "f");
3131
3303
  __classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").createIframe();
3132
3304
  log.info(recoveryUrl, "url loaded");
3133
3305
  await __classPrivateFieldGet(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet(this, _AirService_recoveryIframeController, "f").iframeElement);
@@ -3180,6 +3352,7 @@ exports.AirService = AirService;
3180
3352
  exports.AirServiceError = AirServiceError;
3181
3353
  exports.BUILD_ENV = BUILD_ENV;
3182
3354
  exports.ChainDisconnectedError = ChainDisconnectedError;
3355
+ exports.IFRAME_NAME_PREFIX_SET = IFRAME_NAME_PREFIX_SET;
3183
3356
  exports.InternalRpcError = InternalRpcError;
3184
3357
  exports.InvalidParamsRpcError = InvalidParamsRpcError;
3185
3358
  exports.InvalidRequestRpcError = InvalidRequestRpcError;