@mocanetwork/airkit-connector 1.3.0 → 1.4.0-beta.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.
@@ -92,13 +92,19 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
92
  var e = new Error(message);
93
93
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
94
94
  };
95
+ var version$2 = "1.4.0-beta.1";
96
+ var airkitPackage = {
97
+ version: version$2
98
+ };
95
99
  const AirAuthMessageTypes = {
96
100
  AUTH_SETUP_COMPLETED: "air_auth_setup_completed",
97
101
  INITIALIZATION_REQUEST: "air_auth_initialization_request",
98
102
  INITIALIZATION_RESPONSE: "air_auth_initialization_response",
99
103
  LOGIN_REQUEST: "air_auth_login_request",
100
104
  LOGIN_RESPONSE: "air_auth_login_response",
101
- LOGIN_WALLET_RESPONSE: "air_auth_login_wallet_response",
105
+ LOGIN_SERVICE_RESPONSE: "air_auth_login_service_response",
106
+ PASSKEY_LOGIN_REQUEST: "air_auth_passkey_login_request",
107
+ PASSKEY_LOGIN_RESPONSE: "air_auth_passkey_login_response",
102
108
  USER_INFO_REQUEST: "air_auth_user_info_request",
103
109
  USER_INFO_RESPONSE: "air_auth_user_info_response",
104
110
  PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
@@ -111,17 +117,37 @@ const AirAuthMessageTypes = {
111
117
  IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
112
118
  SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
113
119
  SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
120
+ SETUP_RECOVERY_REQUEST: "air_auth_setup_recovery_request",
121
+ SETUP_RECOVERY_RESPONSE: "air_auth_setup_recovery_response",
114
122
  SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request",
115
123
  SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
116
124
  CROSS_PARTNER_TOKEN_REQUEST: "air_auth_cross_partner_token_request",
117
125
  CROSS_PARTNER_TOKEN_RESPONSE: "air_auth_cross_partner_token_response",
118
126
  PARTNER_ACCESS_TOKEN_REQUEST: "air_auth_partner_access_token_request",
119
127
  PARTNER_ACCESS_TOKEN_RESPONSE: "air_auth_partner_access_token_response",
128
+ PRIVY_LOGIN_REQUEST: "air_auth_privy_login_request",
129
+ PRIVY_LOGIN_RESPONSE: "air_auth_privy_login_response",
120
130
  CREDENTIAL_SALT_REQUEST: "air_auth_credential_salt_request",
121
131
  CREDENTIAL_SALT_RESPONSE: "air_auth_credential_salt_response",
122
132
  LOGOUT_REQUEST: "air_auth_logout_request",
123
133
  LOGOUT_RESPONSE: "air_auth_logout_response",
124
- RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication"
134
+ RESET_WALLET_COMMUNICATION: "air_auth_reset_wallet_communication",
135
+ INIT_RECOVERY_COMMUNICATION: "air_auth_init_recovery_communication",
136
+ RESET_RECOVERY_COMMUNICATION: "air_auth_reset_recovery_communication",
137
+ START_RECOVERY_REQUEST: "air_start_recovery_request",
138
+ START_RECOVERY_RESPONSE: "air_start_recovery_response",
139
+ OTP_REQUEST: "air_auth_otp_request",
140
+ OTP_RESPONSE: "air_auth_otp_response"
141
+ };
142
+ const AirRecoveryMessageTypes = {
143
+ SERVICE_STARTED: "air_recovery_service_started",
144
+ INITIALIZATION_REQUEST: "air_recovery_initialization_request",
145
+ INITIALIZATION_RESPONSE: "air_recovery_initialization_response",
146
+ INIT_AUTH_COMMUNICATION: "air_recovery_init_auth_communication",
147
+ RECOVERY_INITIALIZED: "air_recovery_initialized",
148
+ RECOVERY_IFRAME_VISIBILITY_REQUEST: "air_recovery_iframe_visibility_request",
149
+ LOGOUT_REQUEST: "air_recovery_logout_request",
150
+ LOGOUT_RESPONSE: "air_recovery_logout_response"
125
151
  };
126
152
  const AirWalletMessageTypes = {
127
153
  SERVICE_STARTED: "air_service_started",
@@ -135,223 +161,23 @@ const AirWalletMessageTypes = {
135
161
  SETUP_OR_UPDATE_MFA_RESPONSE: "air_setup_mfa_response",
136
162
  CLAIM_ID_REQUEST: "air_claim_id_request",
137
163
  CLAIM_ID_RESPONSE: "air_claim_id_response",
164
+ SHOW_SWAP_UI_REQUEST: "air_show_swap_ui_request",
165
+ SHOW_SWAP_UI_RESPONSE: "air_show_swap_ui_response",
138
166
  DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
139
167
  DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
140
168
  WALLET_IFRAME_VISIBILITY_REQUEST: "air_wallet_iframe_visibility_request",
141
- OPEN_WINDOW_REQUEST: "air_open_window_request",
142
- OPEN_WINDOW_RESPONSE: "air_open_window_response",
143
- OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
144
- OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
145
- WINDOW_CLOSED: "air_window_closed",
146
169
  IS_SMART_ACCOUNT_DEPLOYED_REQUEST: "air_is_smart_account_deployed_request",
147
170
  IS_SMART_ACCOUNT_DEPLOYED_RESPONSE: "air_is_smart_account_deployed_response",
148
171
  LOGOUT_REQUEST: "air_logout_request",
149
172
  LOGOUT_RESPONSE: "air_logout_response"
150
173
  };
151
- let BaseError$2 = class BaseError extends Error {
152
- constructor(name, message, options = {}) {
153
- const {
154
- cause,
155
- context
156
- } = options;
157
- super(message || name);
158
- this.name = name;
159
- this.stack = cause?.stack;
160
- this.cause = cause;
161
- this.context = context;
162
- }
163
- toJSON() {
164
- return {
165
- name: this.name,
166
- message: this.message,
167
- context: this.context,
168
- cause: this.cause
169
- };
170
- }
171
- };
172
- function ensureError(value) {
173
- if (value instanceof Error) return value;
174
- let stringified = "[Unable to stringify the thrown value]";
175
- try {
176
- stringified = JSON.stringify(value);
177
- } catch {
178
- // ignoring failed stringify
179
- }
180
- return new Error(`This value was not thrown as type Error: ${stringified}`);
181
- }
182
- const BUILD_ENV = {
183
- PRODUCTION: "production",
184
- UAT: "uat",
185
- STAGING: "staging",
186
- DEVELOPMENT: "development"
187
- };
188
- const AIR_URLS = {
189
- [BUILD_ENV.DEVELOPMENT]: {
190
- authUrl: "http://localhost:8200/auth/",
191
- walletUrl: "http://localhost:8200/wallet/"
192
- },
193
- [BUILD_ENV.UAT]: {
194
- authUrl: "https://account.uat.air3.com/auth/",
195
- walletUrl: "https://account.uat.air3.com/wallet/"
196
- },
197
- [BUILD_ENV.STAGING]: {
198
- authUrl: "https://account.staging.air3.com/auth/",
199
- walletUrl: "https://account.staging.air3.com/wallet/"
200
- },
201
- [BUILD_ENV.PRODUCTION]: {
202
- authUrl: "https://account.air3.com/auth/",
203
- walletUrl: "https://account.air3.com/wallet/"
204
- }
205
- };
206
- const isElement = element => element instanceof Element || element instanceof Document;
207
- const randomId = () => Math.random().toString(36).slice(2);
208
- const extractErrorHash = message => {
209
- if (!message) return "";
210
- // Format: "reason: 0x..."
211
- if (message.includes("reason:")) {
212
- return message.split("reason:")[1].trim();
213
- }
214
- // Format: "UserOperation reverted during simulation with reason: 0x..."
215
- if (message.includes("with reason:")) {
216
- const match = message.match(/with reason: (0x[a-fA-F0-9]+)/);
217
- return match ? match[1].trim() : "";
218
- }
219
- // Look for any 0x pattern that could be a hash
220
- const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
221
- return hexMatch ? hexMatch[1].trim() : "";
222
- };
223
- class AirServiceError extends BaseError$2 {
224
- static from(error) {
225
- if (error instanceof AirServiceError) {
226
- return error;
227
- } else if (error instanceof Object && "message" in error) {
228
- if (error.message === "User cancelled login") {
229
- return new AirServiceError("USER_CANCELLED", error.message);
230
- }
231
- return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
232
- }
233
- return new AirServiceError("UNKNOWN_ERROR");
234
- }
235
- }
236
- let ProviderRpcError$1 = class ProviderRpcError extends Error {
237
- constructor(message) {
238
- super(message);
239
- this.metaMessages = [];
240
- }
241
- };
242
- let UserRejectedRequestError$1 = class UserRejectedRequestError extends ProviderRpcError$1 {
243
- constructor() {
244
- super(...arguments);
245
- this.code = 4001;
246
- this.name = "UserRejectedRequestError";
247
- }
248
- };
249
- class UnauthorizedProviderError extends ProviderRpcError$1 {
250
- constructor() {
251
- super(...arguments);
252
- this.code = 4100;
253
- this.name = "UnauthorizedProviderError";
254
- }
255
- }
256
- class UnsupportedProviderMethodError extends ProviderRpcError$1 {
257
- constructor() {
258
- super(...arguments);
259
- this.code = 4200;
260
- this.name = "UnsupportedProviderMethodError";
261
- }
262
- }
263
- class ProviderDisconnectedError extends ProviderRpcError$1 {
264
- constructor() {
265
- super(...arguments);
266
- this.code = 4900;
267
- this.name = "ProviderDisconnectedError";
268
- }
269
- }
270
- class ChainDisconnectedError extends ProviderRpcError$1 {
271
- constructor() {
272
- super(...arguments);
273
- this.code = 4901;
274
- this.name = "ChainDisconnectedError";
275
- }
276
- }
277
- let SwitchChainError$1 = class SwitchChainError extends ProviderRpcError$1 {
278
- constructor() {
279
- super(...arguments);
280
- this.code = 4902;
281
- this.name = "SwitchChainError";
282
- }
174
+ const AirWindowMessageTypes = {
175
+ OPEN_WINDOW_REQUEST: "air_open_window_request",
176
+ OPEN_WINDOW_RESPONSE: "air_open_window_response",
177
+ OPEN_WINDOW_RETRY_REQUEST: "air_open_window_retry_request",
178
+ OPEN_WINDOW_RETRY_RESPONSE: "air_open_window_retry_response",
179
+ WINDOW_CLOSED: "air_window_closed"
283
180
  };
284
- class TransactionRejectedRpcError extends ProviderRpcError$1 {
285
- constructor(message) {
286
- // Remove the "Version: viem@x.x.x" suffix if present
287
- const cleanMessage = message.replace(/\nVersion:.*$/, '');
288
- super(cleanMessage);
289
- this.code = -32003;
290
- this.name = "TransactionRejectedRpcError";
291
- // Parse the error hash from the message
292
- this.metaMessages.push(extractErrorHash(cleanMessage));
293
- }
294
- }
295
- class InvalidRequestRpcError extends ProviderRpcError$1 {
296
- constructor() {
297
- super(...arguments);
298
- this.code = -32600;
299
- this.name = "InvalidRequestRpcError";
300
- }
301
- }
302
- class MethodNotFoundRpcError extends ProviderRpcError$1 {
303
- constructor() {
304
- super(...arguments);
305
- this.code = -32601;
306
- this.name = "MethodNotFoundRpcError";
307
- }
308
- }
309
- class InvalidParamsRpcError extends ProviderRpcError$1 {
310
- constructor() {
311
- super(...arguments);
312
- this.code = -32602;
313
- this.name = "InvalidParamsRpcError";
314
- }
315
- }
316
- class InternalRpcError extends ProviderRpcError$1 {
317
- constructor() {
318
- super(...arguments);
319
- this.code = -32603;
320
- this.name = "InternalRpcError";
321
- }
322
- }
323
- function ensureProviderRpcError(value) {
324
- if (value instanceof ProviderRpcError$1) {
325
- return value;
326
- }
327
- if (typeof value === "object" && value !== null && "errorCode" in value && "errorMessage" in value) {
328
- if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
329
- switch (value.errorCode) {
330
- case 4001:
331
- return new UserRejectedRequestError$1(value.errorMessage);
332
- case 4100:
333
- return new UnauthorizedProviderError(value.errorMessage);
334
- case 4200:
335
- return new UnsupportedProviderMethodError(value.errorMessage);
336
- case 4900:
337
- return new ProviderDisconnectedError(value.errorMessage);
338
- case 4901:
339
- return new ChainDisconnectedError(value.errorMessage);
340
- case 4902:
341
- return new SwitchChainError$1(value.errorMessage);
342
- case -32003:
343
- return new TransactionRejectedRpcError(value.errorMessage);
344
- }
345
- }
346
- }
347
- let stringified = "[Unable to stringify the thrown value]";
348
- try {
349
- stringified = JSON.stringify(value);
350
- } catch {
351
- // ignoring failed stringify
352
- }
353
- return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
354
- }
355
181
  function getDefaultExportFromCjs$1(x) {
356
182
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
357
183
  }
@@ -680,44 +506,281 @@ function requireLoglevel$1() {
680
506
  }
681
507
  var loglevelExports$1 = requireLoglevel$1();
682
508
  var log$1 = /*@__PURE__*/getDefaultExportFromCjs$1(loglevelExports$1);
683
- function isFunction(value) {
684
- return typeof value === 'function';
685
- }
686
- function createErrorClass(createImpl) {
687
- var _super = function (instance) {
688
- Error.call(instance);
689
- instance.stack = new Error().stack;
690
- };
691
- var ctorFunc = createImpl(_super);
692
- ctorFunc.prototype = Object.create(Error.prototype);
693
- ctorFunc.prototype.constructor = ctorFunc;
694
- return ctorFunc;
695
- }
696
- var UnsubscriptionError = createErrorClass(function (_super) {
697
- return function UnsubscriptionErrorImpl(errors) {
698
- _super(this);
699
- this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
700
- return i + 1 + ") " + err.toString();
701
- }).join('\n ') : '';
702
- this.name = 'UnsubscriptionError';
703
- this.errors = errors;
704
- };
705
- });
706
- function arrRemove(arr, item) {
707
- if (arr) {
708
- var index = arr.indexOf(item);
709
- 0 <= index && arr.splice(index, 1);
710
- }
711
- }
712
- var Subscription = function () {
713
- function Subscription(initialTeardown) {
714
- this.initialTeardown = initialTeardown;
715
- this.closed = false;
716
- this._parentage = null;
717
- this._finalizers = null;
509
+ let BaseError$2 = class BaseError extends Error {
510
+ constructor(name, message, options = {}) {
511
+ const {
512
+ cause,
513
+ context
514
+ } = options;
515
+ super(message || name);
516
+ this.name = name;
517
+ this.stack = cause?.stack;
518
+ this.cause = cause;
519
+ this.context = context;
718
520
  }
719
- Subscription.prototype.unsubscribe = function () {
720
- var e_1, _a, e_2, _b;
521
+ toJSON() {
522
+ return {
523
+ name: this.name,
524
+ message: this.message,
525
+ context: this.context,
526
+ cause: this.cause
527
+ };
528
+ }
529
+ };
530
+ function ensureError(value) {
531
+ if (value instanceof Error) return value;
532
+ let stringified = "[Unable to stringify the thrown value]";
533
+ try {
534
+ stringified = JSON.stringify(value);
535
+ } catch {
536
+ // ignoring failed stringify
537
+ }
538
+ return new Error(`This value was not thrown as type Error: ${stringified}`);
539
+ }
540
+ const getLevelName = levelNum => {
541
+ const levelNames = Object.keys(log$1.levels);
542
+ if (levelNum >= 0 && levelNum < levelNames.length) {
543
+ return levelNames[levelNum];
544
+ }
545
+ return "UNKNOWN";
546
+ };
547
+ const configureLogLevel = (environment, enableLogging) => {
548
+ let level = log$1.levels.ERROR;
549
+ if (environment === "development") {
550
+ level = enableLogging ? log$1.levels.TRACE : log$1.levels.INFO;
551
+ } else if (environment === "staging") {
552
+ level = enableLogging ? log$1.levels.DEBUG : log$1.levels.INFO;
553
+ } else if (environment === "uat") {
554
+ level = enableLogging ? log$1.levels.INFO : log$1.levels.WARN;
555
+ } else if (environment === "production") {
556
+ // Be cautious with enabling more than WARN in prod
557
+ level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
558
+ }
559
+ log$1.setLevel(level);
560
+ log$1.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log$1.getLevel())}`);
561
+ };
562
+ const BUILD_ENV = {
563
+ PRODUCTION: "production",
564
+ UAT: "uat",
565
+ STAGING: "staging",
566
+ DEVELOPMENT: "development",
567
+ SANDBOX: "sandbox"
568
+ };
569
+ const AIR_URLS = {
570
+ [BUILD_ENV.DEVELOPMENT]: {
571
+ authUrl: "http://localhost:8200/auth/",
572
+ walletUrl: "http://localhost:8200/wallet/",
573
+ recoveryUrl: "http://localhost:8200/recovery/"
574
+ },
575
+ [BUILD_ENV.STAGING]: {
576
+ authUrl: "https://account.staging.air3.com/auth/",
577
+ walletUrl: "https://account.staging.air3.com/wallet/",
578
+ recoveryUrl: "https://account.staging.air3.com/recovery/"
579
+ },
580
+ [BUILD_ENV.UAT]: {
581
+ authUrl: "https://account.uat.air3.com/auth/",
582
+ walletUrl: "https://account.uat.air3.com/wallet/",
583
+ recoveryUrl: "https://account.uat.air3.com/recovery/"
584
+ },
585
+ [BUILD_ENV.SANDBOX]: {
586
+ authUrl: "https://account.sandbox.air3.com/auth/",
587
+ walletUrl: "https://account.sandbox.air3.com/wallet/",
588
+ recoveryUrl: "https://account.sandbox.air3.com/recovery/"
589
+ },
590
+ [BUILD_ENV.PRODUCTION]: {
591
+ authUrl: "https://account.air3.com/auth/",
592
+ walletUrl: "https://account.air3.com/wallet/",
593
+ recoveryUrl: "https://account.air3.com/recovery/"
594
+ }
595
+ };
596
+ const isElement = element => element instanceof Element || element instanceof Document;
597
+ const randomId = () => Math.random().toString(36).slice(2);
598
+ const extractErrorHash = message => {
599
+ if (!message) return "";
600
+ // Format: "reason: 0x..."
601
+ if (message.includes("reason:")) {
602
+ const match = message.match(/reason:\s*(0x[a-fA-F0-9]+)/);
603
+ return match ? match[1].trim() : "";
604
+ }
605
+ // Format: "UserOperation reverted during simulation with reason: 0x..."
606
+ if (message.includes("with reason:")) {
607
+ const match = message.match(/with reason:\s*(0x[a-fA-F0-9]+)/);
608
+ return match ? match[1].trim() : "";
609
+ }
610
+ // Look for any 0x pattern that could be a hash
611
+ const hexMatch = message.match(/(0x[a-fA-F0-9]{8,})/);
612
+ return hexMatch ? hexMatch[1].trim() : "";
613
+ };
614
+ class AirServiceError extends BaseError$2 {
615
+ static from(error) {
616
+ if (error instanceof AirServiceError) {
617
+ return error;
618
+ } else if (error instanceof Object && "message" in error) {
619
+ if (error.message === "User cancelled login") {
620
+ return new AirServiceError("USER_CANCELLED", error.message);
621
+ }
622
+ return new AirServiceError("UNKNOWN_ERROR", error.message.toString());
623
+ }
624
+ return new AirServiceError("UNKNOWN_ERROR");
625
+ }
626
+ }
627
+ let ProviderRpcError$1 = class ProviderRpcError extends Error {
628
+ constructor(message) {
629
+ super(message);
630
+ this.metaMessages = [];
631
+ }
632
+ };
633
+ let UserRejectedRequestError$1 = class UserRejectedRequestError extends ProviderRpcError$1 {
634
+ constructor() {
635
+ super(...arguments);
636
+ this.code = 4001;
637
+ this.name = "UserRejectedRequestError";
638
+ }
639
+ };
640
+ class UnauthorizedProviderError extends ProviderRpcError$1 {
641
+ constructor() {
642
+ super(...arguments);
643
+ this.code = 4100;
644
+ this.name = "UnauthorizedProviderError";
645
+ }
646
+ }
647
+ class UnsupportedProviderMethodError extends ProviderRpcError$1 {
648
+ constructor() {
649
+ super(...arguments);
650
+ this.code = 4200;
651
+ this.name = "UnsupportedProviderMethodError";
652
+ }
653
+ }
654
+ class ProviderDisconnectedError extends ProviderRpcError$1 {
655
+ constructor() {
656
+ super(...arguments);
657
+ this.code = 4900;
658
+ this.name = "ProviderDisconnectedError";
659
+ }
660
+ }
661
+ class ChainDisconnectedError extends ProviderRpcError$1 {
662
+ constructor() {
663
+ super(...arguments);
664
+ this.code = 4901;
665
+ this.name = "ChainDisconnectedError";
666
+ }
667
+ }
668
+ let SwitchChainError$1 = class SwitchChainError extends ProviderRpcError$1 {
669
+ constructor() {
670
+ super(...arguments);
671
+ this.code = 4902;
672
+ this.name = "SwitchChainError";
673
+ }
674
+ };
675
+ class TransactionRejectedRpcError extends ProviderRpcError$1 {
676
+ constructor(message) {
677
+ // Remove the "Version: viem@x.x.x" suffix if present
678
+ const cleanMessage = message.replace(/\nVersion:.*$/, '');
679
+ super(cleanMessage);
680
+ this.code = -32003;
681
+ this.name = "TransactionRejectedRpcError";
682
+ // Parse the error hash from the message
683
+ this.metaMessages.push(extractErrorHash(cleanMessage));
684
+ }
685
+ }
686
+ class InvalidRequestRpcError extends ProviderRpcError$1 {
687
+ constructor() {
688
+ super(...arguments);
689
+ this.code = -32600;
690
+ this.name = "InvalidRequestRpcError";
691
+ }
692
+ }
693
+ class MethodNotFoundRpcError extends ProviderRpcError$1 {
694
+ constructor() {
695
+ super(...arguments);
696
+ this.code = -32601;
697
+ this.name = "MethodNotFoundRpcError";
698
+ }
699
+ }
700
+ class InvalidParamsRpcError extends ProviderRpcError$1 {
701
+ constructor() {
702
+ super(...arguments);
703
+ this.code = -32602;
704
+ this.name = "InvalidParamsRpcError";
705
+ }
706
+ }
707
+ class InternalRpcError extends ProviderRpcError$1 {
708
+ constructor() {
709
+ super(...arguments);
710
+ this.code = -32603;
711
+ this.name = "InternalRpcError";
712
+ }
713
+ }
714
+ function ensureProviderRpcError(value) {
715
+ if (value instanceof ProviderRpcError$1) {
716
+ return value;
717
+ }
718
+ if (typeof value === "object" && value !== null && "errorCode" in value && "errorMessage" in value) {
719
+ if (typeof value.errorCode === "number" && typeof value.errorMessage === "string") {
720
+ switch (value.errorCode) {
721
+ case 4001:
722
+ return new UserRejectedRequestError$1(value.errorMessage);
723
+ case 4100:
724
+ return new UnauthorizedProviderError(value.errorMessage);
725
+ case 4200:
726
+ return new UnsupportedProviderMethodError(value.errorMessage);
727
+ case 4900:
728
+ return new ProviderDisconnectedError(value.errorMessage);
729
+ case 4901:
730
+ return new ChainDisconnectedError(value.errorMessage);
731
+ case 4902:
732
+ return new SwitchChainError$1(value.errorMessage);
733
+ case -32003:
734
+ return new TransactionRejectedRpcError(value.errorMessage);
735
+ }
736
+ }
737
+ }
738
+ let stringified = "[Unable to stringify the thrown value]";
739
+ try {
740
+ stringified = JSON.stringify(value);
741
+ } catch {
742
+ // ignoring failed stringify
743
+ }
744
+ return new InternalRpcError(`Invalid value for ProviderRpcError: ${stringified}`);
745
+ }
746
+ function isFunction(value) {
747
+ return typeof value === 'function';
748
+ }
749
+ function createErrorClass(createImpl) {
750
+ var _super = function (instance) {
751
+ Error.call(instance);
752
+ instance.stack = new Error().stack;
753
+ };
754
+ var ctorFunc = createImpl(_super);
755
+ ctorFunc.prototype = Object.create(Error.prototype);
756
+ ctorFunc.prototype.constructor = ctorFunc;
757
+ return ctorFunc;
758
+ }
759
+ var UnsubscriptionError = createErrorClass(function (_super) {
760
+ return function UnsubscriptionErrorImpl(errors) {
761
+ _super(this);
762
+ this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
763
+ return i + 1 + ") " + err.toString();
764
+ }).join('\n ') : '';
765
+ this.name = 'UnsubscriptionError';
766
+ this.errors = errors;
767
+ };
768
+ });
769
+ function arrRemove(arr, item) {
770
+ if (arr) {
771
+ var index = arr.indexOf(item);
772
+ 0 <= index && arr.splice(index, 1);
773
+ }
774
+ }
775
+ var Subscription = function () {
776
+ function Subscription(initialTeardown) {
777
+ this.initialTeardown = initialTeardown;
778
+ this.closed = false;
779
+ this._parentage = null;
780
+ this._finalizers = null;
781
+ }
782
+ Subscription.prototype.unsubscribe = function () {
783
+ var e_1, _a, e_2, _b;
721
784
  var errors;
722
785
  if (!this.closed) {
723
786
  this.closed = true;
@@ -1681,15 +1744,17 @@ _a$2 = ProviderMessageService;
1681
1744
  _ProviderMessageService_instance = {
1682
1745
  value: void 0
1683
1746
  };
1684
- var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService, _AirWalletProvider_isLoggedIn, _AirWalletProvider_ensureWallet, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
1747
+ var _AirWalletProvider_instances, _AirWalletProvider_providerMessageService, _AirWalletProvider_isWalletInitialized, _AirWalletProvider_getLoginResult, _AirWalletProvider_ensureWallet, _AirWalletProvider_eventListeners, _AirWalletProvider_emit;
1685
1748
  class AirWalletProvider {
1686
1749
  constructor({
1687
- isLoggedIn,
1688
- ensureWallet
1750
+ ensureWallet,
1751
+ isWalletInitialized,
1752
+ getLoginResult
1689
1753
  }) {
1690
1754
  _AirWalletProvider_instances.add(this);
1691
1755
  _AirWalletProvider_providerMessageService.set(this, void 0);
1692
- _AirWalletProvider_isLoggedIn.set(this, void 0);
1756
+ _AirWalletProvider_isWalletInitialized.set(this, void 0);
1757
+ _AirWalletProvider_getLoginResult.set(this, void 0);
1693
1758
  _AirWalletProvider_ensureWallet.set(this, void 0);
1694
1759
  _AirWalletProvider_eventListeners.set(this, void 0);
1695
1760
  this.startEventMessageListening = async walletIframe => {
@@ -1699,7 +1764,6 @@ class AirWalletProvider {
1699
1764
  });
1700
1765
  };
1701
1766
  __classPrivateFieldSet(this, _AirWalletProvider_providerMessageService, ProviderMessageService.create());
1702
- __classPrivateFieldSet(this, _AirWalletProvider_isLoggedIn, isLoggedIn);
1703
1767
  __classPrivateFieldSet(this, _AirWalletProvider_ensureWallet, ensureWallet);
1704
1768
  __classPrivateFieldSet(this, _AirWalletProvider_eventListeners, {
1705
1769
  connect: [],
@@ -1708,6 +1772,8 @@ class AirWalletProvider {
1708
1772
  chainChanged: [],
1709
1773
  message: []
1710
1774
  });
1775
+ __classPrivateFieldSet(this, _AirWalletProvider_isWalletInitialized, isWalletInitialized);
1776
+ __classPrivateFieldSet(this, _AirWalletProvider_getLoginResult, getLoginResult);
1711
1777
  }
1712
1778
  async request(request) {
1713
1779
  // Check if the request is valid
@@ -1726,11 +1792,14 @@ class AirWalletProvider {
1726
1792
  if (params !== undefined && !Array.isArray(params) && (typeof params !== "object" || params === null)) {
1727
1793
  throw new InvalidParamsRpcError("Invalid params");
1728
1794
  }
1729
- // Check if the user is logged in
1730
- if (!__classPrivateFieldGet$1(this, _AirWalletProvider_isLoggedIn, "f").call(this)) {
1795
+ const loginResult = __classPrivateFieldGet$1(this, _AirWalletProvider_getLoginResult, "f").call(this);
1796
+ if (!loginResult) {
1731
1797
  throw new UnauthorizedProviderError("User is not logged in");
1732
1798
  }
1733
- const skipWalletLoginMethods = ['eth_chainId'];
1799
+ if (method === "eth_accounts" && !__classPrivateFieldGet$1(this, _AirWalletProvider_isWalletInitialized, "f").call(this) && loginResult?.abstractAccountAddress) {
1800
+ return [loginResult.abstractAccountAddress];
1801
+ }
1802
+ const skipWalletLoginMethods = ["eth_chainId"];
1734
1803
  try {
1735
1804
  if (skipWalletLoginMethods.includes(method)) {
1736
1805
  await __classPrivateFieldGet$1(this, _AirWalletProvider_ensureWallet, "f").call(this, {
@@ -1773,7 +1842,7 @@ class AirWalletProvider {
1773
1842
  });
1774
1843
  }
1775
1844
  }
1776
- _AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_isLoggedIn = new WeakMap(), _AirWalletProvider_ensureWallet = new WeakMap(), _AirWalletProvider_eventListeners = new WeakMap(), _AirWalletProvider_instances = new WeakSet(), _AirWalletProvider_emit = function _AirWalletProvider_emit(eventName, ...args) {
1845
+ _AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_isWalletInitialized = new WeakMap(), _AirWalletProvider_getLoginResult = new WeakMap(), _AirWalletProvider_ensureWallet = new WeakMap(), _AirWalletProvider_eventListeners = new WeakMap(), _AirWalletProvider_instances = new WeakSet(), _AirWalletProvider_emit = function _AirWalletProvider_emit(eventName, ...args) {
1777
1846
  (__classPrivateFieldGet$1(this, _AirWalletProvider_eventListeners, "f")[eventName] || []).forEach(listener => {
1778
1847
  try {
1779
1848
  return listener(...args);
@@ -1782,274 +1851,8 @@ _AirWalletProvider_providerMessageService = new WeakMap(), _AirWalletProvider_is
1782
1851
  }
1783
1852
  });
1784
1853
  };
1785
- class IframeController {
1786
- constructor(iframeUrl, iframeId, state) {
1787
- this._iframeElement = null;
1788
- this.state = {
1789
- ...IframeController.defaultState,
1790
- ...state
1791
- };
1792
- this.iframeUrl = iframeUrl;
1793
- this.iframeId = iframeId;
1794
- }
1795
- get iframeElement() {
1796
- return this._iframeElement;
1797
- }
1798
- createIframe() {
1799
- if (this._iframeElement) return this._iframeElement;
1800
- const iframe = document.createElement("iframe");
1801
- iframe.id = this.iframeId;
1802
- iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
1803
- iframe.src = this.iframeUrl;
1804
- iframe.style.position = "fixed";
1805
- iframe.style.zIndex = "999999";
1806
- iframe.style.border = "none";
1807
- iframe.style.margin = "0";
1808
- iframe.style.padding = "0";
1809
- iframe.style.display = "none";
1810
- iframe.style.colorScheme = "auto";
1811
- document.body.appendChild(iframe);
1812
- this._iframeElement = iframe;
1813
- return iframe;
1814
- }
1815
- setIframeVisibility(isVisible) {
1816
- this.state.isVisible = isVisible;
1817
- }
1818
- updateIframeState() {
1819
- if (!this.iframeElement) return;
1820
- const style = {};
1821
- style.display = this.state.isVisible ? "block" : "none";
1822
- style.width = "100%";
1823
- style.height = "100%";
1824
- style.top = "0px";
1825
- style.right = "0px";
1826
- style.left = "0px";
1827
- style.bottom = "0px";
1828
- Object.assign(this.iframeElement.style, style);
1829
- }
1830
- destroy() {
1831
- if (this.iframeElement) {
1832
- this.iframeElement.remove();
1833
- this._iframeElement = null;
1834
- }
1835
- }
1836
- postMessage(message) {
1837
- if (!this.iframeElement) return;
1838
- const {
1839
- origin
1840
- } = new URL(this.iframeElement.src);
1841
- this.iframeElement.contentWindow.postMessage(message, origin);
1842
- }
1843
- }
1844
- IframeController.defaultState = {
1845
- isVisible: false
1846
- };
1847
- class WindowController {
1848
- get messages$() {
1849
- return this._messages$.asObservable();
1850
- }
1851
- constructor(windowId, windowUrl) {
1852
- this._windowInstance = null;
1853
- this._messageHandler = null;
1854
- this._messages$ = new Subject();
1855
- this.windowId = windowId;
1856
- this.windowUrl = windowUrl;
1857
- this.windowOrigin = new URL(windowUrl).origin;
1858
- this._messageHandler = ev => {
1859
- if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
1860
- return;
1861
- }
1862
- this._messages$.next(ev);
1863
- };
1864
- window.addEventListener("message", this._messageHandler);
1865
- }
1866
- get windowInstance() {
1867
- return this._windowInstance;
1868
- }
1869
- async openWindow(onRetry) {
1870
- let windowInstance = this.tryOpenWindow();
1871
- if (!windowInstance) {
1872
- await onRetry();
1873
- windowInstance = this.tryOpenWindow();
1874
- if (!windowInstance) {
1875
- throw new AirError(WindowErrorName.WINDOW_BLOCKED);
1876
- }
1877
- }
1878
- const pendingWindowOpenCheck = new Promise((resolve, reject) => {
1879
- setTimeout(() => {
1880
- if (this.isWindowOpen(windowInstance)) {
1881
- // only now are we scheduling the close event check since we're sure the window is open
1882
- this.scheduleWindowClosedChecks(windowInstance);
1883
- resolve("opened");
1884
- } else {
1885
- onRetry().then(() => {
1886
- windowInstance = this.tryOpenWindow();
1887
- if (windowInstance) {
1888
- this._windowInstance = windowInstance;
1889
- windowInstance.focus();
1890
- this.scheduleWindowClosedChecks(windowInstance);
1891
- resolve("retry");
1892
- } else {
1893
- reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
1894
- }
1895
- }).catch(reject);
1896
- }
1897
- }, 1000);
1898
- });
1899
- this._windowInstance = windowInstance;
1900
- windowInstance.focus();
1901
- return {
1902
- pendingWindowOpenCheck
1903
- };
1904
- }
1905
- postMessage(message, transfer) {
1906
- if (!this._windowInstance) return;
1907
- this._windowInstance.postMessage(message, this.windowOrigin, transfer);
1908
- }
1909
- onMessage(callback) {
1910
- const listener = ev => {
1911
- if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
1912
- callback(ev);
1913
- };
1914
- window.addEventListener("message", listener);
1915
- const close = () => window.removeEventListener("message", listener);
1916
- this.onClose(close);
1917
- return {
1918
- close
1919
- };
1920
- }
1921
- cleanup() {
1922
- if (this._windowInstance && !this._windowInstance.closed) {
1923
- this._windowInstance.close();
1924
- }
1925
- this._windowInstance = null;
1926
- if (this._messageHandler) {
1927
- window.removeEventListener("message", this._messageHandler);
1928
- this._messageHandler = null;
1929
- }
1930
- if (this._messages$ && !this._messages$.closed) {
1931
- this._messages$.complete();
1932
- }
1933
- }
1934
- onClose(callback) {
1935
- return this._messages$.subscribe({
1936
- complete: callback
1937
- });
1938
- }
1939
- isWindowOpen(windowInstance) {
1940
- return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
1941
- }
1942
- tryOpenWindow() {
1943
- const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
1944
- if (this.isWindowOpen(windowInstance)) {
1945
- return windowInstance;
1946
- }
1947
- return null;
1948
- }
1949
- scheduleWindowClosedChecks(windowInstance) {
1950
- const checkWindow = setInterval(() => {
1951
- if (!windowInstance || windowInstance.closed) {
1952
- clearInterval(checkWindow);
1953
- if (windowInstance === this._windowInstance) {
1954
- this.cleanup();
1955
- }
1956
- }
1957
- }, 500);
1958
- }
1959
- }
1960
- class WindowService {
1961
- constructor() {
1962
- this.windowControllers = new Map();
1963
- }
1964
- static get instance() {
1965
- return this._instance || (this._instance = new this());
1966
- }
1967
- async sendWindowInitializationRequest(windowId, payload, port) {
1968
- const windowController = this.windowControllers.get(windowId);
1969
- if (!windowController) {
1970
- throw new Error("Window controller not found");
1971
- }
1972
- const windowInstance = windowController.windowInstance;
1973
- if (!windowInstance) {
1974
- throw new Error("Window instance not found");
1975
- }
1976
- const response = firstValueFrom(windowController.messages$.pipe(filter(event => event.data.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
1977
- windowController.postMessage({
1978
- type: AirWalletMessageTypes.INITIALIZATION_REQUEST,
1979
- payload
1980
- }, [port]);
1981
- return (await response).data;
1982
- }
1983
- async openAndInitializeWalletServiceWindow({
1984
- url,
1985
- windowId,
1986
- partnerId,
1987
- enableLogging,
1988
- onRetry,
1989
- sdkVersion,
1990
- enableAutomation
1991
- }) {
1992
- if (this.windowControllers.has(windowId)) {
1993
- throw new Error("Window controller already exists");
1994
- }
1995
- const windowController = new WindowController(windowId, url);
1996
- const {
1997
- pendingWindowOpenCheck
1998
- } = await windowController.openWindow(onRetry);
1999
- windowController.onClose(() => {
2000
- this.removeWindowController(windowId);
2001
- });
2002
- this.windowControllers.set(windowId, windowController);
2003
- let channel = null;
2004
- const initializeWindow = () => {
2005
- return new Promise((resolve, reject) => {
2006
- windowController.onMessage(async ev => {
2007
- if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
2008
- try {
2009
- channel = new MessageChannel();
2010
- const {
2011
- payload
2012
- } = await this.sendWindowInitializationRequest(windowId, {
2013
- partnerId,
2014
- enableLogging,
2015
- sdkVersion,
2016
- enableAutomation
2017
- }, channel.port1);
2018
- if (payload.success === false) {
2019
- reject(new AirServiceError(payload.errorName, payload.errorMessage));
2020
- } else {
2021
- resolve();
2022
- }
2023
- } catch (e) {
2024
- reject(e);
2025
- }
2026
- }
2027
- });
2028
- });
2029
- };
2030
- const initializeWindowPromise = initializeWindow();
2031
- const result = await pendingWindowOpenCheck;
2032
- if (result === "retry") {
2033
- // we can ignore previous initialization attempt since a new window was opened
2034
- await initializeWindow();
2035
- } else {
2036
- await initializeWindowPromise;
2037
- }
2038
- return {
2039
- windowController,
2040
- port: channel.port2
2041
- };
2042
- }
2043
- getWindowController(windowId) {
2044
- return this.windowControllers.get(windowId);
2045
- }
2046
- removeWindowController(windowId) {
2047
- this.windowControllers.delete(windowId);
2048
- }
2049
- }
2050
- var WindowService$1 = WindowService.instance;
2051
1854
  var _a$1, _AuthMessageService_instance;
2052
- const ALLOWED_AUTH_MESSAGES = [AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.SETUP_WALLET_REQUEST, 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];
1855
+ 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];
2053
1856
  class AuthMessageService extends MessageServiceBase {
2054
1857
  static create() {
2055
1858
  if (__classPrivateFieldGet$1(this, _a$1, "f", _AuthMessageService_instance)) throw new Error("AuthMessageService already created");
@@ -2118,6 +1921,34 @@ class AuthMessageService extends MessageServiceBase {
2118
1921
  async sendSetupWalletErrorResponse(error) {
2119
1922
  await this.sendMessage(this.createErrorResponseMessage(AirAuthMessageTypes.SETUP_WALLET_RESPONSE, error));
2120
1923
  }
1924
+ async initRecoveryCommunication() {
1925
+ await this.sendMessage({
1926
+ type: AirAuthMessageTypes.INIT_RECOVERY_COMMUNICATION
1927
+ });
1928
+ }
1929
+ async resetRecoveryCommunication() {
1930
+ await this.sendMessage({
1931
+ type: AirAuthMessageTypes.RESET_RECOVERY_COMMUNICATION
1932
+ });
1933
+ }
1934
+ async sendSetupRecoverySuccessResponse() {
1935
+ await this.sendMessage({
1936
+ type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
1937
+ payload: {
1938
+ success: true
1939
+ }
1940
+ });
1941
+ }
1942
+ async sendSetupRecoveryErrorResponse(error) {
1943
+ await this.sendMessage({
1944
+ type: AirAuthMessageTypes.SETUP_RECOVERY_RESPONSE,
1945
+ payload: {
1946
+ success: false,
1947
+ errorName: error instanceof AirError ? error.name : "UNKNOWN_ERROR",
1948
+ errorMessage: error.message
1949
+ }
1950
+ });
1951
+ }
2121
1952
  async sendCrossPartnerTokenRequest(targetPartnerUrl) {
2122
1953
  const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CROSS_PARTNER_TOKEN_RESPONSE)));
2123
1954
  await this.sendMessage({
@@ -2135,6 +1966,14 @@ class AuthMessageService extends MessageServiceBase {
2135
1966
  });
2136
1967
  return response;
2137
1968
  }
1969
+ async sendAccountRecoveryRequest(payload) {
1970
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.START_RECOVERY_RESPONSE)));
1971
+ await this.sendMessage({
1972
+ type: AirAuthMessageTypes.START_RECOVERY_REQUEST,
1973
+ payload
1974
+ });
1975
+ return response;
1976
+ }
2138
1977
  async sendCredentialSaltRequest() {
2139
1978
  const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirAuthMessageTypes.CREDENTIAL_SALT_RESPONSE)));
2140
1979
  await this.sendMessage({
@@ -2147,8 +1986,113 @@ _a$1 = AuthMessageService;
2147
1986
  _AuthMessageService_instance = {
2148
1987
  value: void 0
2149
1988
  };
1989
+ class IframeController {
1990
+ constructor(iframeUrl, iframeId, state) {
1991
+ this._iframeElement = null;
1992
+ this.AUTH_IFRAME_Z_INDEX = "9999999";
1993
+ this.DEFAULT_IFRAME_Z_INDEX = "999999";
1994
+ this.state = {
1995
+ ...IframeController.defaultState,
1996
+ ...state
1997
+ };
1998
+ this.iframeUrl = iframeUrl;
1999
+ this.iframeId = iframeId;
2000
+ }
2001
+ get iframeElement() {
2002
+ return this._iframeElement;
2003
+ }
2004
+ createIframe() {
2005
+ if (this._iframeElement) return this._iframeElement;
2006
+ const iframe = document.createElement("iframe");
2007
+ iframe.id = this.iframeId;
2008
+ iframe.allow = "publickey-credentials-get *; publickey-credentials-create *";
2009
+ iframe.src = this.iframeUrl;
2010
+ iframe.style.position = "fixed";
2011
+ iframe.style.zIndex = this.iframeUrl.includes("auth") ? this.AUTH_IFRAME_Z_INDEX : this.DEFAULT_IFRAME_Z_INDEX;
2012
+ iframe.style.border = "none";
2013
+ iframe.style.margin = "0";
2014
+ iframe.style.padding = "0";
2015
+ iframe.style.display = "none";
2016
+ iframe.style.colorScheme = "auto";
2017
+ document.body.appendChild(iframe);
2018
+ this._iframeElement = iframe;
2019
+ return iframe;
2020
+ }
2021
+ setIframeVisibility(isVisible) {
2022
+ this.state.isVisible = isVisible;
2023
+ }
2024
+ updateIframeState() {
2025
+ if (!this.iframeElement) return;
2026
+ const style = {};
2027
+ style.display = this.state.isVisible ? "block" : "none";
2028
+ style.width = "100%";
2029
+ style.height = "100%";
2030
+ style.top = "0px";
2031
+ style.right = "0px";
2032
+ style.left = "0px";
2033
+ style.bottom = "0px";
2034
+ Object.assign(this.iframeElement.style, style);
2035
+ }
2036
+ destroy() {
2037
+ if (this.iframeElement) {
2038
+ this.iframeElement.remove();
2039
+ this._iframeElement = null;
2040
+ }
2041
+ }
2042
+ postMessage(message) {
2043
+ if (!this.iframeElement) return;
2044
+ const {
2045
+ origin
2046
+ } = new URL(this.iframeElement.src);
2047
+ this.iframeElement.contentWindow.postMessage(message, origin);
2048
+ }
2049
+ }
2050
+ IframeController.defaultState = {
2051
+ isVisible: false
2052
+ };
2053
+ const ALLOWED_RECOVERY_MESSAGES = Object.values(AirRecoveryMessageTypes);
2054
+ class RecoveryMessageService extends MessageServiceBase {
2055
+ static create() {
2056
+ if (!RecoveryMessageService._instance) {
2057
+ RecoveryMessageService._instance = new RecoveryMessageService("Recovery Service", ALLOWED_RECOVERY_MESSAGES);
2058
+ }
2059
+ return RecoveryMessageService._instance;
2060
+ }
2061
+ async sendInitializationRequest(payload) {
2062
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.INITIALIZATION_RESPONSE)));
2063
+ await this.sendMessage({
2064
+ type: AirRecoveryMessageTypes.INITIALIZATION_REQUEST,
2065
+ payload
2066
+ });
2067
+ return response;
2068
+ }
2069
+ async initAuthCommunication() {
2070
+ await this.sendMessage({
2071
+ type: AirRecoveryMessageTypes.INIT_AUTH_COMMUNICATION
2072
+ });
2073
+ }
2074
+ async onInitialized() {
2075
+ return firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.RECOVERY_INITIALIZED)));
2076
+ }
2077
+ async logout() {
2078
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirRecoveryMessageTypes.LOGOUT_RESPONSE)));
2079
+ await this.sendMessage({
2080
+ type: AirRecoveryMessageTypes.LOGOUT_REQUEST
2081
+ });
2082
+ return response;
2083
+ }
2084
+ async open(element) {
2085
+ await this._open({
2086
+ window: element.contentWindow,
2087
+ origin: new URL(element.src).origin
2088
+ });
2089
+ }
2090
+ async close() {
2091
+ await super.close();
2092
+ }
2093
+ }
2150
2094
  var _a, _WalletMessageService_instance;
2151
- const ALLOWED_WALLET_MESSAGES = [AirWalletMessageTypes.INITIALIZATION_RESPONSE, AirWalletMessageTypes.WALLET_INITIALIZED, AirWalletMessageTypes.WALLET_LOGIN_RESPONSE, AirWalletMessageTypes.SETUP_OR_UPDATE_MFA_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, AirWalletMessageTypes.OPEN_WINDOW_REQUEST, AirWalletMessageTypes.OPEN_WINDOW_RETRY_RESPONSE];
2095
+ 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.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];
2152
2096
  class WalletMessageService extends MessageServiceBase {
2153
2097
  static create() {
2154
2098
  if (__classPrivateFieldGet$1(this, _a, "f", _WalletMessageService_instance)) throw new Error("WalletMessageService already created");
@@ -2219,7 +2163,7 @@ class WalletMessageService extends MessageServiceBase {
2219
2163
  }
2220
2164
  async sendOpenWindowSuccessResponse(windowId, port) {
2221
2165
  await this.sendMessage({
2222
- type: AirWalletMessageTypes.OPEN_WINDOW_RESPONSE,
2166
+ type: AirWindowMessageTypes.OPEN_WINDOW_RESPONSE,
2223
2167
  payload: {
2224
2168
  success: true,
2225
2169
  windowId
@@ -2227,7 +2171,7 @@ class WalletMessageService extends MessageServiceBase {
2227
2171
  }, [port]);
2228
2172
  }
2229
2173
  async sendOpenWindowErrorResponse(windowId, error) {
2230
- const errorResponse = this.createErrorResponseMessage(AirWalletMessageTypes.OPEN_WINDOW_RESPONSE, error);
2174
+ const errorResponse = this.createErrorResponseMessage(AirWindowMessageTypes.OPEN_WINDOW_RESPONSE, error);
2231
2175
  await this.sendMessage({
2232
2176
  ...errorResponse,
2233
2177
  payload: {
@@ -2237,9 +2181,9 @@ class WalletMessageService extends MessageServiceBase {
2237
2181
  });
2238
2182
  }
2239
2183
  async sendOpenWindowRetryRequest(windowId) {
2240
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.OPEN_WINDOW_RETRY_RESPONSE), filter(msg => msg.payload.windowId === windowId)));
2184
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWindowMessageTypes.OPEN_WINDOW_RETRY_RESPONSE), filter(msg => msg.payload.windowId === windowId)));
2241
2185
  await this.sendMessage({
2242
- type: AirWalletMessageTypes.OPEN_WINDOW_RETRY_REQUEST,
2186
+ type: AirWindowMessageTypes.OPEN_WINDOW_RETRY_REQUEST,
2243
2187
  payload: {
2244
2188
  windowId
2245
2189
  }
@@ -2248,52 +2192,237 @@ class WalletMessageService extends MessageServiceBase {
2248
2192
  }
2249
2193
  async sendWindowClosed(windowId) {
2250
2194
  await this.sendMessage({
2251
- type: AirWalletMessageTypes.WINDOW_CLOSED,
2195
+ type: AirWindowMessageTypes.WINDOW_CLOSED,
2252
2196
  payload: {
2253
2197
  windowId
2254
2198
  }
2255
- });
2199
+ });
2200
+ }
2201
+ async sendClaimIdRequest(payload) {
2202
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.CLAIM_ID_RESPONSE)));
2203
+ await this.sendMessage({
2204
+ type: AirWalletMessageTypes.CLAIM_ID_REQUEST,
2205
+ payload
2206
+ });
2207
+ return response;
2208
+ }
2209
+ async sendShowSwapUIRequest() {
2210
+ const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.SHOW_SWAP_UI_RESPONSE)));
2211
+ await this.sendMessage({
2212
+ type: AirWalletMessageTypes.SHOW_SWAP_UI_REQUEST
2213
+ });
2214
+ return response;
2215
+ }
2216
+ }
2217
+ _a = WalletMessageService;
2218
+ _WalletMessageService_instance = {
2219
+ value: void 0
2220
+ };
2221
+ class WindowController {
2222
+ get messages$() {
2223
+ return this._messages$.asObservable();
2224
+ }
2225
+ constructor(windowId, windowUrl) {
2226
+ this._windowInstance = null;
2227
+ this._messageHandler = null;
2228
+ this._messages$ = new Subject();
2229
+ this.windowId = windowId;
2230
+ this.windowUrl = windowUrl;
2231
+ this.windowOrigin = new URL(windowUrl).origin;
2232
+ this._messageHandler = ev => {
2233
+ if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin || !ev.data || !(ev.data instanceof Object)) {
2234
+ return;
2235
+ }
2236
+ this._messages$.next(ev);
2237
+ };
2238
+ window.addEventListener("message", this._messageHandler);
2239
+ }
2240
+ get windowInstance() {
2241
+ return this._windowInstance;
2242
+ }
2243
+ async openWindow(onRetry) {
2244
+ let windowInstance = this.tryOpenWindow();
2245
+ if (!windowInstance) {
2246
+ await onRetry();
2247
+ windowInstance = this.tryOpenWindow();
2248
+ if (!windowInstance) {
2249
+ throw new AirError(WindowErrorName.WINDOW_BLOCKED);
2250
+ }
2251
+ }
2252
+ const pendingWindowOpenCheck = new Promise((resolve, reject) => {
2253
+ setTimeout(() => {
2254
+ if (this.isWindowOpen(windowInstance)) {
2255
+ // only now are we scheduling the close event check since we're sure the window is open
2256
+ this.scheduleWindowClosedChecks(windowInstance);
2257
+ resolve("opened");
2258
+ } else {
2259
+ onRetry().then(() => {
2260
+ windowInstance = this.tryOpenWindow();
2261
+ if (windowInstance) {
2262
+ this._windowInstance = windowInstance;
2263
+ windowInstance.focus();
2264
+ this.scheduleWindowClosedChecks(windowInstance);
2265
+ resolve("retry");
2266
+ } else {
2267
+ reject(new AirError(WindowErrorName.WINDOW_BLOCKED));
2268
+ }
2269
+ }).catch(reject);
2270
+ }
2271
+ }, 1000);
2272
+ });
2273
+ this._windowInstance = windowInstance;
2274
+ windowInstance.focus();
2275
+ return {
2276
+ pendingWindowOpenCheck
2277
+ };
2278
+ }
2279
+ postMessage(message, transfer) {
2280
+ if (!this._windowInstance) return;
2281
+ this._windowInstance.postMessage(message, this.windowOrigin, transfer);
2282
+ }
2283
+ onMessage(callback) {
2284
+ const listener = ev => {
2285
+ if (ev.source !== this._windowInstance || ev.origin !== this.windowOrigin) return;
2286
+ callback(ev);
2287
+ };
2288
+ window.addEventListener("message", listener);
2289
+ const close = () => window.removeEventListener("message", listener);
2290
+ this.onClose(close);
2291
+ return {
2292
+ close
2293
+ };
2294
+ }
2295
+ cleanup() {
2296
+ if (this._windowInstance && !this._windowInstance.closed) {
2297
+ this._windowInstance.close();
2298
+ }
2299
+ this._windowInstance = null;
2300
+ if (this._messageHandler) {
2301
+ window.removeEventListener("message", this._messageHandler);
2302
+ this._messageHandler = null;
2303
+ }
2304
+ if (this._messages$ && !this._messages$.closed) {
2305
+ this._messages$.complete();
2306
+ }
2307
+ }
2308
+ onClose(callback) {
2309
+ return this._messages$.subscribe({
2310
+ complete: callback
2311
+ });
2312
+ }
2313
+ isWindowOpen(windowInstance) {
2314
+ return !(!windowInstance || windowInstance.closed || typeof windowInstance.closed == "undefined");
2315
+ }
2316
+ tryOpenWindow() {
2317
+ const windowInstance = window.open(this.windowUrl, this.windowId, getWindowFeatures(425, 680));
2318
+ if (this.isWindowOpen(windowInstance)) {
2319
+ return windowInstance;
2320
+ }
2321
+ return null;
2322
+ }
2323
+ scheduleWindowClosedChecks(windowInstance) {
2324
+ const checkWindow = setInterval(() => {
2325
+ if (!windowInstance || windowInstance.closed) {
2326
+ clearInterval(checkWindow);
2327
+ if (windowInstance === this._windowInstance) {
2328
+ this.cleanup();
2329
+ }
2330
+ }
2331
+ }, 500);
2256
2332
  }
2257
- async sendClaimIdRequest(payload) {
2258
- const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirWalletMessageTypes.CLAIM_ID_RESPONSE)));
2259
- await this.sendMessage({
2260
- type: AirWalletMessageTypes.CLAIM_ID_REQUEST,
2333
+ }
2334
+ class WindowService {
2335
+ constructor() {
2336
+ this.windowControllers = new Map();
2337
+ }
2338
+ static get instance() {
2339
+ return this._instance || (this._instance = new this());
2340
+ }
2341
+ async sendWindowInitializationRequest(windowId, payload, port) {
2342
+ const windowController = this.windowControllers.get(windowId);
2343
+ if (!windowController) {
2344
+ throw new Error("Window controller not found");
2345
+ }
2346
+ const windowInstance = windowController.windowInstance;
2347
+ if (!windowInstance) {
2348
+ throw new Error("Window instance not found");
2349
+ }
2350
+ const response = firstValueFrom(windowController.messages$.pipe(filter(event => event.data.type === AirWalletMessageTypes.INITIALIZATION_RESPONSE)));
2351
+ windowController.postMessage({
2352
+ type: AirWalletMessageTypes.INITIALIZATION_REQUEST,
2261
2353
  payload
2354
+ }, [port]);
2355
+ return (await response).data;
2356
+ }
2357
+ async openAndInitializeWalletServiceWindow({
2358
+ url,
2359
+ windowId,
2360
+ partnerId,
2361
+ enableLogging,
2362
+ onRetry,
2363
+ sdkVersion,
2364
+ enableAutomation
2365
+ }) {
2366
+ if (this.windowControllers.has(windowId)) {
2367
+ throw new Error("Window controller already exists");
2368
+ }
2369
+ const windowController = new WindowController(windowId, url);
2370
+ const {
2371
+ pendingWindowOpenCheck
2372
+ } = await windowController.openWindow(onRetry);
2373
+ windowController.onClose(() => {
2374
+ this.removeWindowController(windowId);
2262
2375
  });
2263
- return response;
2376
+ this.windowControllers.set(windowId, windowController);
2377
+ let channel = null;
2378
+ const initializeWindow = () => {
2379
+ return new Promise((resolve, reject) => {
2380
+ windowController.onMessage(async ev => {
2381
+ if (ev.data === AirWalletMessageTypes.SERVICE_STARTED) {
2382
+ try {
2383
+ channel = new MessageChannel();
2384
+ const {
2385
+ payload
2386
+ } = await this.sendWindowInitializationRequest(windowId, {
2387
+ partnerId,
2388
+ enableLogging,
2389
+ sdkVersion,
2390
+ enableAutomation
2391
+ }, channel.port1);
2392
+ if (payload.success === false) {
2393
+ reject(new AirServiceError(payload.errorName, payload.errorMessage));
2394
+ } else {
2395
+ resolve();
2396
+ }
2397
+ } catch (e) {
2398
+ reject(e);
2399
+ }
2400
+ }
2401
+ });
2402
+ });
2403
+ };
2404
+ const initializeWindowPromise = initializeWindow();
2405
+ const result = await pendingWindowOpenCheck;
2406
+ if (result === "retry") {
2407
+ // we can ignore previous initialization attempt since a new window was opened
2408
+ await initializeWindow();
2409
+ } else {
2410
+ await initializeWindowPromise;
2411
+ }
2412
+ return {
2413
+ windowController,
2414
+ port: channel.port2
2415
+ };
2264
2416
  }
2265
- }
2266
- _a = WalletMessageService;
2267
- _WalletMessageService_instance = {
2268
- value: void 0
2269
- };
2270
- const getLevelName = levelNum => {
2271
- const levelNames = Object.keys(log$1.levels);
2272
- if (levelNum >= 0 && levelNum < levelNames.length) {
2273
- return levelNames[levelNum];
2417
+ getWindowController(windowId) {
2418
+ return this.windowControllers.get(windowId);
2274
2419
  }
2275
- return "UNKNOWN";
2276
- };
2277
- const configureLogLevel = (environment, enableLogging) => {
2278
- let level = log$1.levels.ERROR;
2279
- if (environment === "development") {
2280
- level = enableLogging ? log$1.levels.TRACE : log$1.levels.INFO;
2281
- } else if (environment === "staging") {
2282
- level = enableLogging ? log$1.levels.DEBUG : log$1.levels.INFO;
2283
- } else if (environment === "uat") {
2284
- level = enableLogging ? log$1.levels.INFO : log$1.levels.WARN;
2285
- } else if (environment === "production") {
2286
- // Be cautious with enabling more than WARN in prod
2287
- level = enableLogging ? log$1.levels.WARN : log$1.levels.ERROR;
2420
+ removeWindowController(windowId) {
2421
+ this.windowControllers.delete(windowId);
2288
2422
  }
2289
- log$1.setLevel(level);
2290
- log$1.info(`[${window?.location?.href}] LogLevel: ${getLevelName(log$1.getLevel())}`);
2291
- };
2292
- var version$2 = "1.3.0";
2293
- var airkitPackage = {
2294
- version: version$2
2295
- };
2296
- 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_ensureWallet, _AirService_initializeWallet, _AirService_subscribeToWalletEvents, _AirService_triggerEventListeners, _AirService_triggerAirAuthInitialized, _AirService_triggerAirAuthLoggedIn, _AirService_triggerAirAuthLoggedOut, _AirService_triggerWalletInitialized, _AirService_createLoginResult, _AirService_createWalletInitializedResult, _AirService_cleanUpAuth, _AirService_cleanUpWallet;
2423
+ }
2424
+ var WindowService$1 = WindowService.instance;
2425
+ 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;
2297
2426
  const airKitVersion = airkitPackage.version;
2298
2427
  class AirService {
2299
2428
  constructor({
@@ -2314,12 +2443,17 @@ class AirService {
2314
2443
  _AirService_walletInitialization.set(this, void 0);
2315
2444
  _AirService_walletLoggedInResult.set(this, void 0);
2316
2445
  _AirService_airWalletProvider.set(this, void 0);
2446
+ _AirService_recoveryInitialization.set(this, void 0);
2447
+ _AirService_recoveryMessagingService.set(this, void 0);
2448
+ _AirService_recoveryIframeController.set(this, void 0);
2317
2449
  __classPrivateFieldSet(this, _AirService_partnerId, partnerId);
2318
2450
  __classPrivateFieldSet(this, _AirService_authMessagingService, AuthMessageService.create());
2319
2451
  __classPrivateFieldSet(this, _AirService_walletMessagingService, WalletMessageService.create());
2452
+ __classPrivateFieldSet(this, _AirService_recoveryMessagingService, RecoveryMessageService.create());
2320
2453
  __classPrivateFieldSet(this, _AirService_airWalletProvider, new AirWalletProvider({
2321
- isLoggedIn: () => this.isLoggedIn,
2322
- ensureWallet: __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this)
2454
+ isWalletInitialized: () => this.isWalletInitialized,
2455
+ ensureWallet: __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).bind(this),
2456
+ getLoginResult: () => __classPrivateFieldGet$1(this, _AirService_loginResult, "f")
2323
2457
  }));
2324
2458
  // this.#modalZIndex = modalZIndex ?? 99999;
2325
2459
  }
@@ -2332,6 +2466,9 @@ class AirService {
2332
2466
  get isLoggedIn() {
2333
2467
  return !!__classPrivateFieldGet$1(this, _AirService_loginResult, "f");
2334
2468
  }
2469
+ get loginResult() {
2470
+ return __classPrivateFieldGet$1(this, _AirService_loginResult, "f");
2471
+ }
2335
2472
  get isWalletInitialized() {
2336
2473
  return !!__classPrivateFieldGet$1(this, _AirService_walletLoggedInResult, "f");
2337
2474
  }
@@ -2387,6 +2524,17 @@ class AirService {
2387
2524
  }
2388
2525
  break;
2389
2526
  }
2527
+ case AirAuthMessageTypes.SETUP_RECOVERY_REQUEST:
2528
+ {
2529
+ try {
2530
+ await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureRecovery).call(this);
2531
+ await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendSetupRecoverySuccessResponse();
2532
+ } catch (err) {
2533
+ const error = ensureError(err);
2534
+ await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendSetupRecoveryErrorResponse(error);
2535
+ }
2536
+ break;
2537
+ }
2390
2538
  }
2391
2539
  });
2392
2540
  const result = await new Promise((resolve, reject) => {
@@ -2529,6 +2677,16 @@ class AirService {
2529
2677
  }
2530
2678
  throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2531
2679
  }
2680
+ async showSwapUI() {
2681
+ await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_ensureWallet).call(this);
2682
+ const result = await __classPrivateFieldGet$1(this, _AirService_walletMessagingService, "f").sendShowSwapUIRequest();
2683
+ if (result.payload.success === false) {
2684
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2685
+ }
2686
+ return {
2687
+ txHash: result.payload.txHash
2688
+ };
2689
+ }
2532
2690
  async getUserInfo() {
2533
2691
  if (!this.isLoggedIn) throw new Error("User not logged in");
2534
2692
  const info = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendPartnerUserInfoRequest();
@@ -2558,6 +2716,16 @@ class AirService {
2558
2716
  urlWithToken: result.payload.urlWithToken
2559
2717
  };
2560
2718
  }
2719
+ async startRecovery(payload) {
2720
+ try {
2721
+ const result = await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").sendAccountRecoveryRequest(payload);
2722
+ if (result.payload.success === false) {
2723
+ throw new AirServiceError(result.payload.errorName, result.payload.errorMessage);
2724
+ }
2725
+ } catch (error) {
2726
+ throw AirServiceError.from(error);
2727
+ }
2728
+ }
2561
2729
  async getAccessToken() {
2562
2730
  if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) throw new Error("Service is not initialized");
2563
2731
  if (!this.isLoggedIn) throw new Error("No active session to get partner access token");
@@ -2584,6 +2752,7 @@ class AirService {
2584
2752
  async cleanUp() {
2585
2753
  await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpWallet).call(this);
2586
2754
  await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpAuth).call(this);
2755
+ await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
2587
2756
  this.clearEventListeners();
2588
2757
  }
2589
2758
  on(listener) {
@@ -2596,7 +2765,7 @@ class AirService {
2596
2765
  __classPrivateFieldSet(this, _AirService_airAuthListener, []);
2597
2766
  }
2598
2767
  }
2599
- _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_instances = new WeakSet(), _AirService_ensureWallet = async function _AirService_ensureWallet(option) {
2768
+ _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) {
2600
2769
  if (!this.isInitialized) throw new Error("Service not initialized");
2601
2770
  if (!this.isLoggedIn && !option?.skipWalletLogin) throw new Error("User not logged in");
2602
2771
  if (!__classPrivateFieldGet$1(this, _AirService_walletInitialization, "f")) __classPrivateFieldSet(this, _AirService_walletInitialization, __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_initializeWallet).call(this, option));
@@ -2688,7 +2857,7 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2688
2857
  }
2689
2858
  break;
2690
2859
  }
2691
- case AirWalletMessageTypes.OPEN_WINDOW_REQUEST:
2860
+ case AirWindowMessageTypes.OPEN_WINDOW_REQUEST:
2692
2861
  {
2693
2862
  try {
2694
2863
  const onRetry = async () => {
@@ -2792,9 +2961,96 @@ _AirService_loginResult = new WeakMap(), _AirService_buildEnv = new WeakMap(), _
2792
2961
  await __classPrivateFieldGet$1(this, _AirService_walletMessagingService, "f").close();
2793
2962
  __classPrivateFieldSet(this, _AirService_walletLoggedInResult, undefined);
2794
2963
  __classPrivateFieldSet(this, _AirService_walletInitialization, undefined);
2964
+ }, _AirService_ensureRecovery = async function _AirService_ensureRecovery() {
2965
+ if (!this.isInitialized) throw new Error("Service not initialized");
2966
+ if (!__classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f")) {
2967
+ __classPrivateFieldSet(this, _AirService_recoveryInitialization, __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_initializeRecovery).call(this));
2968
+ }
2969
+ try {
2970
+ await __classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f");
2971
+ } catch (error) {
2972
+ __classPrivateFieldSet(this, _AirService_recoveryInitialization, null);
2973
+ log$1.error("Error initializing recovery", error);
2974
+ throw error;
2975
+ }
2976
+ }, _AirService_initializeRecovery = async function _AirService_initializeRecovery() {
2977
+ if (__classPrivateFieldGet$1(this, _AirService_recoveryInitialization, "f")) throw new Error("Already initializing");
2978
+ const {
2979
+ recoveryUrl
2980
+ } = AIR_URLS[__classPrivateFieldGet$1(this, _AirService_buildEnv, "f")];
2981
+ const recoveryIframeOrigin = new URL(recoveryUrl).origin;
2982
+ try {
2983
+ const recoveryInitRequestPromise = new Promise((resolve, reject) => {
2984
+ const handleRecoveryMessage = async ev => {
2985
+ if (ev.origin !== recoveryIframeOrigin) return;
2986
+ if (ev.data === AirRecoveryMessageTypes.SERVICE_STARTED) {
2987
+ window.removeEventListener("message", handleRecoveryMessage);
2988
+ const {
2989
+ payload
2990
+ } = await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").sendInitializationRequest({
2991
+ partnerId: __classPrivateFieldGet$1(this, _AirService_partnerId, "f"),
2992
+ enableLogging: __classPrivateFieldGet$1(this, _AirService_enableLogging, "f"),
2993
+ sdkVersion: airKitVersion,
2994
+ enableAutomation: this.shouldEnableAutomation()
2995
+ });
2996
+ if (payload.success === true) {
2997
+ resolve();
2998
+ } else {
2999
+ reject(new AirServiceError(payload.errorName, payload.errorMessage));
3000
+ }
3001
+ }
3002
+ };
3003
+ window.addEventListener("message", handleRecoveryMessage);
3004
+ });
3005
+ __classPrivateFieldSet(this, _AirService_recoveryIframeController, new IframeController(recoveryUrl, `air-recovery-${randomId()}`), "f");
3006
+ __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").createIframe();
3007
+ log$1.info(recoveryUrl, "url loaded");
3008
+ await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").open(__classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").iframeElement);
3009
+ __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_subscribeToRecoveryEvents).call(this);
3010
+ const recoveryInitPromise = __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").onInitialized();
3011
+ await recoveryInitRequestPromise;
3012
+ await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").initRecoveryCommunication();
3013
+ await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").initAuthCommunication();
3014
+ const recoveryInitResult = await recoveryInitPromise;
3015
+ if (recoveryInitResult.payload.success !== true) {
3016
+ throw new AirServiceError(recoveryInitResult.payload.errorName, recoveryInitResult.payload.errorMessage);
3017
+ }
3018
+ } catch (error) {
3019
+ log$1.error("Error initializing recovery", error);
3020
+ await __classPrivateFieldGet$1(this, _AirService_instances, "m", _AirService_cleanUpRecovery).call(this);
3021
+ throw error;
3022
+ }
3023
+ }, _AirService_subscribeToRecoveryEvents = function _AirService_subscribeToRecoveryEvents() {
3024
+ __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").messages$.subscribe(async message => {
3025
+ switch (message.type) {
3026
+ case AirRecoveryMessageTypes.RECOVERY_IFRAME_VISIBILITY_REQUEST:
3027
+ {
3028
+ const recoveryIframeController = __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f");
3029
+ recoveryIframeController.setIframeVisibility(message.payload.visible);
3030
+ recoveryIframeController.updateIframeState();
3031
+ break;
3032
+ }
3033
+ }
3034
+ });
3035
+ }, _AirService_cleanUpRecovery = async function _AirService_cleanUpRecovery() {
3036
+ if (!__classPrivateFieldGet$1(this, _AirService_isAuthInitialized, "f")) return;
3037
+ // Logout recovery and destroy the recovery iframe
3038
+ const recoveryIframeElement = __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f")?.iframeElement;
3039
+ if (isElement(recoveryIframeElement) && window.document.body.contains(recoveryIframeElement)) {
3040
+ await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").logout();
3041
+ __classPrivateFieldGet$1(this, _AirService_recoveryIframeController, "f").destroy();
3042
+ __classPrivateFieldSet(this, _AirService_recoveryIframeController, undefined);
3043
+ }
3044
+ const authIframeElement = __classPrivateFieldGet$1(this, _AirService_authIframeController, "f")?.iframeElement;
3045
+ if (isElement(authIframeElement) && window.document.body.contains(authIframeElement)) {
3046
+ await __classPrivateFieldGet$1(this, _AirService_authMessagingService, "f").resetRecoveryCommunication();
3047
+ }
3048
+ // Close the message service
3049
+ await __classPrivateFieldGet$1(this, _AirService_recoveryMessagingService, "f").close();
3050
+ __classPrivateFieldSet(this, _AirService_recoveryInitialization, undefined);
2795
3051
  };
2796
3052
 
2797
- const version$1 = '2.26.5';
3053
+ const version$1 = '2.31.0';
2798
3054
 
2799
3055
  let errorConfig = {
2800
3056
  getDocsUrl: ({
@@ -3259,37 +3515,6 @@ class LruMap extends Map {
3259
3515
  }
3260
3516
  }
3261
3517
 
3262
- /**
3263
- * Internal assertion helpers.
3264
- * @module
3265
- */
3266
- /** Asserts something is positive integer. */
3267
- function anumber(n) {
3268
- if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);
3269
- }
3270
- /** Is number an Uint8Array? Copied from utils for perf. */
3271
- function isBytes(a) {
3272
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array';
3273
- }
3274
- /** Asserts something is Uint8Array. */
3275
- function abytes(b, ...lengths) {
3276
- if (!isBytes(b)) throw new Error('Uint8Array expected');
3277
- if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
3278
- }
3279
- /** Asserts a hash instance has not been destroyed / finished */
3280
- function aexists(instance, checkFinished = true) {
3281
- if (instance.destroyed) throw new Error('Hash instance has been destroyed');
3282
- if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
3283
- }
3284
- /** Asserts output is properly-sized byte array */
3285
- function aoutput(out, instance) {
3286
- abytes(out);
3287
- const min = instance.outputLen;
3288
- if (out.length < min) {
3289
- throw new Error('digestInto() expects output buffer of length at least ' + min);
3290
- }
3291
- }
3292
-
3293
3518
  /**
3294
3519
  * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
3295
3520
  * @todo re-check https://issues.chromium.org/issues/42212588
@@ -3308,9 +3533,10 @@ function fromBig(n, le = false) {
3308
3533
  };
3309
3534
  }
3310
3535
  function split(lst, le = false) {
3311
- let Ah = new Uint32Array(lst.length);
3312
- let Al = new Uint32Array(lst.length);
3313
- for (let i = 0; i < lst.length; i++) {
3536
+ const len = lst.length;
3537
+ let Ah = new Uint32Array(len);
3538
+ let Al = new Uint32Array(len);
3539
+ for (let i = 0; i < len; i++) {
3314
3540
  const {
3315
3541
  h,
3316
3542
  l
@@ -3337,12 +3563,45 @@ const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
3337
3563
  // from `crypto` to `cryptoNode`, which imports native module.
3338
3564
  // Makes the utils un-importable in browsers without a bundler.
3339
3565
  // Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
3566
+ /** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
3567
+ function isBytes(a) {
3568
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array';
3569
+ }
3570
+ /** Asserts something is positive integer. */
3571
+ function anumber(n) {
3572
+ if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);
3573
+ }
3574
+ /** Asserts something is Uint8Array. */
3575
+ function abytes(b, ...lengths) {
3576
+ if (!isBytes(b)) throw new Error('Uint8Array expected');
3577
+ if (lengths.length > 0 && !lengths.includes(b.length)) throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
3578
+ }
3579
+ /** Asserts a hash instance has not been destroyed / finished */
3580
+ function aexists(instance, checkFinished = true) {
3581
+ if (instance.destroyed) throw new Error('Hash instance has been destroyed');
3582
+ if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
3583
+ }
3584
+ /** Asserts output is properly-sized byte array */
3585
+ function aoutput(out, instance) {
3586
+ abytes(out);
3587
+ const min = instance.outputLen;
3588
+ if (out.length < min) {
3589
+ throw new Error('digestInto() expects output buffer of length at least ' + min);
3590
+ }
3591
+ }
3592
+ /** Cast u8 / u16 / u32 to u32. */
3340
3593
  function u32(arr) {
3341
3594
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
3342
3595
  }
3596
+ /** Zeroize a byte array. Warning: JS provides no guarantees. */
3597
+ function clean(...arrays) {
3598
+ for (let i = 0; i < arrays.length; i++) {
3599
+ arrays[i].fill(0);
3600
+ }
3601
+ }
3343
3602
  /** Is current platform little-endian? Most are. Big-Endian platform: IBM */
3344
3603
  const isLE = /* @__PURE__ */(() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
3345
- // The byte swap operation for uint32
3604
+ /** The byte swap operation for uint32 */
3346
3605
  function byteSwap(word) {
3347
3606
  return word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff;
3348
3607
  }
@@ -3351,13 +3610,15 @@ function byteSwap32(arr) {
3351
3610
  for (let i = 0; i < arr.length; i++) {
3352
3611
  arr[i] = byteSwap(arr[i]);
3353
3612
  }
3613
+ return arr;
3354
3614
  }
3615
+ const swap32IfBE = isLE ? u => u : byteSwap32;
3355
3616
  /**
3356
- * Convert JS string to byte array.
3357
- * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
3617
+ * Converts string to bytes using UTF8 encoding.
3618
+ * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
3358
3619
  */
3359
3620
  function utf8ToBytes(str) {
3360
- if (typeof str !== 'string') throw new Error('utf8ToBytes expected string, got ' + typeof str);
3621
+ if (typeof str !== 'string') throw new Error('string expected');
3361
3622
  return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
3362
3623
  }
3363
3624
  /**
@@ -3371,14 +3632,9 @@ function toBytes(data) {
3371
3632
  return data;
3372
3633
  }
3373
3634
  /** For runtime check if class implements interface */
3374
- class Hash {
3375
- // Safe version that clones internal state
3376
- clone() {
3377
- return this._cloneInto();
3378
- }
3379
- }
3635
+ class Hash {}
3380
3636
  /** Wraps hash function, creating an interface on top of it */
3381
- function wrapConstructor(hashCons) {
3637
+ function createHasher(hashCons) {
3382
3638
  const hashC = msg => hashCons().update(toBytes(msg)).digest();
3383
3639
  const tmp = hashCons();
3384
3640
  hashC.outputLen = tmp.outputLen;
@@ -3398,16 +3654,18 @@ function wrapConstructor(hashCons) {
3398
3654
  * Check out `sha3-addons` module for cSHAKE, k12, and others.
3399
3655
  * @module
3400
3656
  */
3657
+ // No __PURE__ annotations in sha3 header:
3658
+ // EVERYTHING is in fact used on every export.
3401
3659
  // Various per round constants calculations
3660
+ const _0n = BigInt(0);
3661
+ const _1n = BigInt(1);
3662
+ const _2n = BigInt(2);
3663
+ const _7n = BigInt(7);
3664
+ const _256n = BigInt(256);
3665
+ const _0x71n = BigInt(0x71);
3402
3666
  const SHA3_PI = [];
3403
3667
  const SHA3_ROTL = [];
3404
3668
  const _SHA3_IOTA = [];
3405
- const _0n = /* @__PURE__ */BigInt(0);
3406
- const _1n = /* @__PURE__ */BigInt(1);
3407
- const _2n = /* @__PURE__ */BigInt(2);
3408
- const _7n = /* @__PURE__ */BigInt(7);
3409
- const _256n = /* @__PURE__ */BigInt(256);
3410
- const _0x71n = /* @__PURE__ */BigInt(0x71);
3411
3669
  for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
3412
3670
  // Pi
3413
3671
  [x, y] = [y, (2 * x + 3 * y) % 5];
@@ -3422,7 +3680,9 @@ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
3422
3680
  }
3423
3681
  _SHA3_IOTA.push(t);
3424
3682
  }
3425
- const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */split(_SHA3_IOTA, true);
3683
+ const IOTAS = split(_SHA3_IOTA, true);
3684
+ const SHA3_IOTA_H = IOTAS[0];
3685
+ const SHA3_IOTA_L = IOTAS[1];
3426
3686
  // Left rotation (without 0, 32, 64)
3427
3687
  const rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
3428
3688
  const rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
@@ -3467,44 +3727,49 @@ function keccakP(s, rounds = 24) {
3467
3727
  s[0] ^= SHA3_IOTA_H[round];
3468
3728
  s[1] ^= SHA3_IOTA_L[round];
3469
3729
  }
3470
- B.fill(0);
3730
+ clean(B);
3471
3731
  }
3472
3732
  /** Keccak sponge function. */
3473
3733
  class Keccak extends Hash {
3474
3734
  // NOTE: we accept arguments in bytes instead of bits here.
3475
3735
  constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
3476
3736
  super();
3737
+ this.pos = 0;
3738
+ this.posOut = 0;
3739
+ this.finished = false;
3740
+ this.destroyed = false;
3741
+ this.enableXOF = false;
3477
3742
  this.blockLen = blockLen;
3478
3743
  this.suffix = suffix;
3479
3744
  this.outputLen = outputLen;
3480
3745
  this.enableXOF = enableXOF;
3481
3746
  this.rounds = rounds;
3482
- this.pos = 0;
3483
- this.posOut = 0;
3484
- this.finished = false;
3485
- this.destroyed = false;
3486
3747
  // Can be passed from user as dkLen
3487
3748
  anumber(outputLen);
3488
3749
  // 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
3489
3750
  // 0 < blockLen < 200
3490
- if (0 >= this.blockLen || this.blockLen >= 200) throw new Error('Sha3 supports only keccak-f1600 function');
3751
+ if (!(0 < blockLen && blockLen < 200)) throw new Error('only keccak-f1600 function is supported');
3491
3752
  this.state = new Uint8Array(200);
3492
3753
  this.state32 = u32(this.state);
3493
3754
  }
3755
+ clone() {
3756
+ return this._cloneInto();
3757
+ }
3494
3758
  keccak() {
3495
- if (!isLE) byteSwap32(this.state32);
3759
+ swap32IfBE(this.state32);
3496
3760
  keccakP(this.state32, this.rounds);
3497
- if (!isLE) byteSwap32(this.state32);
3761
+ swap32IfBE(this.state32);
3498
3762
  this.posOut = 0;
3499
3763
  this.pos = 0;
3500
3764
  }
3501
3765
  update(data) {
3502
3766
  aexists(this);
3767
+ data = toBytes(data);
3768
+ abytes(data);
3503
3769
  const {
3504
3770
  blockLen,
3505
3771
  state
3506
3772
  } = this;
3507
- data = toBytes(data);
3508
3773
  const len = data.length;
3509
3774
  for (let pos = 0; pos < len;) {
3510
3775
  const take = Math.min(blockLen - this.pos, len - pos);
@@ -3566,7 +3831,7 @@ class Keccak extends Hash {
3566
3831
  }
3567
3832
  destroy() {
3568
3833
  this.destroyed = true;
3569
- this.state.fill(0);
3834
+ clean(this.state);
3570
3835
  }
3571
3836
  _cloneInto(to) {
3572
3837
  const {
@@ -3590,9 +3855,9 @@ class Keccak extends Hash {
3590
3855
  return to;
3591
3856
  }
3592
3857
  }
3593
- const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
3858
+ const gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
3594
3859
  /** keccak-256 hash function. Different from SHA3-256. */
3595
- const keccak_256 = /* @__PURE__ */gen(0x01, 136, 256 / 8);
3860
+ const keccak_256 = /* @__PURE__ */(() => gen(0x01, 136, 256 / 8))();
3596
3861
 
3597
3862
  function keccak256(value, to_) {
3598
3863
  const bytes = keccak_256(isHex(value, {